AS AgentScopeAPI 手册 / API Reference

OpenAIResponseParser

public class OpenAIResponseParser
源码Source io/agentscope/extensions/model/openai/formatter/OpenAIResponseParser.java:47–630

OpenAIResponse 解析器,与模型服务通信并返回生成或向量化结果。位于 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_PLACEHOLDER
staticfinal
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
responseOpenAIResponse响应(类型 `OpenAIResponse`)。OpenAI response DTO
startTimeInstant启动时间(类型 `Instant`)。Request start time for calculating duration
返回Returns ChatResponse
返回ChatResponse。AgentScope ChatResponse
源码Source io/agentscope/extensions/model/openai/formatter/OpenAIResponseParser.java:161–167

parseCompletionResponse

protected ChatResponse parseCompletionResponse(OpenAIResponse response, Instant startTime)

解析补全响应。

Parse OpenAI non-streaming response.

参数Parameters
名称Name类型Type说明Description
responseOpenAIResponse响应(类型 `OpenAIResponse`)。OpenAI response DTO
startTimeInstant启动时间(类型 `Instant`)。Request start time
返回Returns ChatResponse
返回ChatResponse。AgentScope ChatResponse
源码Source io/agentscope/extensions/model/openai/formatter/OpenAIResponseParser.java:176–368

parseChunkResponse

protected ChatResponse parseChunkResponse(OpenAIResponse response, Instant startTime)

解析分块响应。

Parse OpenAI streaming response chunk.

参数Parameters
名称Name类型Type说明Description
responseOpenAIResponse响应(类型 `OpenAIResponse`)。OpenAI chunk response DTO
startTimeInstant启动时间(类型 `Instant`)。Request start time
返回Returns ChatResponse
返回ChatResponse。AgentScope ChatResponse (or null for malformed chunks)
源码Source io/agentscope/extensions/model/openai/formatter/OpenAIResponseParser.java:377–629
基于官方固定版本源码静态生成Generated from pinned official sources · Python 2.0.11 · Java 2.0.4
签名与文档为静态抽取;如有疑问请以源码为准。Signatures and docs are extracted statically; verify against the source when in doubt.