From 9033dec0de445b6a83579411ef204e0ab4550167 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8B=A5=E6=B5=B7?= Date: Sat, 13 Apr 2024 21:29:50 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20=E4=BC=98=E5=8C=96=E6=A8=A1=E5=9E=8B?= =?UTF-8?q?=E9=85=8D=E7=BD=AE=E9=80=89=E9=A1=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit !!!BREAKING CHANGES!!! 自定义的openai接口,请添加 /v1 路径 --- dbase/setting/extra.go | 5 - go.mod | 2 +- go.sum | 4 +- webview/src/apps/llmodel/create.html | 41 +++---- webview/src/apps/llmodel/create.ts | 3 +- webview/src/apps/llmodel/update.html | 41 +++---- webview/src/apps/llmodel/update.ts | 3 +- webview/src/openapi/const.ts | 154 ++++++++++++++++++++++----- 8 files changed, 156 insertions(+), 97 deletions(-) diff --git a/dbase/setting/extra.go b/dbase/setting/extra.go index 32a953a..f8cfcd1 100644 --- a/dbase/setting/extra.go +++ b/dbase/setting/extra.go @@ -17,8 +17,6 @@ var ( FriendAccept = true // 添加好友后的响应内容,留空则忽略 FriendHello = "群主去修仙了,请留言" - // 自动下载消息中的文件 - AutoSaveFile = true // 自动下载消息中的图片 AutoSaveImage = true // 群聊撤回消息时响应的内容,留空则忽略 @@ -60,8 +58,6 @@ func Laod() { FriendAccept = item.Value == "true" case "FriendHello": FriendHello = item.Value - case "AutoSaveFile": - AutoSaveImage = item.Value == "true" case "AutoSaveImage": AutoSaveImage = item.Value == "true" case "RevokeMsg": @@ -94,7 +90,6 @@ func DataMigrate() { {0, "InvalidHandler", "text", "bot", InvalidHandler, "指令未注册", "未注册指令时响应的内容,仅对\"/\"开头的指令有效"}, {0, "FriendAccept", "bool", "bot", strconv.FormatBool(FriendAccept), "自动确认好友", "是否自动同意新的好友请求"}, {0, "FriendHello", "string", "bot", FriendHello, "好友打招呼", "添加好友后的响应内容"}, - {0, "AutoSaveFile", "bool", "bot", strconv.FormatBool(AutoSaveFile), "自动保存文件", "是否自动下载消息中的文件"}, {0, "AutoSaveImage", "bool", "bot", strconv.FormatBool(AutoSaveImage), "自动保存图片", "是否自动下载消息中的图片"}, {0, "RevokeMsg", "string", "bot", RevokeMsg, "防撤回提醒", "群聊检测到撤回消息时响应的内容前缀"}, {0, "ModelDefault", "lmodel", "bot", ModelDefault, "默认 AI 模型", "/ai 指令默认使用的模型 Id"}, diff --git a/go.mod b/go.mod index 7044dd4..5b79e7d 100644 --- a/go.mod +++ b/go.mod @@ -9,7 +9,7 @@ require ( github.com/importcjj/sensitive v0.0.0-20200106142752-42d1c505be7b github.com/mitchellh/mapstructure v1.5.0 github.com/opentdp/go-helper v0.7.2 - github.com/rehiy/one-llm v0.2.1-0.20240329113024-83b57b0c6b06 + github.com/rehiy/one-llm v0.3.0 github.com/robfig/cron/v3 v3.0.1 go.nanomsg.org/mangos/v3 v3.4.2 google.golang.org/protobuf v1.33.0 diff --git a/go.sum b/go.sum index 1375692..8d0f5d1 100644 --- a/go.sum +++ b/go.sum @@ -104,8 +104,8 @@ github.com/pelletier/go-toml/v2 v2.2.0 h1:QLgLl2yMN7N+ruc31VynXs1vhMZa7CeHHejIeB github.com/pelletier/go-toml/v2 v2.2.0/go.mod h1:1t835xjRzz80PqgE6HHgN2JOsmgYu/h4qDAS4n929Rs= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/rehiy/one-llm v0.2.1-0.20240329113024-83b57b0c6b06 h1:FlSq860LN3qSoQvJVSS73wB9eFDSNTNIriwZMEi2pr4= -github.com/rehiy/one-llm v0.2.1-0.20240329113024-83b57b0c6b06/go.mod h1:Hvz5KUo9hy+fkwIDwG2ZtZtlHZzVrUhvAau+4/0oZZI= +github.com/rehiy/one-llm v0.3.0 h1:3mr7IZ+TtGaH2EiPiMSa4bJ3INiyVeP4FxSHw38z3CE= +github.com/rehiy/one-llm v0.3.0/go.mod h1:Hvz5KUo9hy+fkwIDwG2ZtZtlHZzVrUhvAau+4/0oZZI= github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec h1:W09IVJc94icq4NjY3clb7Lk8O1qJ8BdBEF8z0ibU0rE= github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo= github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= diff --git a/webview/src/apps/llmodel/create.html b/webview/src/apps/llmodel/create.html index 8e25ceb..8c52a99 100644 --- a/webview/src/apps/llmodel/create.html +++ b/webview/src/apps/llmodel/create.html @@ -50,12 +50,9 @@
未支持的服务商,可尝试使用协议兼容代理 @@ -65,26 +62,28 @@
必须和服务商对应,缺失模型请提 Issue 或 PR 补全 @@ -94,30 +93,14 @@
- @switch (formdata.provider) { - @case ('xunfei') { - 科大讯飞填写 APP-ID,API-KEY,API-SECRET - } - @case ('baidu') { - 文心一言填写 API-KEY,API-SECRET - } - @case ('tencent') { - 腾讯混元填写 APP-ID,API-KEY,API-SECRET - } - @case ('ali') { - 阿里百炼(通义千问)填写 APP-ID,AGENT-KEY,ACCESS_KEY_ID,ACCESS_KEY_SECRET - } - @default { - 请填写从服务商获取的 API-KEY - } - } + {{aiModels[formdata.provider].keystyle || '请填写从服务商获取的 API-KEY'}}
- 自定义接口地址,留空则使用官方接口 + 自定义接口地址,留空则使用官方接口:{{aiModels[formdata.provider].endpoint}}
diff --git a/webview/src/apps/llmodel/create.ts b/webview/src/apps/llmodel/create.ts index ce4ee31..98c74e5 100644 --- a/webview/src/apps/llmodel/create.ts +++ b/webview/src/apps/llmodel/create.ts @@ -1,7 +1,7 @@ import { Component } from '@angular/core'; import { Router } from '@angular/router'; -import { UserLevels } from '../../openapi/const'; +import { AiModels, UserLevels } from '../../openapi/const'; import { RobotApi, LlmodelCreateParam } from '../../openapi/wrobot'; @@ -11,6 +11,7 @@ import { RobotApi, LlmodelCreateParam } from '../../openapi/wrobot'; }) export class LLModelCreateComponent { + public aiModels = AiModels; public userLevels = UserLevels; public formdata: LlmodelCreateParam = { diff --git a/webview/src/apps/llmodel/update.html b/webview/src/apps/llmodel/update.html index ea79ff1..1ac53e4 100644 --- a/webview/src/apps/llmodel/update.html +++ b/webview/src/apps/llmodel/update.html @@ -50,12 +50,9 @@
未支持的服务商,可尝试使用协议兼容代理 @@ -65,26 +62,28 @@
必须和服务商对应,缺失模型请提 Issue 或 PR 补全 @@ -94,30 +93,14 @@
- @switch (formdata.provider) { - @case ('xunfei') { - 科大讯飞填写 APP-ID,API-KEY,API-SECRET - } - @case ('baidu') { - 文心一言填写 API-KEY,API-SECRET - } - @case ('tencent') { - 腾讯混元填写 APP-ID,API-KEY,API-SECRET - } - @case ('ali') { - 阿里百炼(通义千问)填写 APP-ID,AGENT-KEY,ACCESS_KEY_ID,ACCESS_KEY_SECRET - } - @default { - 请填写从服务商获取的 API-KEY - } - } + {{aiModels[formdata.provider].keystyle || '请填写从服务商获取的 API-KEY'}}
- 自定义接口地址,留空则使用官方接口 + 自定义接口地址,留空则使用官方接口:{{aiModels[formdata.provider].endpoint}}
diff --git a/webview/src/apps/llmodel/update.ts b/webview/src/apps/llmodel/update.ts index 1dd2121..02dd487 100644 --- a/webview/src/apps/llmodel/update.ts +++ b/webview/src/apps/llmodel/update.ts @@ -1,7 +1,7 @@ import { Component, OnInit } from '@angular/core'; import { ActivatedRoute, Router } from '@angular/router'; -import { UserLevels } from '../../openapi/const'; +import { AiModels, UserLevels } from '../../openapi/const'; import { RobotApi, LlmodelUpdateParam } from '../../openapi/wrobot'; @@ -11,6 +11,7 @@ import { RobotApi, LlmodelUpdateParam } from '../../openapi/wrobot'; }) export class LLModelUpdateComponent implements OnInit { + public aiModels = AiModels; public userLevels = UserLevels; public formdata: LlmodelUpdateParam = {} as LlmodelUpdateParam; diff --git a/webview/src/openapi/const.ts b/webview/src/openapi/const.ts index a97ae9a..2edf176 100644 --- a/webview/src/openapi/const.ts +++ b/webview/src/openapi/const.ts @@ -2,52 +2,148 @@ interface OptionData { name: string; } +interface AiOptionData extends OptionData { + endpoint: string; + keystyle: string; +} + export const FieldTypes: Record = { - bool: { name: '布尔' }, - number: { name: '数字' }, - string: { name: '字符串' }, - text: { name: '多行文本' }, - lmodel: { name: 'AI 模型' }, + bool: { + name: '布尔', + }, + number: { + name: '数字', + }, + string: { + name: '字符串', + }, + text: { + name: '多行文本', + }, + lmodel: { + name: 'AI 模型', + }, +}; + +export const AiModels: Record = { + aliyun: { + name: '阿里通义千问', + endpoint: 'https://dashscope.aliyuncs.com', + keystyle: '阿里百炼(通义千问)填写 APP-ID,AGENT-KEY,ACCESS_KEY_ID,ACCESS_KEY_SECRET', + }, + baidu: { + name: '百度文心', + endpoint: 'https://aip.baidubce.com/rpc/2.0/ai_custom/v1/wenxinworkshop', + keystyle: '文心一言填写 API-KEY,API-SECRET', + }, + google: { + name: 'Google Gemini', + endpoint: 'https://generativelanguage.googleapis.com', + keystyle: '', + }, + openai: { + name: 'OpenAI GPT', + endpoint: 'https://api.openai.com/v1', + keystyle: '', + }, + tencent: { + name: '腾讯混元', + endpoint: 'https://hunyuan.cloud.tencent.com/hyllm/v1', + keystyle: '腾讯混元填写 APP-ID,API-KEY,API-SECRET', + }, + xunfei: { + name: '科大讯飞', + endpoint: 'wss://spark-api.xf-yun.com', + keystyle: '科大讯飞填写 APP-ID,API-KEY,API-SECRET', + }, }; export const CronjobTypes: Record = { - TEXT: { name: '文本内容' }, - AI: { name: 'AI 生成文本' }, - BAT: { name: 'BAT 批处理' }, - POWERSHELL: { name: 'PowerShell 脚本' }, - EXEC: { name: '可执行程序' }, + TEXT: { + name: '文本内容', + }, + AI: { + name: 'AI 生成文本', + }, + BAT: { + name: 'BAT 批处理', + }, + POWERSHELL: { + name: 'PowerShell 脚本', + }, + EXEC: { + name: '可执行程序', + }, }; export const KeywordGroups: Record = { - badword: { name: '违禁词' }, - handler: { name: '指令别名' }, - command: { name: '外部指令' }, - imagefn: { name: '图片处理' }, + badword: { + name: '违禁词', + }, + handler: { + name: '指令别名', + }, + command: { + name: '外部指令', + }, + imagefn: { + name: '图片处理', + }, }; export const BadwordLevels: Record = { - '-1': { name: '未启用' }, - 1: { name: '一般违规' }, - 2: { name: '中度违规' }, - 3: { name: '严重违规' }, + '-1': { + name: '未启用', + }, + 1: { + name: '一般违规', + }, + 2: { + name: '中度违规', + }, + 3: { + name: '严重违规', + }, }; export const RoomLevels: Record = { - '-1': { name: '未注册' }, - 1: { name: '待验证' }, - 2: { name: '已注册' }, + '-1': { + name: '未注册', + }, + 1: { + name: '待验证', + }, + 2: { + name: '已注册', + }, }; export const UserLevels: Record = { - '-1': { name: '未注册' }, - 1: { name: '待验证' }, - 2: { name: '已注册' }, - 7: { name: '管理员' }, - 9: { name: '创始人' } + '-1': { + name: '未注册', + }, + 1: { + name: '待验证', + }, + 2: { + name: '已注册', + }, + 7: { + name: '管理员', + }, + 9: { + name: '创始人', + } }; export const SpecialRooms: Record = { - '*': { name: '全局' }, - '-': { name: '私聊' }, - '+': { name: '群聊全局' }, + '*': { + name: '全局', + }, + '-': { + name: '私聊', + }, + '+': { + name: '群聊全局', + }, };