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_lista list of config dicts to override the base_config.

They can contain additional kwargs as allowed in the create method.

E.g., python config_list = [ \\{ "model": "gpt-4", "api_key": os.environ.get("AZURE_OPENAI_API_KEY"), "api_type": "azure", "base_url": os.environ.get("AZURE_OPENAI_API_BASE"), "api_version": "2024-02-01", }, \\{ "model": "gpt-3.5-turbo", "api_key": os.environ.get("OPENAI_API_KEY"), "api_type": "openai", "base_url": "https://api.openai.com/v1", }, \\{ "model": "llama-7B", "base_url": "http://127.0.0.1:8080", }, ]

Type: Optional[list[dict[str, Any]]]

Default: None
**base_configType: Any

Class Attributes

actual_usage_summary



aopenai_kwargs



extra_kwargs



openai_kwargs



total_usage_summary



Static Methods

extract_text_or_completion_object

extract_text_or_completion_object(response: ModelClient.ModelClientResponseProtocol) -> list[str] | list[autogen.oai.client.ModelClient.ModelClientResponseProtocol.Choice.Message]

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

Parameters:
NameDescription
responseThe response from openai.

Type: ModelClient.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 Methods

clear_usage_summary

clear_usage_summary(self) -> None

Clear the usage summary.


create

create(self, **config: Any) -> autogen.oai.client.ModelClient.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