| 123456789101112131415161718192021222324252627282930313233343536 |
- <?php
- namespace app\api\controller\ps;
- use app\common\controller\Api;
- use app\common\library\ps\LlmClient;
- use think\Config;
- /**
- * 大模型连通测试
- */
- class Llm extends Api
- {
- protected $noNeedRight = '*';
- /**
- * 探测本地 Ollama;顺带返回线上是否已启用(不含 Key)
- */
- public function ping()
- {
- $cfg = Config::get('llm') ?: [];
- unset($cfg['api_key'], $cfg['online_api_key']);
- $online = LlmClient::online();
- $out = [
- 'config' => $cfg,
- 'online_enabled' => $online->enabled(),
- 'online_vision' => $online->enabled() ? $online->visionModel() : '',
- ];
- try {
- $models = LlmClient::local()->listModels();
- $this->success('Ollama 已连通', $out + ['models' => $models]);
- } catch (\Exception $e) {
- $this->error($e->getMessage(), $out);
- }
- }
- }
|