handle empty response for gemini

This commit is contained in:
glidea
2025-08-18 16:33:27 +08:00
parent e4bd0ca43b
commit d640e975bd

View File

@@ -21,6 +21,7 @@ import (
"io"
"reflect"
"strconv"
"strings"
"sync"
"time"
@@ -407,6 +408,9 @@ func (c *cached) String(ctx context.Context, messages []string) (string, error)
if err != nil {
return "", err
}
if strings.Trim(value, " \n\r\t") == "" {
return "", errors.New("empty response") // Gemini may occur this.
}
// TODO: reduce copies.
if err = c.kvStorage.Set(ctx, []byte(keyStr), []byte(value), 65*time.Minute); err != nil {