Model interface
模型追踪
基类: Enum
Source code in src/agents/models/interface.py
模型
基类: ABC
调用大语言模型(LLM)的基础接口。
Source code in src/agents/models/interface.py
get_response
abstractmethod
async
get_response(
system_instructions: str | None,
input: str | list[TResponseInputItem],
model_settings: ModelSettings,
tools: list[Tool],
output_schema: AgentOutputSchema | None,
handoffs: list[Handoff],
tracing: ModelTracing,
) -> ModelResponse
从模型获取响应。
参数:
| 名称 | 类型 | 描述 | 默认值 |
|---|---|---|---|
system_instructions
|
str | None
|
要使用的系统指令。 |
required |
input
|
str | list[TResponseInputItem]
|
模型的输入项,采用OpenAI响应格式。 |
required |
model_settings
|
ModelSettings
|
要使用的模型设置。 |
required |
tools
|
list[Tool]
|
模型可用的工具。 |
required |
output_schema
|
AgentOutputSchema | None
|
要使用的输出模式。 |
required |
handoffs
|
list[Handoff]
|
模型可用的交接选项。 |
required |
tracing
|
ModelTracing
|
追踪配置。 |
required |
返回值:
| 类型 | 描述 |
|---|---|
ModelResponse
|
完整的模型响应。 |
Source code in src/agents/models/interface.py
stream_response
abstractmethod
stream_response(
system_instructions: str | None,
input: str | list[TResponseInputItem],
model_settings: ModelSettings,
tools: list[Tool],
output_schema: AgentOutputSchema | None,
handoffs: list[Handoff],
tracing: ModelTracing,
) -> AsyncIterator[TResponseStreamEvent]
从模型流式传输响应。
参数:
| 名称 | 类型 | 描述 | 默认值 |
|---|---|---|---|
system_instructions
|
str | None
|
要使用的系统指令。 |
required |
input
|
str | list[TResponseInputItem]
|
模型的输入项,采用OpenAI响应格式。 |
required |
model_settings
|
ModelSettings
|
要使用的模型设置。 |
required |
tools
|
list[Tool]
|
模型可用的工具。 |
required |
output_schema
|
AgentOutputSchema | None
|
要使用的输出模式。 |
required |
handoffs
|
list[Handoff]
|
模型可用的交接选项。 |
required |
tracing
|
ModelTracing
|
追踪配置。 |
required |
返回值:
| 类型 | 描述 |
|---|---|
AsyncIterator[TResponseStreamEvent]
|
一个响应流事件的迭代器,采用OpenAI响应格式。 |
Source code in src/agents/models/interface.py
模型提供者
基类: ABC
模型提供者的基础接口。
模型提供者负责按名称查找模型。