AS AgentScopeAPI 手册 / API Reference

OpenAIResponse

@JsonIgnoreProperties(ignoreUnknown = true) public class OpenAIResponse
源码Source io/agentscope/extensions/model/openai/dto/OpenAIResponse.java:68–293

OpenAIResponse,与模型服务通信并返回生成或向量化结果。位于 io.agentscope.extensions.model.openai.dto 包。核心成员包括 getId、setId、getObject、setObject、getCreated、setCreated。

OpenAI Chat Completion API response DTO.

This class represents the response structure from OpenAI's Chat Completion API. It supports both non-streaming and streaming (chunk) responses.

Example non-streaming response:

`{
"id": "chatcmpl-123",
"object": "chat.completion",
"created": 1677652280,
"model": "gpt-4o",
"choices": [{
"index": 0,
"message": {
"role": "assistant",
"content": "Hello!"
},
"finish_reason": "stop"
}],
"usage": {
"prompt_tokens": 10,
"completion_tokens": 20,
"total_tokens": 30
}
}
`

Example streaming chunk:

`{
"id": "chatcmpl-123",
"object": "chat.completion.chunk",
"created": 1677652280,
"model": "gpt-4o",
"choices": [{
"index": 0,
"delta": {
"content": "Hello"
},
"finish_reason": null
}]
}
`

构造器摘要Constructor Summary

构造器Constructor说明Description
public OpenAIResponse()
初始化 `OpenAIResponse` 实例。
Creates a new instance.

方法摘要Method Summary

方法Method说明Description
public String getId()
获取标识。
Returns the id.
public void setId(String id)
设置标识。
Sets the id.
public String getObject()
获取对象。
Returns the object.
public void setObject(String object)
设置对象。
Sets the object.
public Long getCreated()
获取已创建。
Returns the created.
public void setCreated(Long created)
设置已创建。
Sets the created.
public String getModel()
获取模型。
Returns the model.
public void setModel(String model)
设置模型。
Sets the model.
public List<OpenAIChoice> getChoices()
获取 `getChoices`。
Returns the choices.
public void setChoices(List<OpenAIChoice> choices)
设置 `setChoices`。
Sets the choices.
public OpenAIUsage getUsage()
获取用量。
Returns the usage.
public void setUsage(OpenAIUsage usage)
设置用量。
Sets the usage.
public String getSystemFingerprint()
获取 `getSystemFingerprint`。
Returns the system fingerprint.
public void setSystemFingerprint(String systemFingerprint)
设置 `setSystemFingerprint`。
Sets the system fingerprint.
public OpenAIError getError()
获取错误。
Returns the error.
public void setError(OpenAIError error)
设置错误。
Sets the error.
public String getCode()
获取 `getCode`。
Returns the code.
public void setCode(String code)
设置 `setCode`。
Sets the code.
public String getMessage()
获取消息。
Returns the message.
public void setMessage(String message)
设置消息。
Sets the message.
public String getStatus()
获取状态。
Returns the status.
public void setStatus(String status)
设置状态。
Sets the status.
public boolean isError()
判断是否错误。
Check if this response represents an error.
public String getEffectiveErrorMessage()
获取 `getEffectiveErrorMessage`。
Get the effective error message, handling both standard and non-standard formats.
public String getEffectiveErrorCode()
获取 `getEffectiveErrorCode`。
Get the effective error code, handling both standard and non-standard formats.
public boolean isChunk()
检查if 此是流式分块响应。
Check if this is a streaming chunk response.
public OpenAIChoice getFirstChoice()
获取第一个选项 if 可用。
Get the first choice if available.

构造器详情Constructor Detail

OpenAIResponse

public OpenAIResponse()

初始化 OpenAIResponse 实例。

Creates a new instance.

源码Source io/agentscope/extensions/model/openai/dto/OpenAIResponse.java:115

方法详情Method Detail

getId

public String getId()

获取标识。

Returns the id.

返回Returns String
返回字符串结果。Returns a string.
源码Source io/agentscope/extensions/model/openai/dto/OpenAIResponse.java:117–119

setId

public void setId(String id)

设置标识。

Sets the id.

参数Parameters
名称Name类型Type说明Description
idString标识(类型 `String`)。The id.
源码Source io/agentscope/extensions/model/openai/dto/OpenAIResponse.java:121–123

getObject

public String getObject()

获取对象。

Returns the object.

返回Returns String
返回字符串结果。Returns a string.
源码Source io/agentscope/extensions/model/openai/dto/OpenAIResponse.java:125–127

setObject

public void setObject(String object)

设置对象。

Sets the object.

参数Parameters
名称Name类型Type说明Description
objectString对象(类型 `String`)。The object.
源码Source io/agentscope/extensions/model/openai/dto/OpenAIResponse.java:129–131

getCreated

public Long getCreated()

获取已创建。

Returns the created.

返回Returns Long
返回数值结果。Returns a numeric result.
源码Source io/agentscope/extensions/model/openai/dto/OpenAIResponse.java:133–135

setCreated

public void setCreated(Long created)

设置已创建。

Sets the created.

参数Parameters
名称Name类型Type说明Description
createdLong已创建(类型 `Long`)。The created.
源码Source io/agentscope/extensions/model/openai/dto/OpenAIResponse.java:137–139

getModel

public String getModel()

获取模型。

Returns the model.

返回Returns String
返回字符串结果。Returns a string.
源码Source io/agentscope/extensions/model/openai/dto/OpenAIResponse.java:141–143

setModel

public void setModel(String model)

设置模型。

Sets the model.

参数Parameters
名称Name类型Type说明Description
modelString模型实例(类型 `String`)。The model.
源码Source io/agentscope/extensions/model/openai/dto/OpenAIResponse.java:145–147

getChoices

public List<OpenAIChoice> getChoices()

获取 getChoices。

Returns the choices.

返回Returns List<OpenAIChoice>
返回列出。Returns list.
源码Source io/agentscope/extensions/model/openai/dto/OpenAIResponse.java:149–151

setChoices

public void setChoices(List<OpenAIChoice> choices)

设置 setChoices。

Sets the choices.

参数Parameters
名称Name类型Type说明Description
choicesList<OpenAIChoice>choices(类型 `List`)。The choices.
源码Source io/agentscope/extensions/model/openai/dto/OpenAIResponse.java:153–155

getUsage

public OpenAIUsage getUsage()

获取用量。

Returns the usage.

返回Returns OpenAIUsage
返回OpenAIUsage。Returns OpenAI usage.
源码Source io/agentscope/extensions/model/openai/dto/OpenAIResponse.java:157–159

setUsage

public void setUsage(OpenAIUsage usage)

设置用量。

Sets the usage.

参数Parameters
名称Name类型Type说明Description
usageOpenAIUsage用量(类型 `OpenAIUsage`)。The usage.
源码Source io/agentscope/extensions/model/openai/dto/OpenAIResponse.java:161–163

getSystemFingerprint

public String getSystemFingerprint()

获取 getSystemFingerprint。

Returns the system fingerprint.

返回Returns String
返回字符串结果。Returns a string.
源码Source io/agentscope/extensions/model/openai/dto/OpenAIResponse.java:165–167

setSystemFingerprint

public void setSystemFingerprint(String systemFingerprint)

设置 setSystemFingerprint。

Sets the system fingerprint.

参数Parameters
名称Name类型Type说明Description
systemFingerprintString系统 Fingerprint(类型 `String`)。The system fingerprint.
源码Source io/agentscope/extensions/model/openai/dto/OpenAIResponse.java:169–171

getError

public OpenAIError getError()

获取错误。

Returns the error.

返回Returns OpenAIError
返回OpenAIError。Returns OpenAI error.
源码Source io/agentscope/extensions/model/openai/dto/OpenAIResponse.java:173–175

setError

public void setError(OpenAIError error)

设置错误。

Sets the error.

参数Parameters
名称Name类型Type说明Description
errorOpenAIError错误(类型 `OpenAIError`)。The error.
源码Source io/agentscope/extensions/model/openai/dto/OpenAIResponse.java:177–179

getCode

public String getCode()

获取 getCode。

Returns the code.

返回Returns String
返回字符串结果。Returns a string.
源码Source io/agentscope/extensions/model/openai/dto/OpenAIResponse.java:181–183

setCode

public void setCode(String code)

设置 setCode。

Sets the code.

参数Parameters
名称Name类型Type说明Description
codeStringcode(类型 `String`)。The code.
源码Source io/agentscope/extensions/model/openai/dto/OpenAIResponse.java:185–187

getMessage

public String getMessage()

获取消息。

Returns the message.

返回Returns String
返回字符串结果。Returns a string.
源码Source io/agentscope/extensions/model/openai/dto/OpenAIResponse.java:189–191

setMessage

public void setMessage(String message)

设置消息。

Sets the message.

参数Parameters
名称Name类型Type说明Description
messageString消息(类型 `String`)。The message.
源码Source io/agentscope/extensions/model/openai/dto/OpenAIResponse.java:193–195

getStatus

public String getStatus()

获取状态。

Returns the status.

返回Returns String
返回字符串结果。Returns a string.
源码Source io/agentscope/extensions/model/openai/dto/OpenAIResponse.java:197–199

setStatus

public void setStatus(String status)

设置状态。

Sets the status.

参数Parameters
名称Name类型Type说明Description
statusString状态(类型 `String`)。The status.
源码Source io/agentscope/extensions/model/openai/dto/OpenAIResponse.java:201–203

isError

public boolean isError()

判断是否错误。

Check if this response represents an error.

返回Returns boolean
返回布尔值,表示判断结果。true if the response contains an error
源码Source io/agentscope/extensions/model/openai/dto/OpenAIResponse.java:213–239

getEffectiveErrorMessage

public String getEffectiveErrorMessage()

获取 getEffectiveErrorMessage。

Get the effective error message, handling both standard and non-standard formats.

返回Returns String
返回字符串结果。Returns a string.
源码Source io/agentscope/extensions/model/openai/dto/OpenAIResponse.java:244–249

getEffectiveErrorCode

public String getEffectiveErrorCode()

获取 getEffectiveErrorCode。

Get the effective error code, handling both standard and non-standard formats.

返回Returns String
返回字符串结果。Returns a string.
源码Source io/agentscope/extensions/model/openai/dto/OpenAIResponse.java:254–259

isChunk

public boolean isChunk()

检查if 此是流式分块响应。

Check if this is a streaming chunk response.

返回Returns boolean
返回布尔值,表示判断结果。true if this is a streaming chunk response
源码Source io/agentscope/extensions/model/openai/dto/OpenAIResponse.java:273–280

getFirstChoice

public OpenAIChoice getFirstChoice()

获取第一个选项 if 可用。

Get the first choice if available.

返回Returns OpenAIChoice
返回OpenAIChoice。the first choice, or null if no choices
源码Source io/agentscope/extensions/model/openai/dto/OpenAIResponse.java:287–292
基于官方固定版本源码静态生成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.