mirror of
https://github.com/CJackHwang/ds2api.git
synced 2026-05-05 00:45:29 +08:00
Core changes: - stream.go: New accumulation buffer architecture with scanner goroutine + select loop, MinChars=16, MaxWait=10ms, first-flush-immediate - dedupe.go: Add TrimContinuationOverlapFromBuilder to avoid string copies - claude/stream_runtime_core.go: Integrate toolstream for incremental text - claude/stream_runtime_finalize.go: toolstream flush support - stream_emitter.js: Reduce DeltaCoalescer thresholds (160->16 chars, 80->20ms) - empty_retry: Add thinking-aware empty output detection - Fix reasoning_content leak and finish_reason=null in edge cases - Fix tail content truncation when max_tokens exceeded Tests: sync test expectations with upstream for thinking content
31 lines
1.1 KiB
Go
31 lines
1.1 KiB
Go
package shared
|
|
|
|
import (
|
|
"net/http"
|
|
"strings"
|
|
)
|
|
|
|
func ShouldWriteUpstreamEmptyOutputError(text, thinking string) bool {
|
|
return strings.TrimSpace(text) == "" && strings.TrimSpace(thinking) == ""
|
|
}
|
|
|
|
func UpstreamEmptyOutputDetail(contentFilter bool, text, thinking string) (int, string, string) {
|
|
_ = text
|
|
if contentFilter {
|
|
return http.StatusBadRequest, "Upstream content filtered the response and returned no output.", "content_filter"
|
|
}
|
|
if thinking != "" {
|
|
return http.StatusTooManyRequests, "Upstream account hit a rate limit and returned reasoning without visible output.", "upstream_empty_output"
|
|
}
|
|
return http.StatusTooManyRequests, "Upstream account hit a rate limit and returned empty output.", "upstream_empty_output"
|
|
}
|
|
|
|
func WriteUpstreamEmptyOutputError(w http.ResponseWriter, text, thinking string, contentFilter bool) bool {
|
|
if !ShouldWriteUpstreamEmptyOutputError(text, thinking) {
|
|
return false
|
|
}
|
|
status, message, code := UpstreamEmptyOutputDetail(contentFilter, text, thinking)
|
|
WriteOpenAIErrorWithCode(w, status, message, code)
|
|
return true
|
|
}
|