autogen_ext.models.azure#
- class AzureAIChatCompletionClient(**kwargs: Unpack)[source]#
Bases:
ChatCompletionClient
Chat completion client for models hosted on Azure AI Foundry or GitHub Models. See here for more info.
- Parameters:
endpoint (str) – The endpoint to use. Required.
credential (union, AzureKeyCredential, AsyncTokenCredential) – The credentials to use. Required
model_info (ModelInfo) – The model family and capabilities of the model. Required.
model (str) – The name of the model. Required if model is hosted on GitHub Models.
frequency_penalty – (optional,float)
presence_penalty – (optional,float)
temperature – (optional,float)
top_p – (optional,float)
max_tokens – (optional,int)
response_format – (optional, literal[“text”, “json_object”])
stop – (optional,List[str])
tools – (optional,List[ChatCompletionsToolDefinition])
tool_choice – (optional,Union[str, ChatCompletionsToolChoicePreset, ChatCompletionsNamedToolChoice]])
seed – (optional,int)
model_extras – (optional,Dict[str, Any])
To use this client, you must install the azure-ai-inference extension:
pip install "autogen-ext[azure]"
The following code snippet shows how to use the client:
import asyncio from azure.core.credentials import AzureKeyCredential from autogen_ext.models.azure import AzureAIChatCompletionClient from autogen_core.models import UserMessage async def main(): client = AzureAIChatCompletionClient( endpoint="endpoint", credential=AzureKeyCredential("api_key"), model_info={ "json_output": False, "function_calling": False, "vision": False, "family": "unknown", }, ) result = await client.create([UserMessage(content="What is the capital of France?", source="user")]) print(result) if __name__ == "__main__": asyncio.run(main())
- actual_usage() RequestUsage [source]#
- add_usage(usage: RequestUsage) None [source]#
- count_tokens(messages: Sequence[Annotated[SystemMessage | UserMessage | AssistantMessage | FunctionExecutionResultMessage, FieldInfo(annotation=NoneType, required=True, discriminator='type')]], *, tools: Sequence[Tool | ToolSchema] = []) int [source]#
- async create(messages: Sequence[Annotated[SystemMessage | UserMessage | AssistantMessage | FunctionExecutionResultMessage, FieldInfo(annotation=NoneType, required=True, discriminator='type')]], *, tools: Sequence[Tool | ToolSchema] = [], json_output: bool | None = None, extra_create_args: Mapping[str, Any] = {}, cancellation_token: CancellationToken | None = None) CreateResult [source]#
- async create_stream(messages: Sequence[Annotated[SystemMessage | UserMessage | AssistantMessage | FunctionExecutionResultMessage, FieldInfo(annotation=NoneType, required=True, discriminator='type')]], *, tools: Sequence[Tool | ToolSchema] = [], json_output: bool | None = None, extra_create_args: Mapping[str, Any] = {}, cancellation_token: CancellationToken | None = None) AsyncGenerator[str | CreateResult, None] [source]#
- remaining_tokens(messages: Sequence[Annotated[SystemMessage | UserMessage | AssistantMessage | FunctionExecutionResultMessage, FieldInfo(annotation=NoneType, required=True, discriminator='type')]], *, tools: Sequence[Tool | ToolSchema] = []) int [source]#
- total_usage() RequestUsage [source]#