Fix /chat/completions to allow send only the latest message (#15197)

### What problem does this PR solve?

1. Fix /chat/completions to send only the latest message
2. Allo chat stream=False

### Type of change

- [x] Bug Fix (non-breaking change which fixes an issue)
This commit is contained in:
Wang Qi
2026-05-25 14:23:33 +08:00
committed by GitHub
parent bb148edf4c
commit 5069561abc
5 changed files with 284 additions and 18 deletions

View File

@@ -4082,11 +4082,14 @@ The previous endpoint `POST /api/v1/chats/{chat_id}/completions` is deprecated.
- `'content-Type: application/json'`
- `'Authorization: Bearer <YOUR_API_KEY>'`
- Body:
- `"messages"`: `list[object]`
- `"question"`: `string`
- `"stream"`: `boolean`
- `"chat_id"`: `string` (optional)
- `"session_id"`: `string` (optional)
- `"llm_id"`: `string` (optional)
- `"pass_all_history_messages"`: `boolean` (optional)
##### Request example
@@ -4117,10 +4120,6 @@ curl --request POST \
"stream": true,
"session_id":"9fa7691cb85c11ef9c5f0242ac120005",
"messages": [
{
"role": "assistant",
"content": "Hi! I'\''m your assistant. What can I do for you?"
},
{
"role": "user",
"content": "Who are you?"
@@ -4131,8 +4130,10 @@ curl --request POST \
##### Request Parameters
- `"messages"`: (*Body Parameter*), `list[object]`, *Required*
The conversation messages sent to the model.
- `"messages"`: (*Body Parameter*), `list[object]`
The latest user message, or the conversation messages sent to the model when `pass_all_history_messages` is `true`. Either `messages` or `question` is required.
- `"question"`: (*Body Parameter*), `string`
Latest user question. This is equivalent to passing `messages: [{"role": "user", "content": question}]`.
- `"stream"`: (*Body Parameter*), `boolean`
Indicates whether to output responses in a streaming way:
- `true`: Enable streaming (default).
@@ -4143,6 +4144,8 @@ curl --request POST \
Optional session ID. If `chat_id` is provided but `session_id` is omitted, a new session will be generated automatically.
- `"llm_id"`: (*Body Parameter*), `string`
Optional model override when a specific chat model should be used for this request.
- `"pass_all_history_messages"`: (*Body Parameter*), `boolean`
When `chat_id` and `session_id` are provided, defaults to `false`, so the server uses stored session history and only the latest user message from the request. Set to `true` to replace/use the submitted full `messages` history, and overrides the stored session history.
#### Response