类 GeminiChatFormatter
java.lang.Object
io.agentscope.core.formatter.AbstractBaseFormatter<com.google.genai.types.Content,com.google.genai.types.GenerateContentResponse,com.google.genai.types.GenerateContentConfig.Builder>
io.agentscope.core.formatter.gemini.GeminiChatFormatter
- 所有已实现的接口:
Formatter<com.google.genai.types.Content,com.google.genai.types.GenerateContentResponse, com.google.genai.types.GenerateContentConfig.Builder>
public class GeminiChatFormatter
extends AbstractBaseFormatter<com.google.genai.types.Content,com.google.genai.types.GenerateContentResponse,com.google.genai.types.GenerateContentConfig.Builder>
Formatter for Gemini Content Generation API.
Converts between AgentScope Msg objects and Gemini SDK types:
- Msg → Content (request format)
- GenerateContentResponse → ChatResponse (response parsing)
- ToolSchema → Tool (tool definitions)
Important Gemini API Behaviors:
- System messages are converted to "user" role (Gemini doesn't support system role in contents)
- Tool results are independent "user" role Content objects
- Thinking content uses the "thought" flag on Part objects
-
构造器概要
构造器 -
方法概要
修饰符和类型方法说明voidapplyOptions(com.google.genai.types.GenerateContentConfig.Builder configBuilder, GenerateOptions options, GenerateOptions defaultOptions) Apply generation options to provider-specific request parameters.voidapplyToolChoice(com.google.genai.types.GenerateContentConfig.Builder configBuilder, ToolChoice toolChoice) Apply tool choice configuration to provider-specific request parameters.voidapplyTools(com.google.genai.types.GenerateContentConfig.Builder configBuilder, List<ToolSchema> tools) Apply tool schemas to provider-specific request parameters.protected List<com.google.genai.types.Content> parseResponse(com.google.genai.types.GenerateContentResponse response, Instant startTime) Parse provider-specific response to AgentScope ChatResponse.从类继承的方法 io.agentscope.core.formatter.AbstractBaseFormatter
convertToolResultToString, extractTextContent, extractTextContent, format, formatRoleLabel, getOptionOrDefault, hasMediaContent, saveBase64DataToTempFile, shouldBypassHistory从类继承的方法 java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait从接口继承的方法 io.agentscope.core.formatter.Formatter
applyToolChoice, applyTools
-
构造器详细资料
-
GeminiChatFormatter
public GeminiChatFormatter()Creates a new GeminiChatFormatter with default converters and parsers.
-
-
方法详细资料
-
doFormat
- 指定者:
doFormat在类中AbstractBaseFormatter<com.google.genai.types.Content,com.google.genai.types.GenerateContentResponse, com.google.genai.types.GenerateContentConfig.Builder>
-
parseResponse
public ChatResponse parseResponse(com.google.genai.types.GenerateContentResponse response, Instant startTime) 从接口复制的说明:FormatterParse provider-specific response to AgentScope ChatResponse.- 参数:
response- Provider-specific response objectstartTime- Request start time for calculating duration- 返回:
- AgentScope ChatResponse
-
applyOptions
public void applyOptions(com.google.genai.types.GenerateContentConfig.Builder configBuilder, GenerateOptions options, GenerateOptions defaultOptions) 从接口复制的说明:FormatterApply generation options to provider-specific request parameters.- 参数:
configBuilder- Provider-specific request parameters builderoptions- Generation options to applydefaultOptions- Default options to use if options parameter is null
-
applyTools
public void applyTools(com.google.genai.types.GenerateContentConfig.Builder configBuilder, List<ToolSchema> tools) 从接口复制的说明:FormatterApply tool schemas to provider-specific request parameters.- 参数:
configBuilder- Provider-specific request parameters buildertools- List of tool schemas to apply (may be null or empty)
-
applyToolChoice
public void applyToolChoice(com.google.genai.types.GenerateContentConfig.Builder configBuilder, ToolChoice toolChoice) 从接口复制的说明:FormatterApply tool choice configuration to provider-specific request parameters.This method controls how the model uses tools. The default implementation does nothing, allowing formatters to override for providers that support tool choice configuration.
- 参数:
configBuilder- Provider-specific request parameters buildertoolChoice- Tool choice configuration (null means provider default)
-