genai-impact / ecologits

🌱 EcoLogits tracks the energy consumption and environmental footprint of using generative AI models through APIs.
https://ecologits.ai/
Mozilla Public License 2.0
36 stars 3 forks source link

Add Cohere provider #35

Closed adrienbanse closed 2 months ago

adrienbanse commented 2 months ago

See https://github.com/dataforgoodfr/12_genai_impact/issues/27

Only one thing that's weird. Without EcoLogits being initialized, this piece of code

client = cohere.AsyncClient()
stream = await client.chat_stream(
    message="Tell me a short story", 
    model="command-light", 
    max_tokens=50
)
async for event in stream:
    if event.event_type == "text-generation":
        print(event.text, end='')

throws the error TypeError: object async_generator can't be used in 'await' expression, but works without the await before client.chat_stream. I couldn't find any async stream example, and I'm not familiar with async in Python, so I left it without the await.