feat:添加通义千问机器人

This commit is contained in:
zzw 2023-08-04 18:14:02 +08:00
parent 77d3ba0c3b
commit bc5046c04d
4 changed files with 50 additions and 1 deletions

View File

@ -258,7 +258,9 @@ class SystemController extends AbstractController
'claude_agency',
'wenxin_key',
'wenxin_secret',
'wenxin_model'
'wenxin_model',
'qianwen_key',
'qianwen_model'
];
if ($type == 'save') {
@ -292,6 +294,12 @@ class SystemController extends AbstractController
WebSocketDialogMsg::sendMsg(null, $dialog->id, 'text', ['text' => "设置成功"], $botUser->userid, true, false, true);
}
}
if ($backup['qianwen_key'] != $setting['qianwen_key']) {
$botUser = User::botGetOrCreate('ai-qianwen');
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';
@ -302,6 +310,14 @@ class SystemController extends AbstractController
}
}
}
$setting['qianwen_model'] = $setting['qianwen_model'] ?: 'qwen-v1';
if (env("SYSTEM_SETTING") == 'disabled') {
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('{}'));
}

View File

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

View File

@ -417,6 +417,22 @@ class BotReceiveMsgTask extends AbstractTask
$error = 'The client version is low (required version ≥ v0.29.12).';
}
break;
// QianWen 机器人
case 'ai-qianwen@bot.system':
$setting = Base::setting('aibotSetting');
$webhookUrl = "{$serverUrl}/ai/qianwen/send";
$extras = [
'qianwen_key' => $setting['qianwen_key'],
'qianwen_model' => $setting['qianwen_model'],
'server_url' => $serverUrl,
];
if (empty($extras['qianwen_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();

View File

@ -47,6 +47,22 @@
</FormItem>
</div>
</div>
<div class="block-setting-box">
<h3>{{$L('通义千问')}} (Qianwen)</h3>
<div class="form-box">
<FormItem label="API Key" prop="qianwen_key">
<Input :maxlength="255" v-model="formData.qianwen_key" type="password" placeholder="API Key"/>
<div class="form-tip">{{$L('获取方式')}} <a href="https://help.aliyun.com/document_detail/611472.html?spm=a2c4g.2399481.0.0.648f47feHXVgVP" target="_blank">https://help.aliyun.com/document_detail/611472.html?spm=a2c4g.2399481.0.0.648f47feHXVgVP</a></div>
</FormItem>
<FormItem label="模型" prop="qianwen_model">
<Select v-model="formData.qianwen_model" placement="top">
<Option value="qwen-v1">qwen-v1</Option>
<Option value="qwen-plus-v1">qwen-plus-v1</Option>
</Select>
<div class="form-tip">{{$L('查看说明')}} <a href="https://help.aliyun.com/document_detail/2399481.html?spm=a2c4g.2399480.0.0.6a086e16ihOhbr#90ebe270f8rte" target="_blank">https://help.aliyun.com/document_detail/2399481.html?spm=a2c4g.2399480.0.0.6a086e16ihOhbr#90ebe270f8rte</a></div>
</FormItem>
</div>
</div>
</Form>
<div class="setting-footer">
<Button :loading="loadIng > 0" type="primary" @click="submitForm">{{ $L('提交') }}</Button>