mirror of
https://github.com/kuaifan/dootask.git
synced 2025-12-12 11:19:56 +00:00
Merge commit 'a8a2badc99e318319e93ad77aa92d1b3531da391' into pro
This commit is contained in:
commit
3b2460c5d1
@ -250,18 +250,24 @@ class SystemController extends AbstractController
|
||||
//
|
||||
$type = trim(Request::input('type'));
|
||||
$setting = Base::setting('aibotSetting');
|
||||
|
||||
$keys = [
|
||||
'openai_key',
|
||||
'openai_agency',
|
||||
'claude_token',
|
||||
'claude_agency',
|
||||
'wenxin_key',
|
||||
'wenxin_secret',
|
||||
'wenxin_model'
|
||||
];
|
||||
|
||||
if ($type == 'save') {
|
||||
if (env("SYSTEM_SETTING") == 'disabled') {
|
||||
return Base::retError('当前环境禁止修改');
|
||||
}
|
||||
$all = Request::input();
|
||||
foreach ($all as $key => $value) {
|
||||
if (!in_array($key, [
|
||||
'openai_key',
|
||||
'openai_agency',
|
||||
'claude_token',
|
||||
'claude_agency',
|
||||
])) {
|
||||
if (!in_array($key, $keys)) {
|
||||
unset($all[$key]);
|
||||
}
|
||||
}
|
||||
@ -280,18 +286,22 @@ class SystemController extends AbstractController
|
||||
WebSocketDialogMsg::sendMsg(null, $dialog->id, 'text', ['text' => "设置成功"], $botUser->userid, true, false, true);
|
||||
}
|
||||
}
|
||||
if ($backup['wenxin_key'] != $setting['wenxin_key']) {
|
||||
$botUser = User::botGetOrCreate('ai-wenxin');
|
||||
if ($botUser && $dialog = WebSocketDialog::checkUserDialog($botUser, $user->userid)) {
|
||||
WebSocketDialogMsg::sendMsg(null, $dialog->id, 'text', ['text' => "设置成功"], $botUser->userid, true, false, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
//
|
||||
$setting['wenxin_model'] = $setting['wenxin_model'] ?: 'ERNIE-Bot-turbo';
|
||||
if (env("SYSTEM_SETTING") == 'disabled') {
|
||||
foreach ([
|
||||
'openai_key',
|
||||
'openai_agency',
|
||||
'claude_token',
|
||||
'claude_agency',
|
||||
] as $item) {
|
||||
foreach ($keys as $item) {
|
||||
if (strlen($setting[$item]) > 12) {
|
||||
$setting[$item] = substr($setting[$item], 0, 4) . str_repeat('*', strlen($setting[$item]) - 8) . substr($setting[$item], -4);
|
||||
}
|
||||
}
|
||||
}
|
||||
//
|
||||
return Base::retSuccess('success', $setting ?: json_decode('{}'));
|
||||
}
|
||||
|
||||
@ -54,6 +54,7 @@ class UserBot extends AbstractModel
|
||||
'approval-alert' => '审批',
|
||||
'ai-openai' => 'ChatGPT',
|
||||
'ai-claude' => 'Claude',
|
||||
'ai-wenxin' => 'Wenxin',
|
||||
'bot-manager' => '机器人管理',
|
||||
default => '', // 不是系统机器人时返回空(也可以拿来判断是否是系统机器人)
|
||||
};
|
||||
|
||||
@ -400,6 +400,23 @@ class BotReceiveMsgTask extends AbstractTask
|
||||
$error = 'The client version is low (required version ≥ v0.29.11).';
|
||||
}
|
||||
break;
|
||||
// Wenxin 机器人
|
||||
case 'ai-wenxin@bot.system':
|
||||
$setting = Base::setting('aibotSetting');
|
||||
$webhookUrl = "{$serverUrl}/ai/wenxin/send";
|
||||
$extras = [
|
||||
'wenxin_key' => $setting['wenxin_key'],
|
||||
'wenxin_secret' => $setting['wenxin_secret'],
|
||||
'wenxin_model' => $setting['wenxin_model'],
|
||||
'server_url' => $serverUrl,
|
||||
];
|
||||
if (empty($extras['wenxin_key'])) {
|
||||
$error = 'Robot disabled.';
|
||||
} elseif (in_array($this->client['platform'], ['win', 'mac', 'web'])
|
||||
&& !Base::judgeClientVersion("0.29.11", $this->client['version'])) {
|
||||
$error = 'The client version is low (required version ≥ v0.29.12).';
|
||||
}
|
||||
break;
|
||||
// 其他机器人
|
||||
default:
|
||||
$userBot = UserBot::whereBotId($botUser->userid)->first();
|
||||
@ -414,7 +431,8 @@ class BotReceiveMsgTask extends AbstractTask
|
||||
return;
|
||||
}
|
||||
//
|
||||
Ihttp::ihttp_post($webhookUrl, [
|
||||
try {
|
||||
$res = Ihttp::ihttp_post($webhookUrl, [
|
||||
'text' => $command,
|
||||
'token' => User::generateToken($botUser),
|
||||
'dialog_id' => $dialog->id,
|
||||
@ -430,6 +448,14 @@ class BotReceiveMsgTask extends AbstractTask
|
||||
$userBot->webhook_num++;
|
||||
$userBot->save();
|
||||
}
|
||||
if($res['data'] && $data = json_decode($res['data'])){
|
||||
if($data['code'] != 200 && $data['message']){
|
||||
WebSocketDialogMsg::sendMsg(null, $msg->dialog_id, 'text', ['text' => $res['data']['message']], $botUser->userid, false, false, true);
|
||||
}
|
||||
}
|
||||
} catch (\Throwable $th) {
|
||||
//throw $th;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -27,6 +27,26 @@
|
||||
</FormItem>
|
||||
</div>
|
||||
</div>
|
||||
<div class="block-setting-box">
|
||||
<h3>{{$L('文心一言')}} (Wenxin)</h3>
|
||||
<div class="form-box">
|
||||
<FormItem label="API Key" prop="wenxin_key">
|
||||
<Input :maxlength="255" v-model="formData.wenxin_key" type="password" placeholder="API Key"/>
|
||||
<div class="form-tip">{{$L('获取方式')}} <a href="https://ai.baidu.com/ai-doc/REFERENCE/Ck3dwjgn3#3-%E8%8E%B7%E5%8F%96%E5%AF%86%E9%92%A5" target="_blank">https://ai.baidu.com/ai-doc/REFERENCE/Ck3dwjgn3</a></div>
|
||||
</FormItem>
|
||||
<FormItem label="API Secret" prop="wenxin_secret">
|
||||
<Input :maxlength="500" v-model="formData.wenxin_secret" type="password" placeholder="API Secret"/>
|
||||
<div class="form-tip">{{$L('获取方式')}} <a href="https://ai.baidu.com/ai-doc/REFERENCE/Ck3dwjgn3#3-%E8%8E%B7%E5%8F%96%E5%AF%86%E9%92%A5" target="_blank">https://ai.baidu.com/ai-doc/REFERENCE/Ck3dwjgn3</a></div>
|
||||
</FormItem>
|
||||
<FormItem label="模型" prop="wenxin_model">
|
||||
<Select v-model="formData.wenxin_model" placement="top">
|
||||
<Option value="ERNIE-Bot-turbo">ERNIE-Bot-turbo</Option>
|
||||
<Option value="ERNIE-Bot">ERNIE-Bot</Option>
|
||||
</Select>
|
||||
<div class="form-tip">{{$L('查看说明')}} <a href="https://cloud.baidu.com/doc/WENXINWORKSHOP/s/vliu6vq7u" target="_blank">https://cloud.baidu.com/doc/WENXINWORKSHOP/s/vliu6vq7u</a></div>
|
||||
</FormItem>
|
||||
</div>
|
||||
</div>
|
||||
</Form>
|
||||
<div class="setting-footer">
|
||||
<Button :loading="loadIng > 0" type="primary" @click="submitForm">{{ $L('提交') }}</Button>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user