返回 DeepSeek-Reasonix
selection.go
根目录 / internal / imageinput / selection.go
1 package imageinput
2
3 import (
4 "errors"
5 "fmt"
6 "slices"
7 "strings"
8
9 "reasonix/internal/provider"
10 )
11
12 // ErrNoModel means no image understanding model can be chosen for a model that
13 // cannot read images itself.
14 var ErrNoModel = errors.New("no image understanding model is configured")
15
16 func (s *Service) selectModel(current string, images []string) (string, error) {
17 if s == nil || s.config.Model == "" {
18 return "", ErrNoModel
19 }
20 target := s.config.Model
21 if target == "auto" {
22 if s.config.Select == nil {
23 return "", fmt.Errorf("image model selection is unavailable")
24 }
25 var ok bool
26 target, ok = s.config.Select(current, target)
27 if !ok || strings.TrimSpace(target) == "" {
28 return "", fmt.Errorf("%w: 当前服务商没有可用的图片理解模型,请在设置中显式选择。", ErrNoModel)
29 }
30 }
31 from, _, fromOK := strings.Cut(current, "/")
32 to, _, toOK := strings.Cut(target, "/")
33 if (!fromOK || !toOK || from != to) && slices.ContainsFunc(images, provider.IsImageFileID) {
34 return "", fmt.Errorf("来源服务商的 file id 不能跨服务商复用")
35 }
36 return target, nil
37 }
38
38 lines GO