GeminiChatFormatter
public class GeminiChatFormatter extends AbstractBaseFormatter< Content, GenerateContentResponse, GenerateContentConfig.Builder>
io/agentscope/extensions/model/gemini/formatter/GeminiChatFormatter.java:52–208Gemini 聊天格式化器,与模型服务通信并返回生成或向量化结果。位于 io.agentscope.extensions.model.gemini.formatter 包,继承自 AbstractBaseFormatter<Content, GenerateContentResponse, GenerateContentConfig.Builder>。核心成员包括 doFormat、parseResponse、applyOptions、applyTools、applyToolChoice、GeminiChatFormatter。
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
构造器摘要Constructor Summary
| 构造器Constructor | 说明Description |
|---|---|
public GeminiChatFormatter() | 初始化 `GeminiChatFormatter` 实例。 Creates a new GeminiChatFormatter with default converters and parsers. |
方法摘要Method Summary
| 方法Method | 说明Description |
|---|---|
protected List<Content> doFormat(List<Msg> msgs) | 执行格式操作。 Performs the do format operation. |
public ChatResponse parseResponse(GenerateContentResponse response, Instant startTime) | 解析响应。 Parses the response. |
public void applyOptions(GenerateContentConfig.Builder configBuilder, GenerateOptions options, GenerateOptions defaultOptions) | 应用选项。 Performs the apply options operation. |
public void applyTools(GenerateContentConfig.Builder configBuilder, List<ToolSchema> tools) | 应用工具。 Performs the apply tools operation. |
public void applyToolChoice(GenerateContentConfig.Builder configBuilder, ToolChoice toolChoice) | 应用工具选项。 Performs the apply tool choice operation. |
构造器详情Constructor Detail
GeminiChatFormatter
public GeminiChatFormatter()
初始化 GeminiChatFormatter 实例。
Creates a new GeminiChatFormatter with default converters and parsers.
io/agentscope/extensions/model/gemini/formatter/GeminiChatFormatter.java:63–67方法详情Method Detail
doFormat
protected List<Content> doFormat(List<Msg> msgs)
执行格式操作。
Performs the do format operation.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
msgs | List<Msg> | 消息列表(类型 `List`)。The msgs. |
List<Content>io/agentscope/extensions/model/gemini/formatter/GeminiChatFormatter.java:69–72parseResponse
public ChatResponse parseResponse(GenerateContentResponse response, Instant startTime)
解析响应。
Parses the response.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
response | GenerateContentResponse | 响应(类型 `GenerateContentResponse`)。The response. |
startTime | Instant | 启动时间(类型 `Instant`)。The start time. |
ChatResponseio/agentscope/extensions/model/gemini/formatter/GeminiChatFormatter.java:74–77applyOptions
public void applyOptions(GenerateContentConfig.Builder configBuilder, GenerateOptions options, GenerateOptions defaultOptions)
应用选项。
Performs the apply options operation.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
configBuilder | GenerateContentConfig.Builder | 配置构建器(类型 `GenerateContentConfig.Builder`)。The config builder. |
options | GenerateOptions | 选项(类型 `GenerateOptions`)。The options. |
defaultOptions | GenerateOptions | 默认选项(类型 `GenerateOptions`)。The default options. |
io/agentscope/extensions/model/gemini/formatter/GeminiChatFormatter.java:79–130applyTools
public void applyTools(GenerateContentConfig.Builder configBuilder, List<ToolSchema> tools)
应用工具。
Performs the apply tools operation.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
configBuilder | GenerateContentConfig.Builder | 配置构建器(类型 `GenerateContentConfig.Builder`)。The config builder. |
tools | List<ToolSchema> | 工具列表(类型 `List`)。The tools. |
io/agentscope/extensions/model/gemini/formatter/GeminiChatFormatter.java:192–198applyToolChoice
public void applyToolChoice(GenerateContentConfig.Builder configBuilder, ToolChoice toolChoice)
应用工具选项。
Performs the apply tool choice operation.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
configBuilder | GenerateContentConfig.Builder | 配置构建器(类型 `GenerateContentConfig.Builder`)。The config builder. |
toolChoice | ToolChoice | 工具选项(类型 `ToolChoice`)。The tool choice. |
io/agentscope/extensions/model/gemini/formatter/GeminiChatFormatter.java:200–207