autogen
autogen.OpenAIWrapper
OpenAIWrapper
A wrapper class for openai client.
Initialize the OpenAIWrapper.
Parameters:Name | Description |
---|---|
config_list | a 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_config | Type: Any |
Class Attributes
actual_usage_summary
aopenai_kwargs
extra_kwargs
openai_kwargs
total_usage_summary
Static Methods
extract_text_or_completion_object
Extract the text or ChatCompletion objects from a completion or chat response.
Parameters:Name | Description |
---|---|
response | The response from openai. Type: ModelClient.ModelClientResponseProtocol |
Type | Description |
---|---|
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
Name | Description |
---|---|
template | Type: Optional[Union[str, Callable[[dict[str, Any]], str]]] |
context | Type: Optional[dict[str, Any]] Default: None |
allow_format_str_template | Type: Optional[bool] Default: False |
Instance Methods
clear_usage_summary
Clear the usage summary.
create
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:Name | Description |
---|---|
**config | Type: Any |
print_usage_summary
Print the usage summary.
Parameters:Name | Description |
---|---|
mode | Type: Union[str, list[str]] Default: [‘actual’, ‘total’] |
register_model_client
Register a model client.
Parameters:Name | Description |
---|---|
model_client_cls | A custom client class that follows the ModelClient interface Type: ModelClient |
**kwargs | The kwargs for the custom client class to be initialized with |