OpenAIResponse
@JsonIgnoreProperties(ignoreUnknown = true) public class OpenAIResponse
io/agentscope/extensions/model/openai/dto/OpenAIResponse.java:68–293OpenAIResponse,与模型服务通信并返回生成或向量化结果。位于 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
构造器详情Constructor Detail
OpenAIResponse
public OpenAIResponse()
初始化 OpenAIResponse 实例。
Creates a new instance.
io/agentscope/extensions/model/openai/dto/OpenAIResponse.java:115方法详情Method Detail
getId
public String getId()
获取标识。
Returns the id.
Stringio/agentscope/extensions/model/openai/dto/OpenAIResponse.java:117–119setId
public void setId(String id)
设置标识。
Sets the id.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
id | String | 标识(类型 `String`)。The id. |
io/agentscope/extensions/model/openai/dto/OpenAIResponse.java:121–123getObject
public String getObject()
获取对象。
Returns the object.
Stringio/agentscope/extensions/model/openai/dto/OpenAIResponse.java:125–127setObject
public void setObject(String object)
设置对象。
Sets the object.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
object | String | 对象(类型 `String`)。The object. |
io/agentscope/extensions/model/openai/dto/OpenAIResponse.java:129–131getCreated
public Long getCreated()
获取已创建。
Returns the created.
Longio/agentscope/extensions/model/openai/dto/OpenAIResponse.java:133–135setCreated
public void setCreated(Long created)
设置已创建。
Sets the created.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
created | Long | 已创建(类型 `Long`)。The created. |
io/agentscope/extensions/model/openai/dto/OpenAIResponse.java:137–139getModel
public String getModel()
获取模型。
Returns the model.
Stringio/agentscope/extensions/model/openai/dto/OpenAIResponse.java:141–143setModel
public void setModel(String model)
设置模型。
Sets the model.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
model | String | 模型实例(类型 `String`)。The model. |
io/agentscope/extensions/model/openai/dto/OpenAIResponse.java:145–147getChoices
public List<OpenAIChoice> getChoices()
获取 getChoices。
Returns the choices.
List<OpenAIChoice>io/agentscope/extensions/model/openai/dto/OpenAIResponse.java:149–151setChoices
public void setChoices(List<OpenAIChoice> choices)
设置 setChoices。
Sets the choices.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
choices | List<OpenAIChoice> | choices(类型 `List`)。The choices. |
io/agentscope/extensions/model/openai/dto/OpenAIResponse.java:153–155getUsage
public OpenAIUsage getUsage()
获取用量。
Returns the usage.
OpenAIUsageio/agentscope/extensions/model/openai/dto/OpenAIResponse.java:157–159setUsage
public void setUsage(OpenAIUsage usage)
设置用量。
Sets the usage.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
usage | OpenAIUsage | 用量(类型 `OpenAIUsage`)。The usage. |
io/agentscope/extensions/model/openai/dto/OpenAIResponse.java:161–163getSystemFingerprint
public String getSystemFingerprint()
获取 getSystemFingerprint。
Returns the system fingerprint.
Stringio/agentscope/extensions/model/openai/dto/OpenAIResponse.java:165–167setSystemFingerprint
public void setSystemFingerprint(String systemFingerprint)
设置 setSystemFingerprint。
Sets the system fingerprint.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
systemFingerprint | String | 系统 Fingerprint(类型 `String`)。The system fingerprint. |
io/agentscope/extensions/model/openai/dto/OpenAIResponse.java:169–171getError
public OpenAIError getError()
获取错误。
Returns the error.
OpenAIErrorio/agentscope/extensions/model/openai/dto/OpenAIResponse.java:173–175setError
public void setError(OpenAIError error)
设置错误。
Sets the error.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
error | OpenAIError | 错误(类型 `OpenAIError`)。The error. |
io/agentscope/extensions/model/openai/dto/OpenAIResponse.java:177–179getCode
public String getCode()
获取 getCode。
Returns the code.
Stringio/agentscope/extensions/model/openai/dto/OpenAIResponse.java:181–183setCode
public void setCode(String code)
设置 setCode。
Sets the code.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
code | String | code(类型 `String`)。The code. |
io/agentscope/extensions/model/openai/dto/OpenAIResponse.java:185–187getMessage
public String getMessage()
获取消息。
Returns the message.
Stringio/agentscope/extensions/model/openai/dto/OpenAIResponse.java:189–191setMessage
public void setMessage(String message)
设置消息。
Sets the message.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
message | String | 消息(类型 `String`)。The message. |
io/agentscope/extensions/model/openai/dto/OpenAIResponse.java:193–195getStatus
public String getStatus()
获取状态。
Returns the status.
Stringio/agentscope/extensions/model/openai/dto/OpenAIResponse.java:197–199setStatus
public void setStatus(String status)
设置状态。
Sets the status.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
status | String | 状态(类型 `String`)。The status. |
io/agentscope/extensions/model/openai/dto/OpenAIResponse.java:201–203isError
public boolean isError()
判断是否错误。
Check if this response represents an error.
booleanio/agentscope/extensions/model/openai/dto/OpenAIResponse.java:213–239getEffectiveErrorMessage
public String getEffectiveErrorMessage()
获取 getEffectiveErrorMessage。
Get the effective error message, handling both standard and non-standard formats.
Stringio/agentscope/extensions/model/openai/dto/OpenAIResponse.java:244–249getEffectiveErrorCode
public String getEffectiveErrorCode()
获取 getEffectiveErrorCode。
Get the effective error code, handling both standard and non-standard formats.
Stringio/agentscope/extensions/model/openai/dto/OpenAIResponse.java:254–259isChunk
public boolean isChunk()
检查if 此是流式分块响应。
Check if this is a streaming chunk response.
booleanio/agentscope/extensions/model/openai/dto/OpenAIResponse.java:273–280getFirstChoice
public OpenAIChoice getFirstChoice()
获取第一个选项 if 可用。
Get the first choice if available.
OpenAIChoiceio/agentscope/extensions/model/openai/dto/OpenAIResponse.java:287–292