OpenAIChatFormatter
public class OpenAIChatFormatter extends OpenAIBaseFormatter
io/agentscope/extensions/model/openai/formatter/OpenAIChatFormatter.java:46–308用于OpenAI 聊天补全 HTTP API的格式化器。位于 io.agentscope.extensions.model.openai.formatter 包,继承自 OpenAIBaseFormatter。核心成员包括 doFormat、convertMessage、applyOptions、applyMaxTokens、applyTools、supportsStrict。
Formatter for OpenAI Chat Completion HTTP API. Converts between AgentScope Msg objects and OpenAI DTO types.
This formatter is used with the HTTP-based OpenAI client for standard OpenAI GPT models. It provides full support for:
-
All sampling parameters (temperature, top_p, penalties)
-
Tool calling with strict mode support
-
Full tool_choice options (auto, none, required, specific)
构造器摘要Constructor Summary
| 构造器Constructor | 说明Description |
|---|---|
public OpenAIChatFormatter() | 初始化 `OpenAIChatFormatter` 实例。 Creates a new instance. |
方法摘要Method Summary
构造器详情Constructor Detail
OpenAIChatFormatter
public OpenAIChatFormatter()
初始化 OpenAIChatFormatter 实例。
Creates a new instance.
io/agentscope/extensions/model/openai/formatter/OpenAIChatFormatter.java:50–52方法详情Method Detail
doFormat
protected List<OpenAIMessage> doFormat(List<Msg> msgs)
执行格式操作。
Performs the do format operation.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
msgs | List<Msg> | 消息列表(类型 `List`)。The msgs. |
List<OpenAIMessage>io/agentscope/extensions/model/openai/formatter/OpenAIChatFormatter.java:54–65doFormat
protected List<OpenAIMessage> doFormat(List<Msg> msgs, GenerateOptions options)
执行格式操作。
Performs the do format operation.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
msgs | List<Msg> | 消息列表(类型 `List`)。The msgs. |
options | GenerateOptions | 选项(类型 `GenerateOptions`)。The options. |
List<OpenAIMessage>io/agentscope/extensions/model/openai/formatter/OpenAIChatFormatter.java:67–80convertMessage
protected OpenAIMessage convertMessage(Msg msg, boolean hasMedia)
转换消息。
Convert one AgentScope message to OpenAI message format.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
msg | Msg | 消息到转换。the message to convert |
hasMedia | boolean | 有 Media(类型 `boolean`)。whether the message contains media content |
OpenAIMessageio/agentscope/extensions/model/openai/formatter/OpenAIChatFormatter.java:92–94applyOptions
public void applyOptions(OpenAIRequest request, GenerateOptions options, GenerateOptions defaultOptions)
应用选项。
Performs the apply options operation.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
request | OpenAIRequest | 请求(类型 `OpenAIRequest`)。The request. |
options | GenerateOptions | 选项(类型 `GenerateOptions`)。The options. |
defaultOptions | GenerateOptions | 默认选项(类型 `GenerateOptions`)。The default options. |
io/agentscope/extensions/model/openai/formatter/OpenAIChatFormatter.java:96–167applyMaxTokens
protected void applyMaxTokens(OpenAIRequest request, GenerateOptions options, GenerateOptions defaultOptions)
应用最大令牌数。
Performs the apply max tokens operation.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
request | OpenAIRequest | 请求(类型 `OpenAIRequest`)。The request. |
options | GenerateOptions | 选项(类型 `GenerateOptions`)。The options. |
defaultOptions | GenerateOptions | 默认选项(类型 `GenerateOptions`)。The default options. |
io/agentscope/extensions/model/openai/formatter/OpenAIChatFormatter.java:169–183applyTools
public void applyTools(OpenAIRequest request, List<ToolSchema> tools)
应用工具。
Performs the apply tools operation.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
request | OpenAIRequest | 请求(类型 `OpenAIRequest`)。The request. |
tools | List<ToolSchema> | 工具列表(类型 `List`)。The tools. |
io/agentscope/extensions/model/openai/formatter/OpenAIChatFormatter.java:185–220supportsStrict
protected boolean supportsStrict()
返回 supportsStrict 结果。
Returns whether this formatter's target API supports the strict parameter in tool definitions.
booleanio/agentscope/extensions/model/openai/formatter/OpenAIChatFormatter.java:231–233applyToolChoice
public void applyToolChoice(OpenAIRequest request, ToolChoice toolChoice)
应用工具选项。
Performs the apply tool choice operation.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
request | OpenAIRequest | 请求(类型 `OpenAIRequest`)。The request. |
toolChoice | ToolChoice | 工具选项(类型 `ToolChoice`)。The tool choice. |
io/agentscope/extensions/model/openai/formatter/OpenAIChatFormatter.java:235–264applyAdditionalBodyParams
protected void applyAdditionalBodyParams(OpenAIRequest request, GenerateOptions opts)
应用 applyAdditionalBodyParams。
Apply additional body parameters from GenerateOptions to OpenAI request.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
request | OpenAIRequest | 请求(类型 `OpenAIRequest`)。The request. |
opts | GenerateOptions | opts(类型 `GenerateOptions`)。The opts. |
io/agentscope/extensions/model/openai/formatter/OpenAIChatFormatter.java:270–307