OpenAIResponseParser
public class OpenAIResponseParser
源码Source
io/agentscope/extensions/model/openai/formatter/OpenAIResponseParser.java:47–630OpenAIResponse 解析器,与模型服务通信并返回生成或向量化结果。位于 io.agentscope.extensions.model.openai.formatter 包。核心成员包括 parseResponse、parseCompletionResponse、parseChunkResponse、OpenAIResponseParser、FRAGMENT_PLACEHOLDER。
Parses OpenAI HTTP API responses to AgentScope ChatResponse. Handles both non-streaming and streaming (chunk) responses using DTO classes.
字段摘要Field Summary
| 字段Field | 类型Type | 说明Description |
|---|---|---|
FRAGMENT_PLACEHOLDERstaticfinal | String | FRAGMENT PLACEHOLDER字段。 Placeholder name for tool call argument fragments in streaming responses. |
构造器摘要Constructor Summary
| 构造器Constructor | 说明Description |
|---|---|
public OpenAIResponseParser() | 初始化 `OpenAIResponseParser` 实例。 Creates a new instance. |
方法摘要Method Summary
| 方法Method | 说明Description |
|---|---|
public ChatResponse parseResponse(OpenAIResponse response, Instant startTime) | 解析响应。 Parse OpenAI response DTO to AgentScope ChatResponse. |
protected ChatResponse parseCompletionResponse(OpenAIResponse response, Instant startTime) | 解析补全响应。 Parse OpenAI non-streaming response. |
protected ChatResponse parseChunkResponse(OpenAIResponse response, Instant startTime) | 解析分块响应。 Parse OpenAI streaming response chunk. |
字段详情Field Detail
FRAGMENT_PLACEHOLDER
protected static final String FRAGMENT_PLACEHOLDER
staticfinal
FRAGMENT PLACEHOLDER字段。声明为 protected static final String FRAGMENT_PLACEHOLDER。
Placeholder name for tool call argument fragments in streaming responses.
源码Source
io/agentscope/extensions/model/openai/formatter/OpenAIResponseParser.java:52构造器详情Constructor Detail
OpenAIResponseParser
public OpenAIResponseParser()
初始化 OpenAIResponseParser 实例。
Creates a new instance.
源码Source
io/agentscope/extensions/model/openai/formatter/OpenAIResponseParser.java:152方法详情Method Detail
parseResponse
public ChatResponse parseResponse(OpenAIResponse response, Instant startTime)
解析响应。
Parse OpenAI response DTO to AgentScope ChatResponse.
参数Parameters
| 名称Name | 类型Type | 说明Description |
|---|---|---|
response | OpenAIResponse | 响应(类型 `OpenAIResponse`)。OpenAI response DTO |
startTime | Instant | 启动时间(类型 `Instant`)。Request start time for calculating duration |
ChatResponse返回ChatResponse。AgentScope ChatResponse
源码Source
io/agentscope/extensions/model/openai/formatter/OpenAIResponseParser.java:161–167parseCompletionResponse
protected ChatResponse parseCompletionResponse(OpenAIResponse response, Instant startTime)
解析补全响应。
Parse OpenAI non-streaming response.
参数Parameters
| 名称Name | 类型Type | 说明Description |
|---|---|---|
response | OpenAIResponse | 响应(类型 `OpenAIResponse`)。OpenAI response DTO |
startTime | Instant | 启动时间(类型 `Instant`)。Request start time |
ChatResponse返回ChatResponse。AgentScope ChatResponse
源码Source
io/agentscope/extensions/model/openai/formatter/OpenAIResponseParser.java:176–368parseChunkResponse
protected ChatResponse parseChunkResponse(OpenAIResponse response, Instant startTime)
解析分块响应。
Parse OpenAI streaming response chunk.
参数Parameters
| 名称Name | 类型Type | 说明Description |
|---|---|---|
response | OpenAIResponse | 响应(类型 `OpenAIResponse`)。OpenAI chunk response DTO |
startTime | Instant | 启动时间(类型 `Instant`)。Request start time |
ChatResponse返回ChatResponse。AgentScope ChatResponse (or null for malformed chunks)
源码Source
io/agentscope/extensions/model/openai/formatter/OpenAIResponseParser.java:377–629