mirror of
https://github.com/CJackHwang/ds2api.git
synced 2026-05-08 02:15:27 +08:00
- 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>
40 lines
1022 B
Go
40 lines
1022 B
Go
package gemini
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/go-chi/chi/v5"
|
|
|
|
"ds2api/internal/textclean"
|
|
"ds2api/internal/util"
|
|
)
|
|
|
|
var writeJSON = util.WriteJSON
|
|
|
|
type Handler struct {
|
|
Store ConfigReader
|
|
Auth AuthResolver
|
|
DS DeepSeekCaller
|
|
OpenAI OpenAIChatRunner
|
|
}
|
|
|
|
//nolint:unused // used by native Gemini stream/non-stream runtime helpers.
|
|
func stripReferenceMarkersEnabled() bool {
|
|
return textclean.StripReferenceMarkersEnabled()
|
|
}
|
|
|
|
func RegisterRoutes(r chi.Router, h *Handler) {
|
|
r.Post("/v1beta/models/{model}:generateContent", h.GenerateContent)
|
|
r.Post("/v1beta/models/{model}:streamGenerateContent", h.StreamGenerateContent)
|
|
r.Post("/v1/models/{model}:generateContent", h.GenerateContent)
|
|
r.Post("/v1/models/{model}:streamGenerateContent", h.StreamGenerateContent)
|
|
}
|
|
|
|
func (h *Handler) GenerateContent(w http.ResponseWriter, r *http.Request) {
|
|
h.handleGenerateContent(w, r, false)
|
|
}
|
|
|
|
func (h *Handler) StreamGenerateContent(w http.ResponseWriter, r *http.Request) {
|
|
h.handleGenerateContent(w, r, true)
|
|
}
|