fix: retry thinking-only empty outputs, centralize reference marker stripping

- ValidateTurn no longer errors on thinking-only responses, deferring to
  ShouldRetryEmptyOutput which now also covers thinking-only outputs.
- Empty output retry uses multi-turn follow-up with a regeneration prompt
  suffix and parent_message_id in the same DeepSeek session.
- Centralize StripReferenceMarkersEnabled into textclean package to
  eliminate duplicated hardcoded booleans across 4 protocol handlers.
- Log a deprecation warning when the legacy "compat" config key is used.
- Document thinking-only retry and reference marker stripping in API.md.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
CJACK
2026-05-03 05:02:26 +08:00
parent 1286b02247
commit a7522b4188
8 changed files with 30 additions and 6 deletions

View File

@@ -8,6 +8,7 @@ import (
"ds2api/internal/config"
dsprotocol "ds2api/internal/deepseek/protocol"
"ds2api/internal/textclean"
"ds2api/internal/util"
)
@@ -22,7 +23,7 @@ type Handler struct {
}
func stripReferenceMarkersEnabled() bool {
return true
return textclean.StripReferenceMarkersEnabled()
}
var (

View File

@@ -5,6 +5,7 @@ import (
"github.com/go-chi/chi/v5"
"ds2api/internal/textclean"
"ds2api/internal/util"
)
@@ -19,7 +20,7 @@ type Handler struct {
//nolint:unused // used by native Gemini stream/non-stream runtime helpers.
func stripReferenceMarkersEnabled() bool {
return true
return textclean.StripReferenceMarkersEnabled()
}
func RegisterRoutes(r chi.Router, h *Handler) {

View File

@@ -12,6 +12,7 @@ import (
"ds2api/internal/httpapi/openai/history"
"ds2api/internal/httpapi/openai/shared"
"ds2api/internal/promptcompat"
"ds2api/internal/textclean"
"ds2api/internal/toolcall"
"ds2api/internal/toolstream"
)
@@ -36,7 +37,7 @@ type streamLease struct {
}
func stripReferenceMarkersEnabled() bool {
return true
return textclean.StripReferenceMarkersEnabled()
}
func (h *Handler) applyCurrentInputFile(ctx context.Context, a *auth.RequestAuth, stdReq promptcompat.StandardRequest) (promptcompat.StandardRequest, error) {

View File

@@ -11,6 +11,7 @@ import (
"ds2api/internal/httpapi/openai/history"
"ds2api/internal/httpapi/openai/shared"
"ds2api/internal/promptcompat"
"ds2api/internal/textclean"
"ds2api/internal/toolstream"
)
@@ -29,7 +30,7 @@ type Handler struct {
}
func stripReferenceMarkersEnabled() bool {
return true
return textclean.StripReferenceMarkersEnabled()
}
func (h *Handler) applyCurrentInputFile(ctx context.Context, a *auth.RequestAuth, stdReq promptcompat.StandardRequest) (promptcompat.StandardRequest, error) {