From f31e88bed18d3d4795d2edc12af85b5711860cc8 Mon Sep 17 00:00:00 2001 From: kuaifan Date: Sat, 22 Feb 2025 12:14:03 +0800 Subject: [PATCH] no message --- app/Http/Controllers/Api/SystemController.php | 8 +++-- app/Module/Extranet.php | 34 +++++++++---------- .../manage/setting/components/SystemAibot.vue | 1 + 3 files changed, 24 insertions(+), 19 deletions(-) diff --git a/app/Http/Controllers/Api/SystemController.php b/app/Http/Controllers/Api/SystemController.php index 30f5ca193..40195e4d0 100755 --- a/app/Http/Controllers/Api/SystemController.php +++ b/app/Http/Controllers/Api/SystemController.php @@ -333,6 +333,8 @@ class SystemController extends AbstractController * * @apiParam {String} type AI类型 * @apiParam {String} [base_url] 基础URL(仅 type=ollama 时有效) + * @apiParam {String} [key] Key(仅 type=ollama 时有效) + * @apiParam {String} [agency] 使用代理(仅 type=ollama 时有效) * * @apiSuccess {Number} ret 返回状态码(1正确、0错误) * @apiSuccess {String} msg 返回信息(错误描述) @@ -341,12 +343,14 @@ class SystemController extends AbstractController public function setting__aibot_defmodels() { $type = trim(Request::input('type')); - $baseUrl = trim(Request::input('base_url')); if ($type == 'ollama') { + $baseUrl = trim(Request::input('base_url')); + $key = trim(Request::input('key')); + $agency = trim(Request::input('agency')); if (empty($baseUrl)) { return Base::retError('请先填写 Base URL'); } - return Extranet::ollamaModels($baseUrl); + return Extranet::ollamaModels($baseUrl, $key, $agency); } $models = Setting::AIDefaultModels($type); if (empty($models)) { diff --git a/app/Module/Extranet.php b/app/Module/Extranet.php index bc2db2a82..d732c60be 100644 --- a/app/Module/Extranet.php +++ b/app/Module/Extranet.php @@ -34,11 +34,7 @@ class Extranet ]; if ($aibotSetting['openai_agency']) { $extra['CURLOPT_PROXY'] = $aibotSetting['openai_agency']; - if (str_contains($aibotSetting['openai_agency'], 'socks')) { - $extra['CURLOPT_PROXYTYPE'] = CURLPROXY_SOCKS5; - } else { - $extra['CURLOPT_PROXYTYPE'] = CURLPROXY_HTTP; - } + $extra['CURLOPT_PROXYTYPE'] = str_contains($aibotSetting['openai_agency'], 'socks') ? CURLPROXY_SOCKS5 : CURLPROXY_HTTP; } $res = Ihttp::ihttp_request('https://api.openai.com/v1/audio/transcriptions', [ 'file' => new \CURLFile($filePath), @@ -74,11 +70,7 @@ class Extranet ]; if ($aibotSetting['openai_agency']) { $extra['CURLOPT_PROXY'] = $aibotSetting['openai_agency']; - if (str_contains($aibotSetting['openai_agency'], 'socks')) { - $extra['CURLOPT_PROXYTYPE'] = CURLPROXY_SOCKS5; - } else { - $extra['CURLOPT_PROXYTYPE'] = CURLPROXY_HTTP; - } + $extra['CURLOPT_PROXYTYPE'] = str_contains($aibotSetting['openai_agency'], 'socks') ? CURLPROXY_SOCKS5 : CURLPROXY_HTTP; } $res = Ihttp::ihttp_request('https://api.openai.com/v1/chat/completions', json_encode([ "model" => "gpt-4o-mini", @@ -125,11 +117,7 @@ class Extranet ]; if ($aibotSetting['openai_agency']) { $extra['CURLOPT_PROXY'] = $aibotSetting['openai_agency']; - if (str_contains($aibotSetting['openai_agency'], 'socks')) { - $extra['CURLOPT_PROXYTYPE'] = CURLPROXY_SOCKS5; - } else { - $extra['CURLOPT_PROXYTYPE'] = CURLPROXY_HTTP; - } + $extra['CURLOPT_PROXYTYPE'] = str_contains($aibotSetting['openai_agency'], 'socks') ? CURLPROXY_SOCKS5 : CURLPROXY_HTTP; } $res = Ihttp::ihttp_request('https://api.openai.com/v1/chat/completions', json_encode([ "model" => "gpt-4o-mini", @@ -162,11 +150,23 @@ class Extranet /** * 获取 ollama 模型 * @param $baseUrl + * @param $key + * @param $agency * @return array */ - public static function ollamaModels($baseUrl) + public static function ollamaModels($baseUrl, $key = null, $agency = null) { - $res = Ihttp::ihttp_request($baseUrl . '/api/tags', [], [], 15); + $extra = [ + 'Content-Type' => 'application/json', + ]; + if ($key) { + $extra['Authorization'] = 'Bearer ' . $key; + } + if ($agency) { + $extra['CURLOPT_PROXY'] = $agency; + $extra['CURLOPT_PROXYTYPE'] = str_contains($agency, 'socks') ? CURLPROXY_SOCKS5 : CURLPROXY_HTTP; + } + $res = Ihttp::ihttp_request($baseUrl . '/api/tags', [], $extra, 15); if (Base::isError($res)) { return Base::retError("获取失败", $res); } diff --git a/resources/assets/js/pages/manage/setting/components/SystemAibot.vue b/resources/assets/js/pages/manage/setting/components/SystemAibot.vue index 5fd820e01..0e2f9617c 100644 --- a/resources/assets/js/pages/manage/setting/components/SystemAibot.vue +++ b/resources/assets/js/pages/manage/setting/components/SystemAibot.vue @@ -202,6 +202,7 @@ export default { } data.base_url = this.formData[`${this.type}_base_url`]; data.key = this.formData[`${this.type}_key`]; + data.agency = this.formData[`${this.type}_agency`]; } this.$store.dispatch("call", { url: 'system/setting/aibot_defmodels?type=' + this.type,