mirror of
https://github.com/CJackHwang/ds2api.git
synced 2026-05-23 01:17:44 +08:00
feat: add empty-output retry and Vercel auto-continue support
- Auto-retry Chat/Responses streams once when upstream output is empty but not content-filtered, reusing session/token/PoW and appending a regeneration suffix to the prompt - Wire DeepSeek continue API into Vercel streams for multi-round thinking output exhaustion - Defer empty-output errors in stream finalizers to enable synthetic retry; only surface failure when the retry budget is exhausted - Track content_filter stops to avoid retry on filtered outputs - Add comprehensive tests for stream/non-stream retry, Responses retry, and content_filter no-retry - Update prompt-compatibility.md documentation Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
45
internal/httpapi/openai/shared/empty_retry.go
Normal file
45
internal/httpapi/openai/shared/empty_retry.go
Normal file
@@ -0,0 +1,45 @@
|
||||
package shared
|
||||
|
||||
import "strings"
|
||||
|
||||
const EmptyOutputRetrySuffix = "Previous reply had no visible output. Please regenerate the visible final answer or tool call now."
|
||||
|
||||
func EmptyOutputRetryEnabled() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
func EmptyOutputRetryMaxAttempts() int {
|
||||
return 1
|
||||
}
|
||||
|
||||
func ClonePayloadWithEmptyOutputRetryPrompt(payload map[string]any) map[string]any {
|
||||
clone := make(map[string]any, len(payload))
|
||||
for k, v := range payload {
|
||||
clone[k] = v
|
||||
}
|
||||
original, _ := payload["prompt"].(string)
|
||||
clone["prompt"] = AppendEmptyOutputRetrySuffix(original)
|
||||
return clone
|
||||
}
|
||||
|
||||
func AppendEmptyOutputRetrySuffix(prompt string) string {
|
||||
prompt = strings.TrimRight(prompt, "\r\n\t ")
|
||||
if prompt == "" {
|
||||
return EmptyOutputRetrySuffix
|
||||
}
|
||||
return prompt + "\n\n" + EmptyOutputRetrySuffix
|
||||
}
|
||||
|
||||
func UsagePromptWithEmptyOutputRetry(originalPrompt string, retryAttempts int) string {
|
||||
if retryAttempts <= 0 {
|
||||
return originalPrompt
|
||||
}
|
||||
parts := make([]string, 0, retryAttempts+1)
|
||||
parts = append(parts, originalPrompt)
|
||||
next := originalPrompt
|
||||
for i := 0; i < retryAttempts; i++ {
|
||||
next = AppendEmptyOutputRetrySuffix(next)
|
||||
parts = append(parts, next)
|
||||
}
|
||||
return strings.Join(parts, "\n")
|
||||
}
|
||||
Reference in New Issue
Block a user