| 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 { |
| return ClonePayloadForEmptyOutputRetry(payload, 0) |
| } |
|
|
| |
| |
| |
| |
| func ClonePayloadForEmptyOutputRetry(payload map[string]any, parentMessageID int) 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) |
| if parentMessageID > 0 { |
| clone["parent_message_id"] = parentMessageID |
| } |
| 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") |
| } |
|
|