ChatCompletionsRequest
public class ChatCompletionsRequest
io/agentscope/core/chat/completions/model/ChatCompletionsRequest.java:58–114用于聊天补全 HTTP API的请求负载。位于 io.agentscope.core.chat.completions.model 包。核心成员包括 getModel、setModel、getMessages、setMessages、getStream、setStream。
Request payload for the Chat Completions HTTP API.
This request is 100% compatible with OpenAI's Chat Completions API. All fields follow the official OpenAI specification exactly.
Stateless Operation:
This API is fully stateless, just like OpenAI's standard API. The client is responsible for
maintaining conversation history and sending the complete messages array with each
request.
Example Request:
`{
"model": "gpt-4",
"messages": [
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "What's the weather in Hangzhou?"},
{"role": "assistant", "content": "Let me check...", "tool_calls": [...]},
{"role": "tool", "tool_call_id": "call_xxx", "content": "25°C sunny"},
{"role": "user", "content": "Thanks! And tomorrow?"}
],
"stream": false
}
`
Tool Call Flow:
When the assistant calls tools, the response includes tool_calls. The client should:
-
Append the assistant message (with tool_calls) to history
-
Append tool result messages for each tool call
-
Send the updated history in the next request
方法摘要Method Summary
| 方法Method | 说明Description |
|---|---|
public String getModel() | 获取模型。 Returns the model. |
public void setModel(String model) | 设置模型。 Sets the model. |
public List<ChatMessage> getMessages() | 获取消息。 Returns the messages. |
public void setMessages(List<ChatMessage> messages) | 设置消息。 Sets the messages. |
public Boolean getStream() | 获取流。 Returns the stream. |
public void setStream(Boolean stream) | 设置流。 Sets the stream. |
public List<OpenAITool> getTools() | 获取工具。 Returns the tools. |
public void setTools(List<OpenAITool> tools) | 设置工具。 Sets the tools. |
方法详情Method Detail
getModel
public String getModel()
获取模型。
Returns the model.
Stringio/agentscope/core/chat/completions/model/ChatCompletionsRequest.java:83–85setModel
public void setModel(String model)
设置模型。
Sets the model.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
model | String | 模型实例(类型 `String`)。The model. |
io/agentscope/core/chat/completions/model/ChatCompletionsRequest.java:87–89getMessages
public List<ChatMessage> getMessages()
获取消息。
Returns the messages.
List<ChatMessage>io/agentscope/core/chat/completions/model/ChatCompletionsRequest.java:91–93setMessages
public void setMessages(List<ChatMessage> messages)
设置消息。
Sets the messages.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
messages | List<ChatMessage> | 消息列表(类型 `List`)。The messages. |
io/agentscope/core/chat/completions/model/ChatCompletionsRequest.java:95–97getStream
public Boolean getStream()
获取流。
Returns the stream.
Booleanio/agentscope/core/chat/completions/model/ChatCompletionsRequest.java:99–101setStream
public void setStream(Boolean stream)
设置流。
Sets the stream.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
stream | Boolean | 流(类型 `Boolean`)。The stream. |
io/agentscope/core/chat/completions/model/ChatCompletionsRequest.java:103–105getTools
public List<OpenAITool> getTools()
获取工具。
Returns the tools.
List<OpenAITool>io/agentscope/core/chat/completions/model/ChatCompletionsRequest.java:107–109setTools
public void setTools(List<OpenAITool> tools)
设置工具。
Sets the tools.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
tools | List<OpenAITool> | 工具列表(类型 `List`)。The tools. |
io/agentscope/core/chat/completions/model/ChatCompletionsRequest.java:111–113