in internal/enricher/enricher.go [834:858]
func extractTextFromResponse(resp *genai.GenerateContentResponse) (string, error) {
if len(resp.Candidates) == 0 || len(resp.Candidates[0].Content.Parts) == 0 {
return "", fmt.Errorf("empty response from Gemini API")
}
// Safely access and return the text
if textPart, ok := resp.Candidates[0].Content.Parts[0].(genai.Text); ok {
// Extract the text between <result> tags
resp := strings.TrimSpace(string(textPart))
if idx1 := strings.LastIndex(resp, "<result>"); idx1 != -1 {
if idx2 := strings.Index(resp[idx1+len("<result>"):], "</result>"); idx2 != -1 {
resp = resp[idx1+len("<result>") : idx1+len("<result>")+idx2]
} else {
return "", nil
}
} else {
return "", nil
}
return resp, nil
}
return "", fmt.Errorf("unexpected response format from Gemini API: %+v", resp)
}