🌱 EcoLogits tracks the energy consumption and environmental impacts of using generative AI models through APIs.
Documentation: ecologits.ai
pip install ecologits
For integration with a specific provider, use pip install ecologits[openai]
. We are currently supporting the following providers: anthropic
, cohere
, google-generativeai
, huggingface-hub
, mistralai
and openai
. See the full list of providers.
from ecologits import EcoLogits
from openai import OpenAI
# Initialize EcoLogits
EcoLogits.init()
client = OpenAI(api_key="<OPENAI_API_KEY>")
response = client.chat.completions.create(
model="gpt-3.5-turbo",
messages=[
{"role": "user", "content": "Tell me a funny joke!"}
]
)
# Get estimated environmental impacts of the inference
print(f"Energy consumption: {response.impacts.energy.value} kWh")
print(f"GHG emissions: {response.impacts.gwp.value} kgCO2eq")
See package documentation on EcoLogits
Have poetry installed on your system.
Easy install using a virtualenv:
Create a venv:
python3 -m venv .venv
source .venv/bin/activate
Install poetry:
pip install poetry
poetry install --all-extras --with dev,docs
poetry run pytest
pre-commit run --all-files