feat:添加文心一眼机器人配置

This commit is contained in:
weifashi 2023-08-01 18:35:17 +08:00
parent 600944fc22
commit d728e2d7c0
4 changed files with 79 additions and 27 deletions

View File

@ -250,18 +250,24 @@ class SystemController extends AbstractController
// //
$type = trim(Request::input('type')); $type = trim(Request::input('type'));
$setting = Base::setting('aibotSetting'); $setting = Base::setting('aibotSetting');
$keys = [
'openai_key',
'openai_agency',
'claude_token',
'claude_agency',
'wenxin_key',
'wenxin_secret',
'wenxin_model'
];
if ($type == 'save') { if ($type == 'save') {
if (env("SYSTEM_SETTING") == 'disabled') { if (env("SYSTEM_SETTING") == 'disabled') {
return Base::retError('当前环境禁止修改'); return Base::retError('当前环境禁止修改');
} }
$all = Request::input(); $all = Request::input();
foreach ($all as $key => $value) { foreach ($all as $key => $value) {
if (!in_array($key, [ if (!in_array($key, $keys)) {
'openai_key',
'openai_agency',
'claude_token',
'claude_agency',
])) {
unset($all[$key]); unset($all[$key]);
} }
} }
@ -280,15 +286,16 @@ class SystemController extends AbstractController
WebSocketDialogMsg::sendMsg(null, $dialog->id, 'text', ['text' => "设置成功"], $botUser->userid, true, false, true); WebSocketDialogMsg::sendMsg(null, $dialog->id, 'text', ['text' => "设置成功"], $botUser->userid, true, false, true);
} }
} }
if ($backup['wenxin_token'] != $setting['wenxin_token']) {
$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);
}
}
} }
// //
if (env("SYSTEM_SETTING") == 'disabled') { if (env("SYSTEM_SETTING") == 'disabled') {
foreach ([ foreach ($keys as $item) {
'openai_key',
'openai_agency',
'claude_token',
'claude_agency',
] as $item) {
$setting[$item] = substr($setting[$item], 0, 4) . str_repeat('*', strlen($setting[$item]) - 8) . substr($setting[$item], -4); $setting[$item] = substr($setting[$item], 0, 4) . str_repeat('*', strlen($setting[$item]) - 8) . substr($setting[$item], -4);
} }
} }

View File

@ -54,6 +54,7 @@ class UserBot extends AbstractModel
'approval-alert' => '审批', 'approval-alert' => '审批',
'ai-openai' => 'ChatGPT', 'ai-openai' => 'ChatGPT',
'ai-claude' => 'Claude', 'ai-claude' => 'Claude',
'ai-wenxin' => 'Wenxin',
'bot-manager' => '机器人管理', 'bot-manager' => '机器人管理',
default => '', // 不是系统机器人时返回空(也可以拿来判断是否是系统机器人) default => '', // 不是系统机器人时返回空(也可以拿来判断是否是系统机器人)
}; };

View File

@ -400,6 +400,23 @@ class BotReceiveMsgTask extends AbstractTask
$error = 'The client version is low (required version ≥ v0.29.11).'; $error = 'The client version is low (required version ≥ v0.29.11).';
} }
break; 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: default:
$userBot = UserBot::whereBotId($botUser->userid)->first(); $userBot = UserBot::whereBotId($botUser->userid)->first();
@ -414,21 +431,30 @@ class BotReceiveMsgTask extends AbstractTask
return; return;
} }
// //
Ihttp::ihttp_post($webhookUrl, [ try {
'text' => $command, $res = Ihttp::ihttp_post($webhookUrl, [
'token' => User::generateToken($botUser), 'text' => $command,
'dialog_id' => $dialog->id, 'token' => User::generateToken($botUser),
'dialog_type' => $dialog->type, 'dialog_id' => $dialog->id,
'msg_id' => $msg->id, 'dialog_type' => $dialog->type,
'msg_uid' => $msg->userid, 'msg_id' => $msg->id,
'mention' => $this->mention ? 1 : 0, 'msg_uid' => $msg->userid,
'bot_uid' => $botUser->userid, 'mention' => $this->mention ? 1 : 0,
'version' => Base::getVersion(), 'bot_uid' => $botUser->userid,
'extras' => Base::array2json($extras) 'version' => Base::getVersion(),
], 10); 'extras' => Base::array2json($extras)
if ($userBot) { ], 10);
$userBot->webhook_num++; if ($userBot) {
$userBot->save(); $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;
} }
} }

View File

@ -27,6 +27,24 @@
</FormItem> </FormItem>
</div> </div>
</div> </div>
<div class="block-setting-box">
<h3>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://console.bce.baidu.com/qianfan/ais/console/onlineTest" target="_blank">https://console.bce.baidu.com/qianfan/ais/console/onlineTest</a> {{$L('')}}</div>
</FormItem>
<FormItem label="API Secret" prop="wenxin_secret">
<Input :maxlength="500" v-model="formData.wenxin_secret" :placeholder="$L('支持 http 或 socks 代理')"/>
</FormItem>
<FormItem label="模型" prop="wenxin_model">
<Select v-model="formData.wenxin_model" placement="top">
<Option value="ERNIE-Bot">ERNIE-Bot</Option>
<Option value="ERNIE-Bot-turbo">ERNIE-Bot-turbo</Option>
</Select>
</FormItem>
</div>
</div>
</Form> </Form>
<div class="setting-footer"> <div class="setting-footer">
<Button :loading="loadIng > 0" type="primary" @click="submitForm">{{ $L('提交') }}</Button> <Button :loading="loadIng > 0" type="primary" @click="submitForm">{{ $L('提交') }}</Button>