This commit is contained in:
@@ -306,6 +306,7 @@ User query: ` + query,
|
||||
},
|
||||
"generationConfig": map[string]any{
|
||||
"responseMimeType": "application/json",
|
||||
"maxOutputTokens": 1400,
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
@@ -105,7 +105,7 @@ func EvaluateAllCandidatesWithGemini(service *GeminiService, query string, ranke
|
||||
}
|
||||
|
||||
func EvaluateAllCandidatesWithGeminiWithDeadline(service *GeminiService, query string, ranked []SearchResult, deadline time.Time) ([]AIRecommendation, GeminiBatchStats, error) {
|
||||
const chunkSize = 8
|
||||
const chunkSize = 6
|
||||
const maxConcurrentBatches = 2
|
||||
if service == nil {
|
||||
return nil, GeminiBatchStats{}, fmt.Errorf("gemini service is not configured")
|
||||
@@ -186,7 +186,7 @@ func EvaluateAllCandidatesWithGeminiWithDeadline(service *GeminiService, query s
|
||||
"error": batch.err.Error(),
|
||||
})
|
||||
}
|
||||
recovered, recoveredErrs := recoverGeminiBatchSequentially(service, query, ranked, batch.index*chunkSize)
|
||||
recovered, recoveredErrs := recoverGeminiBatchSequentially(service, query, ranked, batch.index*chunkSize, chunkSize, deadline)
|
||||
if len(recovered) > 0 {
|
||||
stats.SequentialRetried++
|
||||
stats.Succeeded++
|
||||
@@ -345,11 +345,17 @@ func MergeGeminiBatchStats(base, extra GeminiBatchStats) GeminiBatchStats {
|
||||
return merged
|
||||
}
|
||||
|
||||
func recoverGeminiBatchSequentially(service *GeminiService, query string, ranked []SearchResult, startIndex int) ([]AIRecommendation, []string) {
|
||||
recovered := make([]AIRecommendation, 0, 8)
|
||||
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)
|
||||
endIndex := min(startIndex+8, len(ranked))
|
||||
endIndex := min(startIndex+chunkSize, len(ranked))
|
||||
for idx := startIndex; idx < endIndex; idx++ {
|
||||
if !deadline.IsZero() && time.Now().After(deadline) {
|
||||
if len(errs) < 4 {
|
||||
errs = append(errs, "sequential gemini recovery stopped at deadline")
|
||||
}
|
||||
break
|
||||
}
|
||||
recs, err := service.Recommend(query, []SearchResult{ranked[idx]})
|
||||
if err != nil {
|
||||
if len(errs) < 4 {
|
||||
|
||||
Reference in New Issue
Block a user