mirror of
https://github.com/kuaifan/dootask.git
synced 2025-12-12 11:19:56 +00:00
perf: 优化 AI 设置
This commit is contained in:
parent
ff41f5c041
commit
b01d5ce8c4
@ -3090,7 +3090,7 @@ class DialogController extends AbstractController
|
|||||||
]
|
]
|
||||||
)) {
|
)) {
|
||||||
WebSocketDialogMsg::sendMsg(null, $dialog_id, 'notice', [
|
WebSocketDialogMsg::sendMsg(null, $dialog_id, 'notice', [
|
||||||
'notice' => $value ? ("修改提示词:" . $value) : "取消提示词",
|
'notice' => $value ? ("修改提示词:" . Base::cutStr($value, 100)) : "取消提示词",
|
||||||
], User::userid(), true, true);
|
], User::userid(), true, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -287,6 +287,7 @@ class SystemController extends AbstractController
|
|||||||
* @apiParam {String} type
|
* @apiParam {String} type
|
||||||
* - get: 获取(默认)
|
* - get: 获取(默认)
|
||||||
* - save: 保存设置(参数:[...])
|
* - save: 保存设置(参数:[...])
|
||||||
|
* @apiParam {String} filter 过滤字段(可选)
|
||||||
*
|
*
|
||||||
* @apiSuccess {Number} ret 返回状态码(1正确、0错误)
|
* @apiSuccess {Number} ret 返回状态码(1正确、0错误)
|
||||||
* @apiSuccess {String} msg 返回信息(错误描述)
|
* @apiSuccess {String} msg 返回信息(错误描述)
|
||||||
@ -297,6 +298,7 @@ class SystemController extends AbstractController
|
|||||||
User::auth('admin');
|
User::auth('admin');
|
||||||
//
|
//
|
||||||
$type = trim(Request::input('type'));
|
$type = trim(Request::input('type'));
|
||||||
|
$filter = trim(Request::input('filter'));
|
||||||
$setting = Base::setting('aibotSetting');
|
$setting = Base::setting('aibotSetting');
|
||||||
if ($type == 'save') {
|
if ($type == 'save') {
|
||||||
if (env("SYSTEM_SETTING") == 'disabled') {
|
if (env("SYSTEM_SETTING") == 'disabled') {
|
||||||
@ -311,10 +313,18 @@ class SystemController extends AbstractController
|
|||||||
}
|
}
|
||||||
$setting = Base::setting('aibotSetting', Base::newTrim($setting));
|
$setting = Base::setting('aibotSetting', Base::newTrim($setting));
|
||||||
}
|
}
|
||||||
|
if ($filter) {
|
||||||
|
$setting = array_filter($setting, function($value, $key) use ($filter) {
|
||||||
|
return str_starts_with($key, $filter);
|
||||||
|
}, ARRAY_FILTER_USE_BOTH);
|
||||||
|
}
|
||||||
//
|
//
|
||||||
if (env("SYSTEM_SETTING") == 'disabled') {
|
if (env("SYSTEM_SETTING") == 'disabled') {
|
||||||
foreach ($setting as $key => $item) {
|
foreach ($setting as $key => $item) {
|
||||||
if (str_contains($key, '_key') && $item) {
|
if (empty($item)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (str_ends_with($key, '_key') || str_ends_with($key, '_secret')) {
|
||||||
$setting[$key] = substr($item, 0, 4) . str_repeat('*', strlen($item) - 8) . substr($item, -4);
|
$setting[$key] = substr($item, 0, 4) . str_repeat('*', strlen($item) - 8) . substr($item, -4);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -66,7 +66,7 @@ class Setting extends AbstractModel
|
|||||||
}
|
}
|
||||||
$array = [];
|
$array = [];
|
||||||
$aiList = ['openai', 'claude', 'deepseek', 'gemini', 'grok', 'ollama', 'zhipu', 'qianwen', 'wenxin'];
|
$aiList = ['openai', 'claude', 'deepseek', 'gemini', 'grok', 'ollama', 'zhipu', 'qianwen', 'wenxin'];
|
||||||
$fieldList = ['key', 'models', 'model', 'base_url', 'agency', 'temperature', 'system', 'secret'];
|
$fieldList = ['key', 'secret', 'models', 'model', 'base_url', 'agency', 'temperature', 'system'];
|
||||||
foreach ($aiList as $aiName) {
|
foreach ($aiList as $aiName) {
|
||||||
foreach ($fieldList as $fieldName) {
|
foreach ($fieldList as $fieldName) {
|
||||||
$key = $aiName . '_' . $fieldName;
|
$key = $aiName . '_' . $fieldName;
|
||||||
|
|||||||
@ -1295,7 +1295,7 @@ class Base
|
|||||||
* 获取或设置
|
* 获取或设置
|
||||||
* @param $setname // 配置名称
|
* @param $setname // 配置名称
|
||||||
* @param bool $array // 保存内容
|
* @param bool $array // 保存内容
|
||||||
* @param false $isUpdate // 保存内容为更新模式,默认否
|
* @param bool $isUpdate // 保存内容为更新模式,默认否
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public static function setting($setname, $array = false, $isUpdate = false)
|
public static function setting($setname, $array = false, $isUpdate = false)
|
||||||
|
|||||||
@ -449,11 +449,12 @@
|
|||||||
<Form :model="modifyData" @submit.native.prevent>
|
<Form :model="modifyData" @submit.native.prevent>
|
||||||
<FormItem prop="value" style="margin-bottom: 16px">
|
<FormItem prop="value" style="margin-bottom: 16px">
|
||||||
<Input
|
<Input
|
||||||
:maxlength="500"
|
:maxlength="20000"
|
||||||
type="textarea"
|
type="textarea"
|
||||||
:autosize="{minRows:3,maxRows:5}"
|
:autosize="{minRows:3,maxRows:5}"
|
||||||
v-model="modifyData.value"
|
v-model="modifyData.value"
|
||||||
:placeholder="$L('例如:你是一个人开发的AI助手')"/>
|
:placeholder="$L('例如:你是一个人开发的AI助手')"
|
||||||
|
show-word-limit/>
|
||||||
</FormItem>
|
</FormItem>
|
||||||
</Form>
|
</Form>
|
||||||
<div slot="footer" class="adaption">
|
<div slot="footer" class="adaption">
|
||||||
@ -2896,7 +2897,8 @@ export default {
|
|||||||
this.modifyLoad++;
|
this.modifyLoad++;
|
||||||
this.$store.dispatch("call", {
|
this.$store.dispatch("call", {
|
||||||
url: 'dialog/config/save',
|
url: 'dialog/config/save',
|
||||||
data: this.modifyData
|
data: this.modifyData,
|
||||||
|
method: 'post'
|
||||||
}).then(({data, msg}) => {
|
}).then(({data, msg}) => {
|
||||||
$A.messageSuccess(msg);
|
$A.messageSuccess(msg);
|
||||||
this.$store.dispatch("saveDialog", data);
|
this.$store.dispatch("saveDialog", data);
|
||||||
|
|||||||
@ -22,11 +22,12 @@
|
|||||||
</template>
|
</template>
|
||||||
<template v-else-if="field.type === 'textarea'">
|
<template v-else-if="field.type === 'textarea'">
|
||||||
<Input
|
<Input
|
||||||
:maxlength="500"
|
:maxlength="field.maxlength || 500"
|
||||||
type="textarea"
|
type="textarea"
|
||||||
:autosize="{minRows:2,maxRows:6}"
|
:autosize="{minRows:2,maxRows:6}"
|
||||||
v-model="formData[field.prop]"
|
v-model="formData[field.prop]"
|
||||||
:placeholder="$L(field.placeholder)"/>
|
:placeholder="$L(field.placeholder)"
|
||||||
|
:show-word-limit="!!field.showWordLimit"/>
|
||||||
</template>
|
</template>
|
||||||
<template v-else>
|
<template v-else>
|
||||||
<Input
|
<Input
|
||||||
@ -174,8 +175,12 @@ export default {
|
|||||||
const data = Object.fromEntries(Object.entries(this.formData).filter(([key]) => props.includes(key)));
|
const data = Object.fromEntries(Object.entries(this.formData).filter(([key]) => props.includes(key)));
|
||||||
this.loadIng++;
|
this.loadIng++;
|
||||||
this.$store.dispatch("call", {
|
this.$store.dispatch("call", {
|
||||||
url: 'system/setting/aibot?type=' + (save ? 'save' : 'all'),
|
url: 'system/setting/aibot',
|
||||||
data: save ? data : {},
|
data: Object.assign(save ? data : {}, {
|
||||||
|
type: save ? 'save' : 'get',
|
||||||
|
filter: this.type,
|
||||||
|
}),
|
||||||
|
method: save ? 'post' : 'get',
|
||||||
}).then(({data}) => {
|
}).then(({data}) => {
|
||||||
if (save) {
|
if (save) {
|
||||||
$A.messageSuccess('修改成功');
|
$A.messageSuccess('修改成功');
|
||||||
|
|||||||
2
resources/assets/js/store/ai.js
vendored
2
resources/assets/js/store/ai.js
vendored
@ -120,6 +120,8 @@ const AISystemConfig = {
|
|||||||
label: "默认提示词",
|
label: "默认提示词",
|
||||||
prop: "system",
|
prop: "system",
|
||||||
type: "textarea",
|
type: "textarea",
|
||||||
|
maxlength: 20000,
|
||||||
|
showWordLimit: true,
|
||||||
placeholder: "请输入默认提示词",
|
placeholder: "请输入默认提示词",
|
||||||
tip: "例如:你是一个人开发的AI助手"
|
tip: "例如:你是一个人开发的AI助手"
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user