Bläddra i källkod

本地ollama调用优化

unknown 1 månad sedan
förälder
incheckning
453c6221c1

+ 6 - 2
fastadmin/application/admin/controller/ps/Llm.php

@@ -92,7 +92,11 @@ class Llm extends Backend
                 'timeout'  => (int)($row['llm_timeout'] ?? 30),
                 'timeout'  => (int)($row['llm_timeout'] ?? 30),
             ]);
             ]);
             $models = $client->listModels();
             $models = $client->listModels();
-            $this->success('本地 Ollama 已连通,共 ' . count($models) . ' 个模型', [
+            $msg = '本地 Ollama 已连通,共 ' . count($models) . ' 个模型';
+            if ($models) {
+                $msg .= ':' . implode('、', array_slice($models, 0, 8));
+            }
+            $this->success($msg, null, [
                 'models' => array_slice($models, 0, 30),
                 'models' => array_slice($models, 0, 30),
             ]);
             ]);
         } catch (\Exception $e) {
         } catch (\Exception $e) {
@@ -129,7 +133,7 @@ class Llm extends Backend
                 'timeout'      => (int)($row['llm_online_timeout'] ?? 60),
                 'timeout'      => (int)($row['llm_online_timeout'] ?? 60),
             ]);
             ]);
             $reply = $client->chat('只回复两个字:成功', $model, false);
             $reply = $client->chat('只回复两个字:成功', $model, false);
-            $this->success('线上接口可用', [
+            $this->success('线上接口可用', null, [
                 'model' => $model,
                 'model' => $model,
                 'reply' => mb_substr(trim((string)$reply), 0, 80),
                 'reply' => mb_substr(trim((string)$reply), 0, 80),
             ]);
             ]);

+ 2 - 0
fastadmin/public/assets/js/backend/ps/llm.js

@@ -67,6 +67,7 @@ define(['jquery', 'bootstrap', 'backend', 'form'], function ($, undefined, Backe
                 btn.prop('disabled', true);
                 btn.prop('disabled', true);
                 Fast.api.ajax({
                 Fast.api.ajax({
                     url: 'ps/llm/testOnline',
                     url: 'ps/llm/testOnline',
+                    type: 'POST',
                     data: $('#llm-form').serialize()
                     data: $('#llm-form').serialize()
                 }, function () {
                 }, function () {
                     btn.prop('disabled', false);
                     btn.prop('disabled', false);
@@ -80,6 +81,7 @@ define(['jquery', 'bootstrap', 'backend', 'form'], function ($, undefined, Backe
                 btn.prop('disabled', true);
                 btn.prop('disabled', true);
                 Fast.api.ajax({
                 Fast.api.ajax({
                     url: 'ps/llm/testLocal',
                     url: 'ps/llm/testLocal',
+                    type: 'POST',
                     data: $('#llm-form').serialize()
                     data: $('#llm-form').serialize()
                 }, function () {
                 }, function () {
                     btn.prop('disabled', false);
                     btn.prop('disabled', false);