openai_tracer
ChatCompletion
Bases: ChatCompletion
Wrapper of openai.types.chat.ChatCompletion
with ImpactsOutput
ChatCompletionChunk
Bases: ChatCompletionChunk
Wrapper of openai.types.chat.ChatCompletionChunk
with ImpactsOutput
OpenAIInstrumentor()
Instrumentor initialized by EcoLogits to automatically wrap all OpenAI calls
Source code in ecologits/tracers/openai_tracer.py
openai_chat_wrapper(wrapped, instance, args, kwargs)
Function that wraps an OpenAI answer with computed impacts
Parameters:
Name | Type | Description | Default |
---|---|---|---|
wrapped |
Callable
|
Callable that returns the LLM response |
required |
instance |
Completions
|
Never used - for compatibility with |
required |
args |
Any
|
Arguments of the callable |
required |
kwargs |
Any
|
Keyword arguments of the callable |
required |
Returns:
Type | Description |
---|---|
Union[ChatCompletion, Stream[ChatCompletionChunk]]
|
A wrapped |
Source code in ecologits/tracers/openai_tracer.py
openai_async_chat_wrapper(wrapped, instance, args, kwargs)
async
Function that wraps an OpenAI answer with computed impacts in async mode
Parameters:
Name | Type | Description | Default |
---|---|---|---|
wrapped |
Callable
|
Async callable that returns the LLM response |
required |
instance |
AsyncCompletions
|
Never used - for compatibility with |
required |
args |
Any
|
Arguments of the callable |
required |
kwargs |
Any
|
Keyword arguments of the callable |
required |
Returns:
Type | Description |
---|---|
Union[ChatCompletion, AsyncStream[ChatCompletionChunk]]
|
A wrapped |