Files
ds2api/internal/httpapi/openai/shared/empty_retry.go
CJACK 0378d8c0a9 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>
2026-04-27 18:00:52 +08:00

46 lines
1.2 KiB
Go

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