This commit is contained in:
@@ -147,6 +147,11 @@ func (g *GeminiService) ExpandImageQueries(query string) ([]string, error) {
|
||||
}
|
||||
jsonText, err := extractJSONObject(rawText)
|
||||
if err != nil {
|
||||
if looseQueries := parseLooseImageExpansionLines(rawText); len(looseQueries) == 5 {
|
||||
g.setCachedExpansion(cacheKey, looseQueries, 15*time.Minute)
|
||||
g.debug("gemini:image_expand_success", map[string]any{"query": trimmed, "queries": looseQueries, "mode": "loose_text"})
|
||||
return looseQueries, nil
|
||||
}
|
||||
g.debug("gemini:image_expand_parse_error", map[string]any{"query": trimmed, "error": err.Error()})
|
||||
g.setCachedExpansion(cacheKey, fallback, 15*time.Minute)
|
||||
return fallback, err
|
||||
@@ -801,6 +806,34 @@ func truncateForError(text string, limit int) string {
|
||||
return trimmed[:limit] + "..."
|
||||
}
|
||||
|
||||
func parseLooseImageExpansionLines(text string) []string {
|
||||
candidates := make([]string, 0, 8)
|
||||
for _, line := range strings.Split(text, "\n") {
|
||||
trimmed := strings.TrimSpace(line)
|
||||
if trimmed == "" {
|
||||
continue
|
||||
}
|
||||
trimmed = strings.TrimPrefix(trimmed, "- ")
|
||||
trimmed = strings.TrimPrefix(trimmed, "* ")
|
||||
trimmed = strings.TrimPrefix(trimmed, "1. ")
|
||||
trimmed = strings.TrimPrefix(trimmed, "2. ")
|
||||
trimmed = strings.TrimPrefix(trimmed, "3. ")
|
||||
trimmed = strings.TrimPrefix(trimmed, "4. ")
|
||||
trimmed = strings.TrimPrefix(trimmed, "5. ")
|
||||
trimmed = strings.TrimSpace(strings.Trim(trimmed, "\"'`"))
|
||||
lower := strings.ToLower(trimmed)
|
||||
if strings.HasPrefix(lower, "here is") || strings.HasPrefix(lower, "json") || strings.HasPrefix(lower, "output") {
|
||||
continue
|
||||
}
|
||||
candidates = append(candidates, trimmed)
|
||||
}
|
||||
queries := normalizeImageExpansionQueries(candidates)
|
||||
if len(queries) < 5 {
|
||||
return nil
|
||||
}
|
||||
return queries[:5]
|
||||
}
|
||||
|
||||
func normalizeKoreanReason(reason string) string {
|
||||
trimmed := strings.TrimSpace(reason)
|
||||
if trimmed == "" {
|
||||
|
||||
Reference in New Issue
Block a user