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:
CJACK
2026-04-27 17:56:33 +08:00
parent 2d5d211a7a
commit 0378d8c0a9
13 changed files with 1220 additions and 138 deletions

View 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")
}