类 OpenAIResponse
java.lang.Object
io.agentscope.core.formatter.openai.dto.OpenAIResponse
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
}]
}
-
构造器概要
构造器 -
方法概要
修饰符和类型方法说明getError()Get the first choice if available.getId()getModel()getUsage()booleanisChunk()Check if this is a streaming chunk response.booleanisError()Check if this response represents an error.voidsetChoices(List<OpenAIChoice> choices) voidsetCreated(Long created) voidsetError(OpenAIError error) voidvoidvoidvoidsetSystemFingerprint(String systemFingerprint) voidsetUsage(OpenAIUsage usage)
-
构造器详细资料
-
OpenAIResponse
public OpenAIResponse()
-
-
方法详细资料
-
getId
-
setId
-
getObject
-
setObject
-
getCreated
-
setCreated
-
getModel
-
setModel
-
getChoices
-
setChoices
-
getUsage
-
setUsage
-
getSystemFingerprint
-
setSystemFingerprint
-
getError
-
setError
-
isError
public boolean isError()Check if this response represents an error.- 返回:
- true if the response contains an error
-
isChunk
public boolean isChunk()Check if this is a streaming chunk response.Detects streaming chunks by:
- Object type not equals "chat.completion" (Not Streaming)
- Object type equals "chat.completion.chunk" (OpenAI standard)
- OR presence of delta field without message field (GLM and other OpenAI-compatible APIs)
- 返回:
- true if this is a streaming chunk response
-
getFirstChoice
Get the first choice if available.- 返回:
- the first choice, or null if no choices
-