GeminiResponseParser
public class GeminiResponseParser
io/agentscope/extensions/model/gemini/formatter/GeminiResponseParser.java:56–221Gemini 响应解析器,与模型服务通信并返回生成或向量化结果。位于 io.agentscope.extensions.model.gemini.formatter 包。核心成员包括 parseResponse、parsePartsToBlocks、parseToolCall、GeminiResponseParser。
Parses Gemini API responses to AgentScope ChatResponse.
This parser handles the conversion of Gemini's GenerateContentResponse to AgentScope's ChatResponse format, including:
-
Text blocks from text parts
-
Thinking blocks from parts with thought=true flag
-
Tool use blocks from function_call parts
-
Usage metadata with token counts
Important: In Gemini API, thinking content is indicated by the "thought" flag on Part objects.
构造器摘要Constructor Summary
| 构造器Constructor | 说明Description |
|---|---|
public GeminiResponseParser() | 创建新的GeminiResponseParser。 Creates a new GeminiResponseParser. |
方法摘要Method Summary
| 方法Method | 说明Description |
|---|---|
public ChatResponse parseResponse(GenerateContentResponse response, Instant startTime) | 解析响应。 Parse Gemini GenerateContentResponse to AgentScope ChatResponse. |
protected void parsePartsToBlocks(List<Part> parts, List<ContentBlock> blocks) | 解析 `parsePartsToBlocks`。 Parse Gemini Part objects to AgentScope ContentBlocks. |
protected void parseToolCall(FunctionCall functionCall, byte[] thoughtSignature, List<ContentBlock> blocks) | 解析工具调用。 Parse Gemini FunctionCall to ToolUseBlock. |
构造器详情Constructor Detail
GeminiResponseParser
public GeminiResponseParser()
创建新的GeminiResponseParser。
Creates a new GeminiResponseParser.
io/agentscope/extensions/model/gemini/formatter/GeminiResponseParser.java:63方法详情Method Detail
parseResponse
public ChatResponse parseResponse(GenerateContentResponse response, Instant startTime)
解析响应。
Parse Gemini GenerateContentResponse to AgentScope ChatResponse.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
response | GenerateContentResponse | 响应(类型 `GenerateContentResponse`)。Gemini generation response |
startTime | Instant | 启动时间(类型 `Instant`)。Request start time for calculating duration |
ChatResponseio/agentscope/extensions/model/gemini/formatter/GeminiResponseParser.java:72–129parsePartsToBlocks
protected void parsePartsToBlocks(List<Part> parts, List<ContentBlock> blocks)
解析 parsePartsToBlocks。
Parse Gemini Part objects to AgentScope ContentBlocks.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
parts | List<Part> | parts(类型 `List`)。List of Gemini Part objects |
blocks | List<ContentBlock> | 内容块列表(类型 `List`)。List to add parsed ContentBlocks to |
io/agentscope/extensions/model/gemini/formatter/GeminiResponseParser.java:138–164parseToolCall
protected void parseToolCall(FunctionCall functionCall, byte[] thoughtSignature, List<ContentBlock> blocks)
解析工具调用。
Parse Gemini FunctionCall to ToolUseBlock.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
functionCall | FunctionCall | 函数调用(类型 `FunctionCall`)。Gemini FunctionCall object |
thoughtSignature | byte[] | thought Signature(类型 `byte[]`)。Thought signature from the Part (may be null) |
blocks | List<ContentBlock> | 内容块列表(类型 `List`)。List to add parsed ToolUseBlock to |
io/agentscope/extensions/model/gemini/formatter/GeminiResponseParser.java:173–220