Class OpenAIChatFormatter
java.lang.Object
io.agentscope.core.formatter.AbstractBaseFormatter<OpenAIMessage,OpenAIResponse,OpenAIRequest>
io.agentscope.extensions.model.openai.formatter.OpenAIBaseFormatter
io.agentscope.extensions.model.openai.formatter.OpenAIChatFormatter
- All Implemented Interfaces:
io.agentscope.core.formatter.Formatter<OpenAIMessage,OpenAIResponse, OpenAIRequest>
- Direct Known Subclasses:
DeepSeekFormatter,DeepSeekFormatter,GLMFormatter,GLMFormatter,KimiFormatter,MiniMaxFormatter,OpenAIMultiAgentFormatter
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)
-
Field Summary
Fields inherited from class io.agentscope.extensions.model.openai.formatter.OpenAIBaseFormatter
messageConverter, responseParser -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidapplyAdditionalBodyParams(OpenAIRequest request, io.agentscope.core.model.GenerateOptions opts) Apply additional body parameters from GenerateOptions to OpenAI request.protected voidapplyMaxTokens(OpenAIRequest request, io.agentscope.core.model.GenerateOptions options, io.agentscope.core.model.GenerateOptions defaultOptions) voidapplyOptions(OpenAIRequest request, io.agentscope.core.model.GenerateOptions options, io.agentscope.core.model.GenerateOptions defaultOptions) Apply generation options to the request.voidapplyToolChoice(OpenAIRequest request, io.agentscope.core.model.ToolChoice toolChoice) Apply tool choice configuration to the request.voidapplyTools(OpenAIRequest request, List<io.agentscope.core.model.ToolSchema> tools) Apply tool schemas to the request.protected OpenAIMessageconvertMessage(io.agentscope.core.message.Msg msg, boolean hasMedia) Convert one AgentScope message to OpenAI message format.protected List<OpenAIMessage>protected List<OpenAIMessage>doFormat(List<io.agentscope.core.message.Msg> msgs, io.agentscope.core.model.GenerateOptions options) protected booleanReturns whether this formatter's target API supports the strict parameter in tool definitions.Methods inherited from class io.agentscope.extensions.model.openai.formatter.OpenAIBaseFormatter
applyToolChoice, applyTools, buildRequest, buildRequest, parseResponseMethods inherited from class io.agentscope.core.formatter.AbstractBaseFormatter
convertToolResultToString, extractTextContent, extractTextContent, format, format, formatRoleLabel, getOptionOrDefault, hasMediaContent, saveBase64DataToTempFile, shouldBypassHistory
-
Constructor Details
-
OpenAIChatFormatter
public OpenAIChatFormatter()
-
-
Method Details
-
doFormat
- Specified by:
doFormatin classio.agentscope.core.formatter.AbstractBaseFormatter<OpenAIMessage,OpenAIResponse, OpenAIRequest>
-
doFormat
protected List<OpenAIMessage> doFormat(List<io.agentscope.core.message.Msg> msgs, io.agentscope.core.model.GenerateOptions options) - Overrides:
doFormatin classio.agentscope.core.formatter.AbstractBaseFormatter<OpenAIMessage,OpenAIResponse, OpenAIRequest>
-
convertMessage
Convert one AgentScope message to OpenAI message format.Provider-specific subclasses may override this when the target API supports a slightly different message shape.
- Parameters:
msg- the message to converthasMedia- whether the message contains media content- Returns:
- converted OpenAI message
-
applyOptions
public void applyOptions(OpenAIRequest request, io.agentscope.core.model.GenerateOptions options, io.agentscope.core.model.GenerateOptions defaultOptions) Description copied from class:OpenAIBaseFormatterApply generation options to the request. Subclasses implement provider-specific option handling.- Specified by:
applyOptionsin interfaceio.agentscope.core.formatter.Formatter<OpenAIMessage,OpenAIResponse, OpenAIRequest> - Specified by:
applyOptionsin classOpenAIBaseFormatter- Parameters:
request- OpenAI request DTOoptions- Generation options to applydefaultOptions- Default options to use if options parameter is null
-
applyMaxTokens
protected void applyMaxTokens(OpenAIRequest request, io.agentscope.core.model.GenerateOptions options, io.agentscope.core.model.GenerateOptions defaultOptions) -
applyTools
Description copied from class:OpenAIBaseFormatterApply tool schemas to the request. Subclasses implement provider-specific tool handling.- Specified by:
applyToolsin interfaceio.agentscope.core.formatter.Formatter<OpenAIMessage,OpenAIResponse, OpenAIRequest> - Specified by:
applyToolsin classOpenAIBaseFormatter- Parameters:
request- OpenAI request DTOtools- List of tool schemas to apply (may be null or empty)
-
supportsStrict
protected boolean supportsStrict()Returns whether this formatter's target API supports the strict parameter in tool definitions.Subclasses can override this method to disable strict parameter for providers that don't support it (e.g., DeepSeek).
- Returns:
- true if strict parameter is supported, false otherwise
-
applyToolChoice
Description copied from class:OpenAIBaseFormatterApply tool choice configuration to the request. Subclasses implement provider-specific tool choice handling.- Specified by:
applyToolChoicein interfaceio.agentscope.core.formatter.Formatter<OpenAIMessage,OpenAIResponse, OpenAIRequest> - Specified by:
applyToolChoicein classOpenAIBaseFormatter- Parameters:
request- OpenAI request DTOtoolChoice- Tool choice configuration (null means auto)
-
applyAdditionalBodyParams
protected void applyAdditionalBodyParams(OpenAIRequest request, io.agentscope.core.model.GenerateOptions opts) Apply additional body parameters from GenerateOptions to OpenAI request. Unknown parameters are passed through to extraParams.
-