[PR #3332] [Other] add legacy /v1/completions for raw-prompt clients (#2277) #4572

Open
opened 2026-11-07 15:37:32 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Niko1221/Strata/pull/3332
Author: @kossum
Created: 10/20/2026
Status: 🔄 Open

Base: main ← Head: serve-completions


📝 Commits (4)

  • e04fe08 serve: add the legacy /v1/completions endpoint
  • 7e08755 fix(serve): restore structured SSE errors and avoid duplicate completion text
  • ca77c15 serve: preserve raw completions prompts and generated text
  • 6c46256 Merge upstream/main into serve-completions

📊 Changes

6 files changed (+465 additions, -24 deletions)

View changed files

📝 docs/DETAILS.md (+9 -0)
📝 serve/frontend.py (+12 -0)
📝 serve/server.py (+211 -21)
📝 serve/test_monitor.py (+17 -0)
📝 serve/test_server.py (+204 -0)
📝 serve/test_structured.py (+12 -3)

📄 Description

Problem and result

Clients that build their own prompts need /v1/completions. Sending those prompts through the chat API would apply the chat template again.

This adds the endpoint for string prompts, with streaming and non-streaming responses in the OpenAI text_completion format, including token usage. It also handles continuing a reply that was cut off by a token limit.

#2277, #2278.

This replaces #2278 after the tracker reset. The reopen format check passed, but GitHub returned "Validation Failed". The bot suggested opening a new PR and linking the old one. The earlier review and fixes are in #2278.

The latest changes address the continuation issues reported by @fulgurist in this PR.

Approach

The handler reuses the existing generation path without rendering a chat template. It returns the raw continuation, including </think>, the newlines after it and literal tool-call text.

The initial thinking state comes from whether the prompt's last <think> is still open. This route does not apply automatic answer-room budgeting or reasoning recovery. An explicit request reasoning_budget_tokens still works when continuing an open thinking block.

For anyone already running an earlier version of this branch: disabling thinking no longer appends a no-think tail. Clients that need one must include it in their own prompt. Reasoning budgets from server or shared settings no longer apply to this route, and output markers previously consumed by the chat parser are now preserved.

max_tokens: 0 or a negative value uses the remaining context. With echo: true, the prompt is returned once at the start and the finish chunk has empty text.

The structured-output error handler stays in the chat endpoint. Errors after streaming starts are sent as SSE errors followed by [DONE], rather than a second HTTP response inside the stream.

Validation

Tested 6c46256b, after merging main at c62d5e3a.

Passed:

On Windows with Python 3.13.2, using the project venv from Git Bash:

PYTHONUTF8=0 PYTHONIOENCODING=utf-8 .venv/Scripts/python.exe -m unittest discover -s serve -p 'test_*.py' -q

1312 tests, OK with 24 skipped. PYTHONUTF8=0 is needed for the Windows process test to decode the local CP932 tasklist output.

I also tested the merged version against a running Qwen3.8-Flash-Next model with the existing Strata 0.1.53 native engine:

  • Streaming and non-streaming preserve the closing thinking tag and blank lines.
  • A 1024-token answer continuation has no injected wrap-up. Both modes return identical text for this case.
  • Feeding the truncated output back into the prompt continues the list from the next integer.
  • Disabling thinking leaves the prompt-token count unchanged.
  • Stop, echo, Unicode and explicit reasoning-budget checks pass in the tested cases.
  • The chat endpoint returns the requested short answer, and the service remains healthy afterward.

GitHub's Linux / runtime requirements only check passed on this revision. git diff --check upstream/main passed locally.

Failed:

No endpoint or automated-test failures in the checks above. One live response had off-topic reasoning but still gave the correct final answer. Three follow-up requests did not reproduce that; the cause is unconfirmed.

Not run:

  • The full Linux serve suite on this revision. The Linux results previously listed here were for 7e08755f.
  • Native backend builds; the PR's diff against main changes no native backend source.
  • A byte-for-byte comparison of all existing endpoints against the release.
  • The reporter's eval harness.

Limits

The endpoint accepts one string prompt and supports only n=1 and best_of=1. Suffix and logprobs are rejected.

stream_options accepts only include_usage, with streaming enabled. Usage is returned on the finish chunk rather than a separate choices: [] chunk, so the OpenAI streaming-usage format is not fully implemented.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Niko1221/Strata/pull/3332 **Author:** [@kossum](https://github.com/kossum) **Created:** 10/20/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `serve-completions` --- ### 📝 Commits (4) - [`e04fe08`](https://github.com/Niko1221/Strata/commit/e04fe08b681f160e82e252c875b065c0fb6f44ef) serve: add the legacy /v1/completions endpoint - [`7e08755`](https://github.com/Niko1221/Strata/commit/7e08755f0f0239b7db7305b1fad7cc137a454f24) fix(serve): restore structured SSE errors and avoid duplicate completion text - [`ca77c15`](https://github.com/Niko1221/Strata/commit/ca77c15570c9b14f2b68b12b158e2bed7f0e73c5) serve: preserve raw completions prompts and generated text - [`6c46256`](https://github.com/Niko1221/Strata/commit/6c46256b500503d8368e39fa57f0b97941353701) Merge upstream/main into serve-completions ### 📊 Changes **6 files changed** (+465 additions, -24 deletions) <details> <summary>View changed files</summary> 📝 `docs/DETAILS.md` (+9 -0) 📝 `serve/frontend.py` (+12 -0) 📝 `serve/server.py` (+211 -21) 📝 `serve/test_monitor.py` (+17 -0) 📝 `serve/test_server.py` (+204 -0) 📝 `serve/test_structured.py` (+12 -3) </details> ### 📄 Description ## Problem and result Clients that build their own prompts need `/v1/completions`. Sending those prompts through the chat API would apply the chat template again. This adds the endpoint for string prompts, with streaming and non-streaming responses in the OpenAI `text_completion` format, including token usage. It also handles continuing a reply that was cut off by a token limit. ## Related discussion #2277, #2278. This replaces #2278 after the tracker reset. The reopen format check passed, but GitHub returned "Validation Failed". The bot suggested opening a new PR and linking the old one. The earlier review and fixes are in #2278. The latest changes address the continuation issues reported by @fulgurist in this PR. ## Approach The handler reuses the existing generation path without rendering a chat template. It returns the raw continuation, including `</think>`, the newlines after it and literal tool-call text. The initial thinking state comes from whether the prompt's last `<think>` is still open. This route does not apply automatic answer-room budgeting or reasoning recovery. An explicit request `reasoning_budget_tokens` still works when continuing an open thinking block. For anyone already running an earlier version of this branch: disabling thinking no longer appends a no-think tail. Clients that need one must include it in their own prompt. Reasoning budgets from server or shared settings no longer apply to this route, and output markers previously consumed by the chat parser are now preserved. `max_tokens: 0` or a negative value uses the remaining context. With `echo: true`, the prompt is returned once at the start and the finish chunk has empty text. The structured-output error handler stays in the chat endpoint. Errors after streaming starts are sent as SSE errors followed by `[DONE]`, rather than a second HTTP response inside the stream. ## Validation Tested `6c46256b`, after merging main at `c62d5e3a`. **Passed:** On Windows with Python 3.13.2, using the project venv from Git Bash: ```sh PYTHONUTF8=0 PYTHONIOENCODING=utf-8 .venv/Scripts/python.exe -m unittest discover -s serve -p 'test_*.py' -q ``` 1312 tests, OK with 24 skipped. `PYTHONUTF8=0` is needed for the Windows process test to decode the local CP932 `tasklist` output. I also tested the merged version against a running Qwen3.8-Flash-Next model with the existing Strata 0.1.53 native engine: - Streaming and non-streaming preserve the closing thinking tag and blank lines. - A 1024-token answer continuation has no injected wrap-up. Both modes return identical text for this case. - Feeding the truncated output back into the prompt continues the list from the next integer. - Disabling thinking leaves the prompt-token count unchanged. - Stop, echo, Unicode and explicit reasoning-budget checks pass in the tested cases. - The chat endpoint returns the requested short answer, and the service remains healthy afterward. GitHub's `Linux / runtime requirements only` check passed on this revision. `git diff --check upstream/main` passed locally. **Failed:** No endpoint or automated-test failures in the checks above. One live response had off-topic reasoning but still gave the correct final answer. Three follow-up requests did not reproduce that; the cause is unconfirmed. **Not run:** - The full Linux serve suite on this revision. The Linux results previously listed here were for `7e08755f`. - Native backend builds; the PR's diff against main changes no native backend source. - A byte-for-byte comparison of all existing endpoints against the release. - The reporter's eval harness. ## Limits The endpoint accepts one string prompt and supports only `n=1` and `best_of=1`. Suffix and logprobs are rejected. `stream_options` accepts only `include_usage`, with streaming enabled. Usage is returned on the finish chunk rather than a separate `choices: []` chunk, so the OpenAI streaming-usage format is not fully implemented. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Niko1221/Strata#4572
No description provided.