mirror of
https://github.com/kuaifan/dootask.git
synced 2025-12-12 03:01:12 +00:00
feat:添加文心一眼机器人配置
This commit is contained in:
parent
600944fc22
commit
d728e2d7c0
@ -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,15 +286,16 @@ class SystemController extends AbstractController
|
||||
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') {
|
||||
foreach ([
|
||||
'openai_key',
|
||||
'openai_agency',
|
||||
'claude_token',
|
||||
'claude_agency',
|
||||
] as $item) {
|
||||
foreach ($keys as $item) {
|
||||
$setting[$item] = substr($setting[$item], 0, 4) . str_repeat('*', strlen($setting[$item]) - 8) . substr($setting[$item], -4);
|
||||
}
|
||||
}
|
||||
|
||||
@ -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,21 +431,30 @@ class BotReceiveMsgTask extends AbstractTask
|
||||
return;
|
||||
}
|
||||
//
|
||||
Ihttp::ihttp_post($webhookUrl, [
|
||||
'text' => $command,
|
||||
'token' => User::generateToken($botUser),
|
||||
'dialog_id' => $dialog->id,
|
||||
'dialog_type' => $dialog->type,
|
||||
'msg_id' => $msg->id,
|
||||
'msg_uid' => $msg->userid,
|
||||
'mention' => $this->mention ? 1 : 0,
|
||||
'bot_uid' => $botUser->userid,
|
||||
'version' => Base::getVersion(),
|
||||
'extras' => Base::array2json($extras)
|
||||
], 10);
|
||||
if ($userBot) {
|
||||
$userBot->webhook_num++;
|
||||
$userBot->save();
|
||||
try {
|
||||
$res = Ihttp::ihttp_post($webhookUrl, [
|
||||
'text' => $command,
|
||||
'token' => User::generateToken($botUser),
|
||||
'dialog_id' => $dialog->id,
|
||||
'dialog_type' => $dialog->type,
|
||||
'msg_id' => $msg->id,
|
||||
'msg_uid' => $msg->userid,
|
||||
'mention' => $this->mention ? 1 : 0,
|
||||
'bot_uid' => $botUser->userid,
|
||||
'version' => Base::getVersion(),
|
||||
'extras' => Base::array2json($extras)
|
||||
], 10);
|
||||
if ($userBot) {
|
||||
$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,24 @@
|
||||
</FormItem>
|
||||
</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>
|
||||
<div class="setting-footer">
|
||||
<Button :loading="loadIng > 0" type="primary" @click="submitForm">{{ $L('提交') }}</Button>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user