autogen_core.models#

pydantic model AssistantMessage[源代码]#

基础:BaseModel

助理消息是从语言模型中进行采样的。

Show JSON schema
{
   "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"
   ]
}

Fields:
  • content (str | List[autogen_core._types.FunctionCall])

  • source (str)

  • thought (str | None)

  • type (Literal['AssistantMessage'])

field content: str | 列表[FunctionCall] [Required]#

消息的内容。

field source: str [Required]#

发送此消息的代理名称。

field thought: str | = None#

如果可用,则为完成的推理文本。用于推理模型和除函数调用之外的附加文本内容。

field type: 字面量['AssistantMessage'] = 'AssistantMessage'#
class ChatCompletionClient[源代码]#

基类:ComponentBase[BaseModel], ABC

abstract actual_usage() RequestUsage[源代码]#
abstract property capabilities: ModelCapabilities#
abstract async close() [源代码]#
abstract count_tokens(messages: Sequence[已注解[系统消息 | UserMessage | AssistantMessage | FunctionExecutionResultMessage, FieldInfo(annotation=NoneType, required=True, discriminator='type')]], *, tools: Sequence[工具 | 工具架构] = []) int[源代码]#
abstract async create(messages: Sequence[已注解[系统消息 | UserMessage | AssistantMessage | FunctionExecutionResultMessage, FieldInfo(annotation=NoneType, required=True, discriminator='type')]], *, tools: Sequence[工具 | 工具模式] = [], json_output: bool | = None, extra_create_args: 映射[str, 任何] = {}, cancellation_token: CancellationToken | = None) CreateResult[源代码]#
abstract create_stream(messages: Sequence[已注解[系统消息 | UserMessage | AssistantMessage | FunctionExecutionResultMessage, FieldInfo(annotation=NoneType, required=True, discriminator='type')]], *, tools: Sequence[工具 | 工具架构] = [], json_output: bool | = None, extra_create_args: 映射[str, 任何] = {}, cancellation_token: CancellationToken | = None) AsyncGenerator[str | CreateResult, ][源代码]#
abstract property model_info: ModelInfo#
abstract remaining_tokens(messages: Sequence[已注解[系统消息 | UserMessage | AssistantMessage | FunctionExecutionResultMessage, FieldInfo(annotation=NoneType, required=True, discriminator='type')]], *, tools: Sequence[工具 | 工具模式] = []) int[源代码]#
abstract total_usage() RequestUsage[源代码]#
pydantic model ChatCompletionTokenLogprob[源代码]#

基础:BaseModel

Show JSON schema
{
   "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"
   ]
}

Fields:
  • bytes (List[int] | None)

  • logprob (float)

  • token (str)

  • top_logprobs (List[autogen_core.models._types.TopLogprob] | None)

field bytes: 列表[int] | = None#
field logprob: float [Required]#
field token: str [Required]#
field top_logprobs: 列表[TopLogprob] | = None#
pydantic model CreateResult[源代码]#

基础:BaseModel

创建结果包含模型完成的输出。

Show JSON schema
{
   "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"
   ]
}

Fields:
  • 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)

field cached: bool [Required]#

是否从缓存响应生成了完成。

field content: str | 列表[FunctionCall] [Required]#

模型完成的输出。

field finish_reason: 字面量['stop', 'length', 'function_calls', 'content_filter', 'unknown'] [Required]#

模型完成生成的原因。

field logprobs: 列表[ChatCompletionTokenLogprob] | = None#

完成中令牌的logprobs。

field thought: str | = None#

如果可用,完成时的推理文本。用于推理模型和函数调用之外的额外文本内容。

field usage: RequestUsage [Required]#

提示和完成中令牌的使用。

pydantic model FunctionExecutionResult[源代码]#

基础:BaseModel

函数执行结果包含函数调用的输出。

显示 JSON 模式
{
   "title": "FunctionExecutionResult",
   "description": "函数执行结果包含函数调用的输出。",
   "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"
   ]
}

Fields:
  • call_id (str)

  • 内容 (str)

  • is_error (bool | None)

  • name (str)

field call_id: str [Required]#

函数调用的ID。请注意,某些模型的此ID可能为空。

field content: str [Required]#

函数调用的输出。

field is_error: bool | = None#

函数调用是否导致了错误。

field name: str [Required]#

(在v0.4.8中新增)被调用函数的名称。

pydantic model FunctionExecutionResultMessage[源代码]#

基础:BaseModel

函数执行结果消息包含多个函数调用的输出。

Show JSON schema
{
   "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"
   ]
}

Fields:
  • 内容 (List[autogen_core.models._types.FunctionExecutionResult])

  • type (Literal['FunctionExecutionResultMessage'])

field content: 列表[FunctionExecutionResult] [Required]#
field type: 字面量['FunctionExecutionResultMessage'] = 'FunctionExecutionResultMessage'#
class ModelCapabilities(**kwargs)[源代码]#

基础:TypedDict

function_calling: 必选[bool]#
json_output: 必需[bool]#
vision: 必填[bool]#
class ModelFamily(*args: 任何, **kwargs: 任何)[源代码]#

基础: object

模型家族是从能力角度共享相似特性的一组模型。这与离散支持的功能(如视觉、函数调用和JSON输出)不同。

此命名空间类包含autogen理解的模型家族的常量。当然,其他家族也存在,并可以用字符串表示,但autogen会将它们视为未知。

ANY#

别名 Literal[‘gpt-4o’, ‘o1’, ‘o3’, ‘gpt-4’, ‘gpt-35’, ‘r1’, ‘gemini-1.5-flash’, ‘gemini-1.5-pro’, ‘gemini-2.0-flash’, ‘claude-3-haiku’, ‘claude-3-sonnet’, ‘claude-3-opus’, ‘claude-3.5-haiku’, ‘claude-3.5-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'#
GPT_35 = 'gpt-35'#
GPT_4 = 'gpt-4'#
GPT_4O = 'gpt-4o'#
O1 = 'o1'#
O3 = 'o3'#
R1 = 'r1'#
UNKNOWN = 'unknown'#
static is_claude(family: str) bool[源代码]#
static is_gemini(family: str) bool[源代码]#
static is_openai(family: str) bool[源代码]#
class ModelInfo[源代码]#

基础:TypedDict

ModelInfo 是一个包含模型属性信息的字典。 它预期用于模型客户端的 model_info 属性中。

我们预计随着时间的推移,随着我们添加更多功能,这一内容将会增加。

family: 必选[字面量['gpt-4o', 'o1', 'o3', 'gpt-4', 'gpt-35', 'r1', 'gemini-1.5-flash', 'gemini-1.5-pro', 'gemini-2.0-flash', 'claude-3-haiku', 'claude-3-sonnet', 'claude-3-opus', 'claude-3.5-haiku', 'claude-3.5-sonnet', 'unknown'] | str]#

模型家族应该是来自ModelFamily的常量之一,或者是一个表示未知模型家族的字符串。

function_calling: 必选[bool]#

如果模型支持函数调用,则为True,否则为False。

json_output: 必选[bool]#

这与结构化json不同。

Type:

如果模型支持json输出,则为True,否则为False。注意

vision: 必选[bool]#

如果模型支持视觉,即图像输入,则为True,否则为False。

class RequestUsage(prompt_tokens: int, completion_tokens: int)[源代码]#

基础: object

completion_tokens: int#
prompt_tokens: int#
pydantic model SystemMessage[源代码]#

基础:BaseModel

系统消息包含开发者为模型提供的指令。

注意

Open AI 正在从使用‘system’角色转向使用‘developer’角色。 详情请参见 Model Spec。 然而,他们的API中仍然允许使用‘system’角色,并且会在服务器端自动转换为‘developer’角色。 因此,你可以使用 SystemMessage 来传递开发者消息。

显示JSON模式
{
   "title": "SystemMessage",
   "description": "系统消息包含来自开发人员的模型指令。\n\n.. 注意::\n\n    Open AI 正在从使用 'system' 角色转向 'developer' 角色。\n    详见 `Model Spec `_ 获取更多信息。\n    然而,'system' 角色仍然在他们的 API 中允许使用,并会在服务器端自动转换为 'developer' 角色。\n    因此,您可以使用 `SystemMessage` 表示开发人员的消息。",
   "type": "object",
   "properties": {
      "content": {
         "title": "Content",
         "type": "string"
      },
      "type": {
         "const": "SystemMessage",
         "default": "SystemMessage",
         "title": "Type",
         "type": "string"
      }
   },
   "required": [
      "content"
   ]
}

Fields:
  • 内容 (str)

  • 类型 (Literal['SystemMessage'])

field content: str [Required]#

消息的内容。

field type: 字面量['SystemMessage'] = 'SystemMessage'#
class TopLogprob(logprob: float, bytes: List[int] | = None)[源代码]#

基础: object

bytes: 列表[int] | = None#
logprob: float#
pydantic model UserMessage[源代码]#

基础:BaseModel

用户消息包含来自最终用户的输入,或提供给模型的数据的通用捕获。

显示JSON模式
{
   "title": "UserMessage",
   "description": "用户消息包含来自最终用户的输入,或提供给模型的数据的全面捕捉。",
   "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"
   ]
}

Fields:
  • content (str | List[str | autogen_core._image.Image])

  • source (str)

  • type (Literal['UserMessage'])

field content: str | 列表[str | 图片] [Required]#

消息的内容。

field source: str [Required]#

发送此消息的代理名称。

field type: 字面量['UserMessage'] = 'UserMessage'#
validate_model_info(model_info: ModelInfo) [源代码]#

验证模型信息字典。

Raises:

ValueError – 如果模型信息字典缺少必填字段。