This commit is contained in:
@@ -213,3 +213,18 @@ func TestMergeRecommendationsExcludesIrrelevantAndPendingFiller(t *testing.T) {
|
||||
t.Fatalf("unexpected merged result: %#v", merged)
|
||||
}
|
||||
}
|
||||
|
||||
func TestFilterHardGeminiErrorsIgnoresLowValueVisualFailures(t *testing.T) {
|
||||
errs := []string{
|
||||
"candidate thumbnail is low value",
|
||||
"no candidate thumbnails or preview frames could be fetched for gemini vision",
|
||||
"gemini vision JSON extraction failed: no complete JSON object found",
|
||||
}
|
||||
filtered := filterHardGeminiErrors(errs)
|
||||
if len(filtered) != 1 {
|
||||
t.Fatalf("expected only hard errors to remain, got %#v", filtered)
|
||||
}
|
||||
if !strings.Contains(filtered[0], "JSON extraction failed") {
|
||||
t.Fatalf("unexpected filtered errors: %#v", filtered)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -187,6 +187,7 @@ func EvaluateAllCandidatesWithGeminiWithDeadline(service *GeminiService, query s
|
||||
})
|
||||
}
|
||||
recovered, recoveredErrs := recoverGeminiBatchSequentially(service, query, ranked, batch.index*chunkSize, chunkSize, deadline)
|
||||
hardErrs := filterHardGeminiErrors(recoveredErrs)
|
||||
if len(recovered) > 0 {
|
||||
stats.SequentialRetried++
|
||||
stats.Succeeded++
|
||||
@@ -197,9 +198,9 @@ func EvaluateAllCandidatesWithGeminiWithDeadline(service *GeminiService, query s
|
||||
seen[item.Link] = true
|
||||
merged = append(merged, item)
|
||||
}
|
||||
if len(recoveredErrs) > 0 {
|
||||
if len(hardErrs) > 0 {
|
||||
stats.Failed++
|
||||
for _, recoveredErr := range recoveredErrs {
|
||||
for _, recoveredErr := range hardErrs {
|
||||
if len(stats.Errors) < 5 {
|
||||
stats.Errors = append(stats.Errors, recoveredErr)
|
||||
}
|
||||
@@ -207,6 +208,9 @@ func EvaluateAllCandidatesWithGeminiWithDeadline(service *GeminiService, query s
|
||||
}
|
||||
continue
|
||||
}
|
||||
if len(hardErrs) == 0 {
|
||||
continue
|
||||
}
|
||||
stats.Failed++
|
||||
if len(stats.Errors) < 5 {
|
||||
stats.Errors = append(stats.Errors, batch.err.Error())
|
||||
@@ -345,6 +349,35 @@ func MergeGeminiBatchStats(base, extra GeminiBatchStats) GeminiBatchStats {
|
||||
return merged
|
||||
}
|
||||
|
||||
func filterHardGeminiErrors(errs []string) []string {
|
||||
filtered := make([]string, 0, len(errs))
|
||||
for _, item := range errs {
|
||||
if isIgnorableGeminiError(item) {
|
||||
continue
|
||||
}
|
||||
filtered = append(filtered, item)
|
||||
}
|
||||
return filtered
|
||||
}
|
||||
|
||||
func isIgnorableGeminiError(message string) bool {
|
||||
lower := strings.ToLower(strings.TrimSpace(message))
|
||||
if lower == "" {
|
||||
return false
|
||||
}
|
||||
for _, token := range []string{
|
||||
"no candidate thumbnails or preview frames could be fetched for gemini vision",
|
||||
"candidate thumbnail is low value",
|
||||
"candidate has no thumbnail or preview video",
|
||||
"image url is empty",
|
||||
} {
|
||||
if strings.Contains(lower, token) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func recoverGeminiBatchSequentially(service *GeminiService, query string, ranked []SearchResult, startIndex, chunkSize int, deadline time.Time) ([]AIRecommendation, []string) {
|
||||
recovered := make([]AIRecommendation, 0, chunkSize)
|
||||
errs := make([]string, 0, 4)
|
||||
|
||||
Reference in New Issue
Block a user