Просмотр исходного кода

🐛 (api-v13): AI 内置头像也按 name 匹配,关键字不区分大小写

assistantLogo() 原来只看 model / url 且区分大小写:config 里的 `Claude`
匹配不上 `claude-opus-5-5`,model 为空、只在 name 里写了 Claude 的模型
也拿不到 logo,都显示通用图标。现在 name / model / url 三者分别匹配,统一转小写。

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
visuddhinanda 4 часов назад
Родитель
Сommit
428f90e114
1 измененных файлов с 13 добавлено и 10 удалено
  1. 13 10
      api-v13/app/Services/UserService.php

+ 13 - 10
api-v13/app/Services/UserService.php

@@ -291,7 +291,7 @@ class UserService
             'roles' => ['ai'],
             'sn' => 0,
             'avatar' => $this->avatarUrl($assistant->avatar)
-                ?? $this->assistantLogo($assistant->model, $assistant->url),
+                ?? $this->assistantLogo($assistant->name, $assistant->model, $assistant->url),
         ];
     }
 
@@ -369,19 +369,22 @@ class UserService
     }
 
     /**
-     * AI 助手没有自定义头像时的内置 logo:按 model / url 里的关键字挑,都不匹配
-     * 就用通用图标。
+     * AI 助手没有自定义头像时的内置 logo:按 name / model / url 里的关键字挑(不区分大小写),
+     * 都不匹配就用通用图标。
      */
-    private function assistantLogo(?string $model, ?string $url): string
+    private function assistantLogo(?string $name, ?string $model, ?string $url): string
     {
         $logo = 'ai-assistant.png';
-        // model 与 url 分别匹配,不要拼成一个串:关键字可能跨越拼接处产生假匹配。
-        // 两者都可为 null(新建模型时未必填写),转字符串避免 str_contains 报类型错。
+        // 三个字段分别匹配,不要拼成一个串:关键字可能跨越拼接处产生假匹配。
+        // 都可为 null(新建模型时未必填写),转字符串避免 str_contains 报类型错。
+        $fields = array_map(fn (?string $field) => mb_strtolower((string) $field), [$name, $model, $url]);
         foreach (config('mint.ai.logo', []) as $keyword => $file) {
-            if (str_contains((string) $model, (string) $keyword)
-                || str_contains((string) $url, (string) $keyword)) {
-                $logo = $file;
-                break;
+            $keyword = mb_strtolower((string) $keyword);
+            foreach ($fields as $field) {
+                if (str_contains($field, $keyword)) {
+                    $logo = $file;
+                    break 2;
+                }
             }
         }