fix(修复超时):修复翻译超时!
deploy-hxtesting / build-and-deploy (push) Successful in 1m14s

This commit is contained in:
runny committed 2026-11-30 23:05:36 +08:00
1 parent aa329d7a09
commit 74d21cb204
2 files changed
+19 -1

No files matched your search

+1 -1
View File
@@ -320,7 +320,7 @@ func (c *chatBatchTranslator) translateOnce(ctx context.Context, user string) (s
ch, err := c.model.ChatStream(ctx, []chat.Message{
{Role: "system", Content: translateSystemPrompt},
{Role: "user", Content: user},
}, &chat.ChatOptions{Temperature: 0.2, MaxCompletionTokens: 16384})
}, &chat.ChatOptions{Temperature: 0.2, MaxCompletionTokens: 8192})
if err != nil {
return "", err
}
+18
View File
@@ -4,6 +4,7 @@ import (
"archive/zip"
"bytes"
"context"
"errors"
"fmt"
"regexp"
"sort"
@@ -313,6 +314,9 @@ func Translate(ctx context.Context, data []byte, opt *Options, tr Translator) ([
if failed.Load() {
return // a sibling already failed; stop burning provider calls
}
// Stagger wave starts so concurrency*N streams never hit the
// provider as one simultaneous burst.
time.Sleep(time.Duration(i/concurrency) * 250 * time.Millisecond)
sem <- struct{}{}
defer func() { <-sem }()
out, tokens, err := runBatch(runCtx, tr, batches[i])
@@ -325,8 +329,22 @@ func Translate(ctx context.Context, data []byte, opt *Options, tr Translator) ([
}
wg.Wait()
}
for i := range batches {
if batchErr[i] == nil {
continue
}
// Concurrent batches: when one batch fails the sibling contexts are
// cancelled, so the first error in order is often a cancellation
// VICTIM, not the root cause. Prefer any non-context error.
if errors.Is(batchErr[i], context.Canceled) || errors.Is(batchErr[i], context.DeadlineExceeded) {
continue
}
return nil, report, fmt.Errorf("LLM batch %d failed: %w", i+1, batchErr[i])
}
for i, batch := range batches {
if batchErr[i] != nil {
// Every batch failed with a context error: report the first and
// say so, it means the caller cancelled or the transport dropped.
return nil, report, fmt.Errorf("LLM batch %d failed: %w", i+1, batchErr[i])
}
if len(batchOut[i]) != len(batch) {