You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
importOpenAIfrom"@genai-impact/ecologits-openai";constclient=newOpenAI({apiKey: process.env.OPENAI_API_KEY,});constmain=async()=>{try{constresponse=awaitclient.chat.completions.create({messages: [{role: "user",content: "Tell me a funny joke!"}],model: "gpt-3.5-turbo",});// Get estimated environmental impacts of the inferenceconsole.log(`Energy consumption: ${response.impacts.energy.value}${response.impacts.energy.unit}`);console.log(`GHG emissions: ${response.impacts.gwp.value}${response.impacts.gwp.unit}`);}catch(e){console.error(e);throwe;}};main();
Usage (Calculator)
import{completeImpact}from"@genai-impact/ecologits-openai";importOpenAIfrom"openai";constclient=newOpenAI({apiKey: process.env.OPENAI_API_KEY,});constmodel="gpt-3.5-turbo";constmain=async()=>{try{conststartDate=newDate();constresponse=awaitclient.chat.completions.create({messages: [{role: "user",content: "Tell me a funny joke!"}],
model,});constimpacts=completeImpact(response,model,startDate);// Get estimated environmental impacts of the inferenceconsole.log(`Energy consumption: ${impacts.energy.value}${impacts.energy.unit}`);console.log(`GHG emissions: ${impacts.gwp.value}${impacts.gwp.unit}`);}catch(e){console.error(e);throwe;}};main();