opt: add tip message when no available key

This commit is contained in:
RockYang 2023-07-06 10:47:36 +08:00
parent ae255a3bd9
commit 5d0b0ad33e
2 changed files with 5 additions and 2 deletions

View File

@ -197,6 +197,9 @@ func (h *ChatHandler) sendMessage(ctx context.Context, session types.ChatSession
if strings.Contains(err.Error(), "context canceled") { if strings.Contains(err.Error(), "context canceled") {
logger.Info("用户取消了请求:", prompt) logger.Info("用户取消了请求:", prompt)
return nil return nil
} else if strings.Contains(err.Error(), "no available key") {
replyMessage(ws, "抱歉😔😔😔,系统已经没有可用的 API KEY🔑您可以导入自己的 API KEY🔑 继续使用!🙏🙏🙏")
return nil
} else { } else {
logger.Error(err) logger.Error(err)
} }
@ -414,7 +417,7 @@ func (h *ChatHandler) doRequest(ctx context.Context, user vo.User, apiKey *strin
var key model.ApiKey var key model.ApiKey
res := h.db.Where("user_id = ?", 0).Order("last_used_at ASC").First(&key) res := h.db.Where("user_id = ?", 0).Order("last_used_at ASC").First(&key)
if res.Error != nil { if res.Error != nil {
return nil, errors.New("no available key, please import key") return nil, errors.New("no available key")
} }
*apiKey = key.Value *apiKey = key.Value
// 更新 API KEY 的最后使用时间 // 更新 API KEY 的最后使用时间

View File

@ -31,7 +31,7 @@ const sendMsg = () => {
httpGet('/api/verify/token').then(res => { httpGet('/api/verify/token').then(res => {
httpPost('/api/verify/sms', {token: res.data, mobile: props.mobile}).then(() => { httpPost('/api/verify/sms', {token: res.data, mobile: props.mobile}).then(() => {
ElMessage.success('短信发送成功') ElMessage.success('短信发送成功')
let time = 10 let time = 120
btnText.value = time btnText.value = time
const handler = setInterval(() => { const handler = setInterval(() => {
time = time - 1 time = time - 1