autogen_ext.models.openai.config 源代码
from typing import Awaitable, Callable, Dict, List, Literal, Optional, Union
from autogen_core import ComponentModel
from autogen_core.models import ModelCapabilities, ModelInfo # type: ignore
from pydantic import BaseModel, SecretStr
from typing_extensions import Required, TypedDict
class JSONSchema(TypedDict, total=False):
name: Required[str]
"""响应格式的名称。必须由a-z、A-Z、0-9组成,或包含下划线和短横线,最大长度为64个字符。"""
description: str
"""响应格式用途的描述,模型根据该描述决定如何以该格式进行响应。"""
schema: Dict[str, object]
"""响应格式的JSON Schema对象描述的模式。"""
strict: Optional[bool]
"""是否在生成输出时启用严格的模式遵循。
如果设置为 true,模型将始终严格遵循 `schema` 字段中定义的精确模式。
当 `strict` 为 `true` 时,仅支持 JSON Schema 的一个子集。
了解更多信息,请阅读
[结构化输出指南](https://platform.openai.com/docs/guides/structured-outputs)。
"""
class ResponseFormat(TypedDict):
type: Literal["text", "json_object", "json_schema"]
"""定义的响应格式类型:`text`、`json_object` 或 `json_schema`"""
json_schema: Optional[JSONSchema]
"""定义的响应格式类型:`json_schema`"""
class StreamOptions(TypedDict):
include_usage: bool
class CreateArguments(TypedDict, total=False):
frequency_penalty: Optional[float]
logit_bias: Optional[Dict[str, int]]
max_tokens: Optional[int]
n: Optional[int]
presence_penalty: Optional[float]
response_format: ResponseFormat
seed: Optional[int]
stop: Union[Optional[str], List[str]]
temperature: Optional[float]
top_p: Optional[float]
user: str
stream_options: Optional[StreamOptions]
AsyncAzureADTokenProvider = Callable[[], Union[str, Awaitable[str]]]
class BaseOpenAIClientConfiguration(CreateArguments, total=False):
model: str
api_key: str
timeout: Union[float, None]
max_retries: int
model_capabilities: ModelCapabilities # type: ignore
model_info: ModelInfo
add_name_prefixes: bool
"""模型支持的功能特性,默认由模型名称决定,但如果传入了值则会被覆盖。"""
default_headers: Dict[str, str] | None
# See OpenAI docs for explanation of these parameters
class OpenAIClientConfiguration(BaseOpenAIClientConfiguration, total=False):
organization: str
base_url: str
class AzureOpenAIClientConfiguration(BaseOpenAIClientConfiguration, total=False):
# Azure specific
azure_endpoint: Required[str]
azure_deployment: str
api_version: Required[str]
azure_ad_token: str
azure_ad_token_provider: AsyncAzureADTokenProvider # Or AzureTokenProvider
# Pydantic equivalents of the above TypedDicts
[文档]
class CreateArgumentsConfigModel(BaseModel):
frequency_penalty: float | None = None
logit_bias: Dict[str, int] | None = None
max_tokens: int | None = None
n: int | None = None
presence_penalty: float | None = None
response_format: ResponseFormat | None = None
seed: int | None = None
stop: str | List[str] | None = None
temperature: float | None = None
top_p: float | None = None
user: str | None = None
stream_options: StreamOptions | None = None
[文档]
class BaseOpenAIClientConfigurationConfigModel(CreateArgumentsConfigModel):
model: str
api_key: SecretStr | None = None
timeout: float | None = None
max_retries: int | None = None
model_capabilities: ModelCapabilities | None = None # type: ignore
model_info: ModelInfo | None = None
add_name_prefixes: bool | None = None
default_headers: Dict[str, str] | None = None
# See OpenAI docs for explanation of these parameters
[文档]
class OpenAIClientConfigurationConfigModel(BaseOpenAIClientConfigurationConfigModel):
organization: str | None = None
base_url: str | None = None
[文档]
class AzureOpenAIClientConfigurationConfigModel(BaseOpenAIClientConfigurationConfigModel):
# Azure specific
azure_endpoint: str
azure_deployment: str | None = None
api_version: str
azure_ad_token: str | None = None
azure_ad_token_provider: ComponentModel | None = None