ecologits.tracers.openai_tracer
¶
ChatCompletion
¶
Bases: ChatCompletion
Wrapper of openai.types.chat.ChatCompletion with ImpactsOutput
ChatCompletionChunk
¶
Bases: ChatCompletionChunk
Wrapper of openai.types.chat.ChatCompletionChunk with ImpactsOutput
Response
¶
Bases: Response
Wrapper of openai.types.responses.Response with ImpactsOutput
ParsedResponse
¶
Bases: ParsedResponse
Wrapper of openai.types.responses.ParsedResponse with ImpactsOutput
ParsedChatCompletion
¶
Bases: ParsedChatCompletion
Wrapper of openai.types.chat.ParsedChatCompletion 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 |
|---|---|
ChatCompletion | ChatCompletion | Stream[ChatCompletionChunk] | 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 |
|---|---|
ChatCompletion | ChatCompletion | AsyncStream[ChatCompletionChunk]
|
A wrapped |
Source code in ecologits/tracers/openai_tracer.py
openai_responses_wrapper(wrapped, instance, args, kwargs)
¶
Function that wraps an OpenAI Responses API answer with computed impacts
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
wrapped
|
Callable
|
Callable that returns the LLM response |
required |
instance
|
Responses
|
Never used - for compatibility with |
required |
args
|
Any
|
Arguments of the callable |
required |
kwargs
|
Any
|
Keyword arguments of the callable |
required |
Returns:
| Type | Description |
|---|---|
Response | Response | Stream[ResponseStreamEvent]
|
A wrapped |
Source code in ecologits/tracers/openai_tracer.py
openai_async_responses_wrapper(wrapped, instance, args, kwargs)
async
¶
Function that wraps an OpenAI Responses API answer with computed impacts in async mode
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
wrapped
|
Callable
|
Async callable that returns the LLM response |
required |
instance
|
AsyncResponses
|
Never used - for compatibility with |
required |
args
|
Any
|
Arguments of the callable |
required |
kwargs
|
Any
|
Keyword arguments of the callable |
required |
Returns:
| Type | Description |
|---|---|
Response | Response | AsyncStream[ResponseStreamEvent]
|
A wrapped |