OpenAIWrapper

OpenAIWrapper(
    *,
    config_list: Optional[list[dict[str, Any]]] = None,
    **base_config: Any
)

A wrapper class for openai client.
Initialize the OpenAIWrapper.

Parameters:
NameDescription
config_listType: Optional[list[dict[str, Any]]]

Default: None
**base_configType: Any

Class Attributes

actual_usage_summary



extra_kwargs



total_usage_summary



Static Methods

extract_text_or_completion_object

extract_text_or_completion_object(response: ModelClientResponseProtocol) -> list[str] | list[Message]

Extract the text or ChatCompletion objects from a completion or chat response.

Parameters:
NameDescription
responseThe response from openai.

Type: ModelClientResponseProtocol
Returns:
TypeDescription
list[str] | list[autogen.oai.client.ModelClient.ModelClientResponseProtocol.Choice.Message]A list of text, or a list of ChatCompletion objects if function_call/tool_calls are present.

instantiate

instantiate(
    template: Optional[Union[str, Callable[[dict[str, Any]], str]]],
    context: Optional[dict[str, Any]] = None,
    allow_format_str_template: Optional[bool] = False
) -> str | None
Parameters:
NameDescription
templateType: Optional[Union[str, Callable[[dict[str, Any]], str]]]
contextType: Optional[dict[str, Any]]

Default: None
allow_format_str_templateType: Optional[bool]

Default: False

Instance Attributes

openai_kwargs



Instance Methods

clear_usage_summary

clear_usage_summary(self) -> None

Clear the usage summary.


create

create(self, **config: Any) -> ModelClientResponseProtocol

Make a completion for a given config using available clients.
Besides the kwargs allowed in openai’s [or other] client, we allow the following additional kwargs.
The config in each client will be overridden by the config.

Parameters:
NameDescription
**configType: Any

print_usage_summary(self, mode: Union[str, list[str]] = ['actual', 'total']) -> None

Print the usage summary.

Parameters:
NameDescription
modeType: Union[str, list[str]]

Default: [‘actual’, ‘total’]

register_model_client

register_model_client(
    self,
    model_client_cls: ModelClient,
    **kwargs
) -> 

Register a model client.

Parameters:
NameDescription
model_client_clsA custom client class that follows the ModelClient interface

Type: ModelClient
**kwargsThe kwargs for the custom client class to be initialized with