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