autogen_core.models#
- pydantic 模型 AssistantMessage[源代码]#
基类:
BaseModel
助手消息从语言模型中采样。
显示 JSON 模式
{ "title": "AssistantMessage", "description": "Assistant message are sampled from the language model.", "type": "object", "properties": { "content": { "anyOf": [ { "type": "string" }, { "items": { "$ref": "#/$defs/FunctionCall" }, "type": "array" } ], "title": "Content" }, "thought": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "default": null, "title": "Thought" }, "source": { "title": "Source", "type": "string" }, "type": { "const": "AssistantMessage", "default": "AssistantMessage", "title": "Type", "type": "string" } }, "$defs": { "FunctionCall": { "properties": { "id": { "title": "Id", "type": "string" }, "arguments": { "title": "Arguments", "type": "string" }, "name": { "title": "Name", "type": "string" } }, "required": [ "id", "arguments", "name" ], "title": "FunctionCall", "type": "object" } }, "required": [ "content", "source" ] }
- 字段:
content (str | List[autogen_core._types.FunctionCall])
source (str)
thought (str | None)
type (Literal['AssistantMessage'])
- field content: str | List[FunctionCall] [必需]#
消息的内容。
- class ChatCompletionClient[源代码]#
基类:
ComponentBase
[BaseModel
],ABC
- abstract actual_usage() RequestUsage [源代码]#
- abstract property capabilities: ModelCapabilities#
- abstract count_tokens(messages: Sequence[Annotated[SystemMessage | UserMessage | AssistantMessage | FunctionExecutionResultMessage, FieldInfo(annotation=NoneType, required=True, discriminator='type')]], *, tools: Sequence[Tool | ToolSchema] = []) int [源代码]#
- abstract async create(messages: Sequence[Annotated[SystemMessage | UserMessage | AssistantMessage | FunctionExecutionResultMessage, FieldInfo(annotation=NoneType, required=True, discriminator='type')]], *, tools: Sequence[Tool | ToolSchema] = [], json_output: bool | type[BaseModel] | None = None, extra_create_args: Mapping[str, Any] = {}, cancellation_token: CancellationToken | None = None) CreateResult [source]#
从模型创建一个单一的响应。
- 参数:
messages (Sequence[LLMMessage]) – 发送给模型的消息。
tools (Sequence[Tool | ToolSchema], optional) – 与模型一起使用的工具。默认为 []。
json_output (Optional[bool | type[BaseModel]], optional) – 是否使用 JSON 模式、结构化输出或两者都不使用。 默认为 None。 如果设置为 Pydantic BaseModel 类型,它将用作结构化输出的输出类型。如果设置为布尔值,它将用于确定是否使用 JSON 模式。 如果设置为 True,请确保指示模型在指令或提示中生成 JSON 输出。
extra_create_args (Mapping[str, Any], optional) – 传递给底层客户端的额外参数。默认为 {}。
cancellation_token (Optional[CancellationToken], optional) – 用于取消的令牌。默认为 None。
- 返回值:
CreateResult – 模型调用的结果。
- abstract create_stream(messages: Sequence[Annotated[SystemMessage | UserMessage | AssistantMessage | FunctionExecutionResultMessage, FieldInfo(annotation=NoneType, required=True, discriminator='type')]], *, tools: Sequence[Tool | ToolSchema] = [], json_output: bool | type[BaseModel] | None = None, extra_create_args: Mapping[str, Any] = {}, cancellation_token: CancellationToken | None = None) AsyncGenerator[str | CreateResult, None] [source]#
创建一个来自模型的字符串块的流,以 CreateResult 结尾。
- 参数:
messages (Sequence[LLMMessage]) – 发送给模型的消息。
tools (Sequence[Tool | ToolSchema], optional) – 与模型一起使用的工具。默认为 []。
json_output (Optional[bool | type[BaseModel]], optional) –
是否使用 JSON 模式、结构化输出或两者都不使用。默认为 None。 如果设置为 Pydantic BaseModel 类型,它将用作结构化输出的输出类型。如果设置为布尔值,它将用于确定是否使用 JSON 模式。如果设置为 True,请确保指示模型在指令或提示中生成 JSON 输出。
extra_create_args (Mapping[str, Any], optional) – 传递给底层客户端的额外参数。默认为 {}。
cancellation_token (Optional[CancellationToken], optional) – 用于取消的令牌。默认为 None。
- 返回值:
AsyncGenerator[Union[str, CreateResult], None] – 一个生成字符串块并以
CreateResult
结尾的生成器。
- abstract remaining_tokens(messages: Sequence[Annotated[SystemMessage | UserMessage | AssistantMessage | FunctionExecutionResultMessage, FieldInfo(annotation=NoneType, required=True, discriminator='type')]], *, tools: Sequence[Tool | ToolSchema] = []) int [source]#
- abstract total_usage() RequestUsage [source]#
- pydantic model ChatCompletionTokenLogprob[source]#
基类:
BaseModel
显示 JSON 模式
{ "title": "ChatCompletionTokenLogprob", "type": "object", "properties": { "token": { "title": "Token", "type": "string" }, "logprob": { "title": "Logprob", "type": "number" }, "top_logprobs": { "anyOf": [ { "items": { "$ref": "#/$defs/TopLogprob" }, "type": "array" }, { "type": "null" } ], "default": null, "title": "Top Logprobs" }, "bytes": { "anyOf": [ { "items": { "type": "integer" }, "type": "array" }, { "type": "null" } ], "default": null, "title": "Bytes" } }, "$defs": { "TopLogprob": { "properties": { "logprob": { "title": "Logprob", "type": "number" }, "bytes": { "anyOf": [ { "items": { "type": "integer" }, "type": "array" }, { "type": "null" } ], "default": null, "title": "Bytes" } }, "required": [ "logprob" ], "title": "TopLogprob", "type": "object" } }, "required": [ "token", "logprob" ] }
- 字段:
bytes (List[int] | None)
logprob (float)
token (str)
top_logprobs (List[autogen_core.models._types.TopLogprob] | None)
- 字段 top_logprobs: List[TopLogprob] | None = None#
- pydantic 模型 CreateResult[source]#
基类:
BaseModel
创建结果包含模型补全的输出。
显示 JSON 模式
{ "title": "CreateResult", "description": "Create result contains the output of a model completion.", "type": "object", "properties": { "finish_reason": { "enum": [ "stop", "length", "function_calls", "content_filter", "unknown" ], "title": "Finish Reason", "type": "string" }, "content": { "anyOf": [ { "type": "string" }, { "items": { "$ref": "#/$defs/FunctionCall" }, "type": "array" } ], "title": "Content" }, "usage": { "$ref": "#/$defs/RequestUsage" }, "cached": { "title": "Cached", "type": "boolean" }, "logprobs": { "anyOf": [ { "items": { "$ref": "#/$defs/ChatCompletionTokenLogprob" }, "type": "array" }, { "type": "null" } ], "default": null, "title": "Logprobs" }, "thought": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "default": null, "title": "Thought" } }, "$defs": { "ChatCompletionTokenLogprob": { "properties": { "token": { "title": "Token", "type": "string" }, "logprob": { "title": "Logprob", "type": "number" }, "top_logprobs": { "anyOf": [ { "items": { "$ref": "#/$defs/TopLogprob" }, "type": "array" }, { "type": "null" } ], "default": null, "title": "Top Logprobs" }, "bytes": { "anyOf": [ { "items": { "type": "integer" }, "type": "array" }, { "type": "null" } ], "default": null, "title": "Bytes" } }, "required": [ "token", "logprob" ], "title": "ChatCompletionTokenLogprob", "type": "object" }, "FunctionCall": { "properties": { "id": { "title": "Id", "type": "string" }, "arguments": { "title": "Arguments", "type": "string" }, "name": { "title": "Name", "type": "string" } }, "required": [ "id", "arguments", "name" ], "title": "FunctionCall", "type": "object" }, "RequestUsage": { "properties": { "prompt_tokens": { "title": "Prompt Tokens", "type": "integer" }, "completion_tokens": { "title": "Completion Tokens", "type": "integer" } }, "required": [ "prompt_tokens", "completion_tokens" ], "title": "RequestUsage", "type": "object" }, "TopLogprob": { "properties": { "logprob": { "title": "Logprob", "type": "number" }, "bytes": { "anyOf": [ { "items": { "type": "integer" }, "type": "array" }, { "type": "null" } ], "default": null, "title": "Bytes" } }, "required": [ "logprob" ], "title": "TopLogprob", "type": "object" } }, "required": [ "finish_reason", "content", "usage", "cached" ] }
- 字段:
cached (bool)
content (str | List[autogen_core._types.FunctionCall])
finish_reason (Literal['stop', 'length', 'function_calls', 'content_filter', 'unknown'])
logprobs (List[autogen_core.models._types.ChatCompletionTokenLogprob] | None)
thought (str | None)
usage (autogen_core.models._types.RequestUsage)
- 字段 content: str | List[FunctionCall] [必需]#
模型补全的输出。
- 字段 finish_reason: Literal['stop', 'length', 'function_calls', 'content_filter', 'unknown'] [必需]#
模型完成生成的原因。
- 字段 logprobs: List[ChatCompletionTokenLogprob] | None = None#
补全中 token 的 logprobs。
- 字段 usage: RequestUsage [必需]#
提示和补全中 token 的使用情况。
- pydantic 模型 FunctionExecutionResult[source]#
基类:
BaseModel
函数执行结果包含函数调用的输出。
显示 JSON 模式
{ "title": "FunctionExecutionResult", "description": "Function execution result contains the output of a function call.", "type": "object", "properties": { "content": { "title": "Content", "type": "string" }, "name": { "title": "Name", "type": "string" }, "call_id": { "title": "Call Id", "type": "string" }, "is_error": { "anyOf": [ { "type": "boolean" }, { "type": "null" } ], "default": null, "title": "Is Error" } }, "required": [ "content", "name", "call_id" ] }
- 字段:
call_id (str)
content (str)
is_error (bool | None)
name (str)
- pydantic 模型 FunctionExecutionResultMessage[source]#
基类:
BaseModel
函数执行结果消息包含多个函数调用的输出。
显示 JSON 模式
{ "title": "FunctionExecutionResultMessage", "description": "Function execution result message contains the output of multiple function calls.", "type": "object", "properties": { "content": { "items": { "$ref": "#/$defs/FunctionExecutionResult" }, "title": "Content", "type": "array" }, "type": { "const": "FunctionExecutionResultMessage", "default": "FunctionExecutionResultMessage", "title": "Type", "type": "string" } }, "$defs": { "FunctionExecutionResult": { "description": "Function execution result contains the output of a function call.", "properties": { "content": { "title": "Content", "type": "string" }, "name": { "title": "Name", "type": "string" }, "call_id": { "title": "Call Id", "type": "string" }, "is_error": { "anyOf": [ { "type": "boolean" }, { "type": "null" } ], "default": null, "title": "Is Error" } }, "required": [ "content", "name", "call_id" ], "title": "FunctionExecutionResult", "type": "object" } }, "required": [ "content" ] }
- 字段:
content (List[autogen_core.models._types.FunctionExecutionResult])
type (Literal['FunctionExecutionResultMessage'])
- 字段 content: List[FunctionExecutionResult] [必需]#
- 类 ModelFamily(*args: Any, **kwargs: Any)[源代码]#
基类:
object
模型族是一组从能力角度来看具有相似特征的模型。 这与离散支持的功能(如视觉、函数调用和 JSON 输出)不同。
此命名空间类保存 AutoGen 了解的模型族的常量。 其他族肯定存在,可以用字符串表示,但是,AutoGen 会将它们视为未知。
- ANY#
别名:
Literal
[‘gpt-41’, ‘gpt-45’, ‘gpt-4o’, ‘o1’, ‘o3’, ‘o4’, ‘gpt-4’, ‘gpt-35’, ‘r1’, ‘gemini-1.5-flash’, ‘gemini-1.5-pro’, ‘gemini-2.0-flash’, ‘gemini-2.5-pro’, ‘claude-3-haiku’, ‘claude-3-sonnet’, ‘claude-3-opus’, ‘claude-3-5-haiku’, ‘claude-3-5-sonnet’, ‘claude-3-7-sonnet’, ‘unknown’]
- CLAUDE_3_5_HAIKU = 'claude-3-5-haiku'#
- CLAUDE_3_5_SONNET = 'claude-3-5-sonnet'#
- CLAUDE_3_7_SONNET = 'claude-3-7-sonnet'#
- CLAUDE_3_HAIKU = 'claude-3-haiku'#
- CLAUDE_3_OPUS = 'claude-3-opus'#
- CLAUDE_3_SONNET = 'claude-3-sonnet'#
- GEMINI_1_5_FLASH = 'gemini-1.5-flash'#
- GEMINI_1_5_PRO = 'gemini-1.5-pro'#
- GEMINI_2_0_FLASH = 'gemini-2.0-flash'#
- GEMINI_2_5_PRO = 'gemini-2.5-pro'#
- GPT_35 = 'gpt-35'#
- GPT_4 = 'gpt-4'#
- GPT_41 = 'gpt-41'#
- GPT_45 = 'gpt-45'#
- GPT_4O = 'gpt-4o'#
- O1 = 'o1'#
- O3 = 'o3'#
- O4 = 'o4'#
- R1 = 'r1'#
- UNKNOWN = 'unknown'#
- 类 ModelInfo[source]#
基类:
TypedDict
ModelInfo 是一个字典,包含有关模型属性的信息。它预计在模型客户端的 model_info 属性中使用。
随着我们添加更多功能,我们预计它会随着时间的推移而增长。
- family: Required[Literal['gpt-41', 'gpt-45', 'gpt-4o', 'o1', 'o3', 'o4', 'gpt-4', 'gpt-35', 'r1', 'gemini-1.5-flash', 'gemini-1.5-pro', 'gemini-2.0-flash', 'gemini-2.5-pro', 'claude-3-haiku', 'claude-3-sonnet', 'claude-3-opus', 'claude-3-5-haiku', 'claude-3-5-sonnet', 'claude-3-7-sonnet', 'unknown'] | str]#
模型系列应该是
ModelFamily
中的常量之一,或者表示未知模型系列的字符串。
- pydantic 模型 SystemMessage[源代码]#
基类:
BaseModel
系统消息包含来自开发者的模型指令。
注意
Open AI 正在放弃使用“system”角色,而倾向于使用“developer”角色。有关更多详细信息,请参阅模型规范。 但是,他们的 API 中仍然允许使用“system”角色,并且会在服务器端自动转换为“developer”角色。 因此,您可以将 SystemMessage 用于开发者消息。
显示 JSON 模式
{ "title": "SystemMessage", "description": "System message contains instructions for the model coming from the developer.\n\n.. note::\n\n Open AI is moving away from using 'system' role in favor of 'developer' role.\n See `Model Spec <https://cdn.openai.com/spec/model-spec-2024-05-08.html#definitions>`_ for more details.\n However, the 'system' role is still allowed in their API and will be automatically converted to 'developer' role\n on the server side.\n So, you can use `SystemMessage` for developer messages.", "type": "object", "properties": { "content": { "title": "Content", "type": "string" }, "type": { "const": "SystemMessage", "default": "SystemMessage", "title": "Type", "type": "string" } }, "required": [ "content" ] }
- 字段:
content (str)
类型 (Literal['SystemMessage'])
- pydantic 模型 UserMessage[源代码]#
基类:
BaseModel
用户消息包含来自最终用户的输入,或是提供给模型的通用数据。
显示 JSON 模式
{ "title": "UserMessage", "description": "User message contains input from end users, or a catch-all for data provided to the model.", "type": "object", "properties": { "content": { "anyOf": [ { "type": "string" }, { "items": { "anyOf": [ { "type": "string" }, {} ] }, "type": "array" } ], "title": "Content" }, "source": { "title": "Source", "type": "string" }, "type": { "const": "UserMessage", "default": "UserMessage", "title": "Type", "type": "string" } }, "required": [ "content", "source" ] }
- 字段:
content (str | List[str | autogen_core._image.Image])
source (str)
类型 (Literal['UserMessage'])
- validate_model_info(model_info: ModelInfo) None [源代码]#
验证模型信息字典。
- 引发:
ValueError – 如果模型信息字典缺少必需的字段。