mirror of
https://github.com/kuaifan/dootask.git
synced 2025-12-12 03:01:12 +00:00
perf: 优化 Ollama AI
This commit is contained in:
parent
b3e83e13bc
commit
a8f3b02ee7
@ -331,7 +331,8 @@ class SystemController extends AbstractController
|
|||||||
* @apiGroup system
|
* @apiGroup system
|
||||||
* @apiName setting__aibot_defmodels
|
* @apiName setting__aibot_defmodels
|
||||||
*
|
*
|
||||||
* @apiParam {String} type AI类型
|
* @apiParam {String} type AI类型
|
||||||
|
* @apiParam {String} [base_url] 基础URL(仅 type=ollama 时有效)
|
||||||
*
|
*
|
||||||
* @apiSuccess {Number} ret 返回状态码(1正确、0错误)
|
* @apiSuccess {Number} ret 返回状态码(1正确、0错误)
|
||||||
* @apiSuccess {String} msg 返回信息(错误描述)
|
* @apiSuccess {String} msg 返回信息(错误描述)
|
||||||
@ -340,6 +341,13 @@ class SystemController extends AbstractController
|
|||||||
public function setting__aibot_defmodels()
|
public function setting__aibot_defmodels()
|
||||||
{
|
{
|
||||||
$type = trim(Request::input('type'));
|
$type = trim(Request::input('type'));
|
||||||
|
$baseUrl = trim(Request::input('base_url'));
|
||||||
|
if ($type == 'ollama') {
|
||||||
|
if (empty($baseUrl)) {
|
||||||
|
return Base::retError('请填写基础URL');
|
||||||
|
}
|
||||||
|
return Extranet::ollamaModels($baseUrl);
|
||||||
|
}
|
||||||
$models = Setting::AIDefaultModels($type);
|
$models = Setting::AIDefaultModels($type);
|
||||||
if (empty($models)) {
|
if (empty($models)) {
|
||||||
return Base::retError('未找到默认模型');
|
return Base::retError('未找到默认模型');
|
||||||
|
|||||||
@ -159,6 +159,35 @@ class Extranet
|
|||||||
return Base::retSuccess("success", $result);
|
return Base::retSuccess("success", $result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取 ollama 模型
|
||||||
|
* @param $baseUrl
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public static function ollamaModels($baseUrl)
|
||||||
|
{
|
||||||
|
$res = Ihttp::ihttp_request($baseUrl . '/api/tags', [], [], 15);
|
||||||
|
if (Base::isError($res)) {
|
||||||
|
return Base::retError("获取失败", $res);
|
||||||
|
}
|
||||||
|
$resData = Base::json2array($res['data']);
|
||||||
|
if (empty($resData['models'])) {
|
||||||
|
return Base::retError("获取失败", $resData);
|
||||||
|
}
|
||||||
|
$models = [];
|
||||||
|
foreach ($resData['models'] as $model) {
|
||||||
|
if ($model['name'] !== $model['model']) {
|
||||||
|
$models[] = "{$model['model']} | {$model['name']}";
|
||||||
|
} else {
|
||||||
|
$models[] = $model['model'];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return Base::retSuccess("success", [
|
||||||
|
'models' => $models,
|
||||||
|
'original' => $resData['models']
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取IP地址经纬度
|
* 获取IP地址经纬度
|
||||||
* @param string $ip
|
* @param string $ip
|
||||||
|
|||||||
@ -443,6 +443,9 @@ class BotReceiveMsgTask extends AbstractTask
|
|||||||
if ($type === 'wenxin') {
|
if ($type === 'wenxin') {
|
||||||
$extras['api_key'] .= ':' . $setting['wenxin_secret'];
|
$extras['api_key'] .= ':' . $setting['wenxin_secret'];
|
||||||
}
|
}
|
||||||
|
if ($type === 'ollama' && empty($extras['api_key'])) {
|
||||||
|
$extras['api_key'] = Base::strRandom(6);
|
||||||
|
}
|
||||||
if (empty($extras['api_key'])) {
|
if (empty($extras['api_key'])) {
|
||||||
$errorContent = '机器人未启用。';
|
$errorContent = '机器人未启用。';
|
||||||
}
|
}
|
||||||
|
|||||||
@ -182,8 +182,17 @@ export default {
|
|||||||
|
|
||||||
functionClick(prop) {
|
functionClick(prop) {
|
||||||
if (prop === `${this.type}_models`) {
|
if (prop === `${this.type}_models`) {
|
||||||
|
const data = {};
|
||||||
|
if (this.type === 'ollama') {
|
||||||
|
if (!this.formData[`${this.type}_base_url`]) {
|
||||||
|
$A.modalError('请先填写 Base URL');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
data.base_url = this.formData[`${this.type}_base_url`];
|
||||||
|
}
|
||||||
this.$store.dispatch("call", {
|
this.$store.dispatch("call", {
|
||||||
url: 'system/setting/aibot_defmodels?type=' + this.type,
|
url: 'system/setting/aibot_defmodels?type=' + this.type,
|
||||||
|
data,
|
||||||
spinner: 600,
|
spinner: 600,
|
||||||
}).then(({data}) => {
|
}).then(({data}) => {
|
||||||
this.formData[prop] = data.models.join('\n');
|
this.formData[prop] = data.models.join('\n');
|
||||||
|
|||||||
8
resources/assets/js/store/ai.js
vendored
8
resources/assets/js/store/ai.js
vendored
@ -200,11 +200,17 @@ const AISystemConfig = {
|
|||||||
{
|
{
|
||||||
prop: "key",
|
prop: "key",
|
||||||
placeholder: "Ollama API Key",
|
placeholder: "Ollama API Key",
|
||||||
|
tip: "如果没有请留空",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
prop: "models",
|
prop: "models",
|
||||||
link: "https://ollama.com/models",
|
link: "https://ollama.com/models",
|
||||||
functions: null,
|
functions: "获取本地模型列表",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
prop: "base_url",
|
||||||
|
placeholder: "Enter base URL...",
|
||||||
|
tip: "API请求的URL路径",
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user