diff --git a/.DS_Store b/.DS_Store index 350aaf6..8d3c13a 100644 Binary files a/.DS_Store and b/.DS_Store differ diff --git a/admin/.env.example b/admin/.env.example index c23da78..aeabaea 100644 --- a/admin/.env.example +++ b/admin/.env.example @@ -1,6 +1,6 @@ -# 本地链接生产# xxx填写你的后端服务地址后面/api勿删除 -VITE_GLOB_API_URL=https://xxx/api +# 页面标题 +VITE_APP_TITLE = YiAi-Admin +# 接口请求地址,会设置到 axios 的 baseURL 参数上 生产地址测试 - -VITE_GLOB_OPEN_LONG_REPLY=false -VITE_GLOB_APP_PWA=false +VITE_APP_API_BASEURL = https://xxxx/api +VITE_BASE_PATH=/ diff --git a/admin/package.json b/admin/package.json index e503f13..7768325 100644 --- a/admin/package.json +++ b/admin/package.json @@ -1,5 +1,5 @@ { - "version": "2.4.5", + "version": "2.4.0", "scripts": { "dev": "vite", "build:test": "vue-tsc --noEmit && vite build --mode test", diff --git a/admin/src/constants/index.ts b/admin/src/constants/index.ts index dfc7454..7fdc558 100644 --- a/admin/src/constants/index.ts +++ b/admin/src/constants/index.ts @@ -1,305 +1,350 @@ export const USER_STATUS_OPTIONS = [ - { value: 0, label: '待激活' }, - { value: 1, label: '正常' }, - { value: 2, label: '已封禁' }, - { value: 3, label: '黑名单' }, -] + { value: 0, label: "待激活" }, + { value: 1, label: "正常" }, + { value: 2, label: "已封禁" }, + { value: 3, label: "黑名单" }, +]; export const USER_STATUS_MAP = { - 0: '待激活', - 1: '正常', - 2: '已封禁', - 3: '黑名单', -} + 0: "待激活", + 1: "正常", + 2: "已封禁", + 3: "黑名单", +}; export const USER_STATUS_TYPE_MAP = { - 0: 'info', - 1: 'success', - 2: 'danger', - 3: 'danger', -} + 0: "info", + 1: "success", + 2: "danger", + 3: "danger", +}; // 充值类型map 1: 注册赠送 2: 受邀请赠送 3: 邀请人赠送 4: 购买套餐赠送 5: 管理员赠送 6:扫码支付 7: 绘画失败退款 8: 签到奖励 export const RECHARGE_TYPE_MAP = { - 1: '注册赠送', - 2: '受邀请赠送', - 3: '邀请人赠送', - 4: '购买套餐赠送', - 5: '管理员赠送', - 6: '扫码支付', - 7: '绘画失败退款', - 8: '签到奖励', -} + 1: "注册赠送", + 2: "受邀请赠送", + 3: "邀请人赠送", + 4: "购买套餐赠送", + 5: "管理员赠送", + 6: "扫码支付", + 7: "绘画失败退款", + 8: "签到奖励", +}; // 充值数组 export const RECHARGE_TYPE_OPTIONS = [ - { value: 1, label: '注册赠送' }, - { value: 2, label: '受邀请赠送' }, - { value: 3, label: '邀请人赠送' }, - { value: 4, label: '购买套餐赠送' }, - { value: 5, label: '管理员赠送' }, - { value: 6, label: '扫码支付' }, - { value: 7, label: '绘画失败退款' }, - { value: 8, label: '签到奖励' }, -] + { value: 1, label: "注册赠送" }, + { value: 2, label: "受邀请赠送" }, + { value: 3, label: "邀请人赠送" }, + { value: 4, label: "购买套餐赠送" }, + { value: 5, label: "管理员赠送" }, + { value: 6, label: "扫码支付" }, + { value: 7, label: "绘画失败退款" }, + { value: 8, label: "签到奖励" }, +]; -export type UserStatus = keyof typeof USER_STATUS_TYPE_MAP +export type UserStatus = keyof typeof USER_STATUS_TYPE_MAP; // 是否开启额外赠送 export const IS_OPTIONS = { - 0: '关闭', - 1: '开启', -} + 0: "关闭", + 1: "开启", +}; // 是否开启额外赠送类型 export const IS_TYPE_MAP = { - 0: 'danger', - 1: 'success', -} + 0: "danger", + 1: "success", +}; export const PACKAGE_TYPE_OPTIONS = [ - { value: 0, label: '禁用' }, - { value: 1, label: '启动' }, -] + { value: 0, label: "禁用" }, + { value: 1, label: "启动" }, +]; // 扣费形式 1: 按次数扣费 2:按Token扣费 export const DEDUCTION_TYPE_OPTIONS = [ - { value: 1, label: '按次数扣费' }, - { value: 2, label: '按Token扣费' }, -] + { value: 1, label: "按次数扣费" }, + { value: 2, label: "按Token扣费" }, +]; // 扣费形式 map export const DEDUCTION_TYPE_MAP = { - 1: '按次数扣费', - 2: '按Token扣费', -} + 1: "按次数扣费", + 2: "按Token扣费", +}; export const CRAMI_STATUS_OPTIONS = [ - { value: 0, label: '未使用' }, - { value: 1, label: '已使用' }, -] + { value: 0, label: "未使用" }, + { value: 1, label: "已使用" }, +]; // 图片推荐状态0未推荐1已推荐 export const RECOMMEND_STATUS_OPTIONS = [ - { value: 0, label: '未推荐' }, - { value: 1, label: '已推荐' }, -] + { value: 0, label: "未推荐" }, + { value: 1, label: "已推荐" }, +]; // 0 禁用 1 启用 export const ENABLE_STATUS_OPTIONS = [ - { value: 0, label: '禁用' }, - { value: 1, label: '启用' }, - { value: 3, label: '待审核' }, - { value: 4, label: '拒绝共享' }, - { value: 5, label: '通过共享' }, -] + { value: 0, label: "禁用" }, + { value: 1, label: "启用" }, + { value: 3, label: "待审核" }, + { value: 4, label: "拒绝共享" }, + { value: 5, label: "通过共享" }, +]; // 问题状态 0 未解决 1 已解决 export const QUESTION_STATUS_OPTIONS = [ - { value: '0', label: '未启用' }, - { value: '1', label: '已启用' }, -] + { value: "0", label: "未启用" }, + { value: "1", label: "已启用" }, +]; // 问题状态 0 未解决 1 已解决 export const ORDER_STATUS_OPTIONS = [ - { value: 0, label: '待审核' }, - { value: 1, label: '已通过' }, - { value: -1, label: '已拒绝' }, -] + { value: 0, label: "待审核" }, + { value: 1, label: "已通过" }, + { value: -1, label: "已拒绝" }, +]; // 0:未推荐 1:已推荐 数组 export const RECOMMEND_STATUS = [ - { value: 0, label: '未推荐' }, - { value: 1, label: '已推荐' }, -] + { value: 0, label: "未推荐" }, + { value: 1, label: "已推荐" }, +]; // 提现渠道 支付宝 微信 export const WITHDRAW_CHANNEL_OPTIONS = [ - { value: 1, label: '支付宝' }, - { value: 2, label: '微信' }, -] + { value: 1, label: "支付宝" }, + { value: 2, label: "微信" }, +]; // 1 排队中 2 处理中 3 已完成 4 失败 5 超时 export const WITHDRAW_STATUS_OPTIONS = [ - { value: 1, label: '正在排队' }, - { value: 2, label: '正在绘制' }, - { value: 3, label: '绘制完成' }, - { value: 4, label: '绘制失败' }, - { value: 5, label: '绘制超时' }, -] + { value: 1, label: "正在排队" }, + { value: 2, label: "正在绘制" }, + { value: 3, label: "绘制完成" }, + { value: 4, label: "绘制失败" }, + { value: 5, label: "绘制超时" }, +]; // 0 禁用 warning 1启用 状态 success export const ENABLE_STATUS_TYPE_MAP: QuestionStatusMap = { - 0: 'danger', - 1: 'success', -} + 0: "danger", + 1: "success", +}; interface QuestionStatusMap { - [key: number]: string + [key: number]: string; } // 问题状态 0 未解决 1 已解决 映射 export const QUESTION_STATUS_MAP: QuestionStatusMap = { - '-1': '欠费锁定', - '0': '未启用', - '1': '已启用', - '3': '待审核', - '4': '拒绝共享', - '5': '通过共享', -} + "-1": "欠费锁定", + "0": "未启用", + "1": "已启用", + "3": "待审核", + "4": "拒绝共享", + "5": "通过共享", +}; // 问题状态 0 被封号 1 正常 映射 export const KEY_STATUS_MAP: QuestionStatusMap = { - 0: '被封禁', - 1: '工作中', -} + 0: "被封禁", + 1: "工作中", +}; // 账号类型 5$ 18$ 120$ export const ACCOUNT_TYPE_MAP: QuestionStatus = [ - { value: '5$', label: '5$' }, - { value: '18$', label: '18$' }, - { value: '120$', label: '120$' }, - { value: '其他', label: '其他' }, -] + { value: "5$", label: "5$" }, + { value: "18$", label: "18$" }, + { value: "120$", label: "120$" }, + { value: "其他", label: "其他" }, +]; // 模型列表 export const MODEL_LIST = [ - 'gpt-3.5-turbo', - 'gpt-3.5-turbo-1106', - 'gpt-3.5-turbo-16k', - 'gpt-4', - 'gpt-4-0613', - 'gpt-4-32k', - 'gpt-4-32k-0613', - 'gpt-4-1106-preview', - 'gpt-4-vision-preview', - 'gpt-4-all', - 'gpt-4-0125-preview', -] + "gpt-3.5-turbo", + "gpt-3.5-turbo-1106", + "gpt-3.5-turbo-16k", + "gpt-4", + "gpt-4-0613", + "gpt-4-32k", + "gpt-4-32k-0613", + "gpt-4-1106-preview", + "gpt-4-vision-preview", + "gpt-4-all", + "gpt-4-0125-preview", + // claude + "claude-2.0", + "claude-2.1", + // gemini + "gemini-pro", + // 百度文心 + "ERNIE-Bot", + "ERNIE-Bot-4", + "ERNIE-Bot-turbo", + // 阿里通义 + "qwen-turbo", + "qwen-plus", + "qwen-max", + "qwen-max-lingcontext", + // 腾讯混元 + "hunyuan", + // 清华智谱 + "chatglm_turbo", + "chatglm_pro", + "chatglm_std", + "chatglm_lite", + // 360 智脑 + "360GPT_S2_V9", + // 讯飞星火 + "SparkDesk", +]; // 模型列表 0 mj 1 Dall-e export const DRAW_MODEL_LIST = [ - { value: 'mj', label: 'MidjourneyAi' }, - { value: 'DALL-E2', label: 'DALL-E' }, -] + { value: "mj", label: "MidjourneyAi" }, + { value: "DALL-E2", label: "DALL-E" }, +]; // 支付状态列表 status 0:未支付、1:已支付、2、支付失败、3:支付超时 export const PAY_STATUS_OPTIONS = [ - { value: 0, label: '未支付' }, - { value: 1, label: '已支付' }, - { value: 2, label: '支付失败' }, - { value: 3, label: '支付超时' }, -] + { value: 0, label: "未支付" }, + { value: 1, label: "已支付" }, + { value: 2, label: "支付失败" }, + { value: 3, label: "支付超时" }, +]; // 支付状态 status 0:未支付、1:已支付、2、支付失败、3:支付超时 export const PAY_STATUS_MAP: QuestionStatusMap = { - 0: '未支付', - 1: '已支付', - 2: '支付失败', - 3: '支付超时', -} + 0: "未支付", + 1: "已支付", + 2: "支付失败", + 3: "支付超时", +}; // 平台列表 epay: 易支付 hupi:虎皮椒 export const PAY_PLATFORM_LIST = [ - { value: 'epay', label: '易支付' }, - { value: 'hupi', label: '虎皮椒' }, - { value: 'wechat', label: '微信支付' }, - { value: 'mpay', label: '码支付' }, -] + { value: "epay", label: "易支付" }, + { value: "hupi", label: "虎皮椒" }, + { value: "wechat", label: "微信支付" }, + { value: "mpay", label: "码支付" }, +]; // 支付对应 export const PAY_PLATFORM_MAP = { - epay: '易支付', - hupi: '虎皮椒', - wechat: '微信支付', - mpay: '码支付', -} + epay: "易支付", + hupi: "虎皮椒", + wechat: "微信支付", + mpay: "码支付", +}; // 绘画状态 1: 等待中 2: 绘制中 3: 绘制完成 4: 绘制失败 5: 绘制超时 export const DRAW_MJ_STATUS_LIST = [ - { value: 1, label: '等待中' }, - { value: 2, label: '绘制中' }, - { value: 3, label: '绘制完成' }, - { value: 4, label: '绘制失败' }, - { value: 5, label: '绘制超时' }, -] + { value: 1, label: "等待中" }, + { value: 2, label: "绘制中" }, + { value: 3, label: "绘制完成" }, + { value: 4, label: "绘制失败" }, + { value: 5, label: "绘制超时" }, +]; // App角色 系统 system 用户 user export const APP_ROLE_LIST = [ - { value: 'system', label: '系统' }, - { value: 'user', label: '用户' }, -] + { value: "system", label: "系统" }, + { value: "user", label: "用户" }, +]; // 绘画状态 1:排队中 2:绘制中 3:绘制完成 4:绘制失败 5:绘制超时 export const DRAW_STATUS_MAP = { - 1: '排队中', - 2: '绘制中', - 3: '绘制完成', - 4: '绘制失败', - 5: '绘制超时', -} + 1: "排队中", + 2: "绘制中", + 3: "绘制完成", + 4: "绘制失败", + 5: "绘制超时", +}; export const TYPEORIGINLIST = [ - { value: '百度云检测', label: '百度云检测' }, - { value: '自定义检测', label: '自定义检测' }, - { value: 'NineAI检测', label: 'NineAI检测' }, -] + { value: "百度云检测", label: "百度云检测" }, + { value: "自定义检测", label: "自定义检测" }, + { value: "NineAI检测", label: "NineAI检测" }, +]; export const MODELTYPELIST = [ - { value: 1, label: 'OpenAi - [chatGpt]' }, - { value: 2, label: '百度 - [千帆大模型]' }, - { value: 3, label: '清华 - [智谱大模型]' }, -] + { value: 1, label: "OpenAi - [chatGpt]" }, + { value: 2, label: "百度 - [千帆大模型]" }, + { value: 3, label: "清华 - [智谱大模型]" }, +]; export const MODELSMAP = { - 1: 'OPENAI', - 2: '百度文心', - 3: '清华智谱', -} + 1: "OPENAI", + 2: "百度文心", + 3: "清华智谱", +}; export const MODELSMAPLIST = { 1: [ - 'gpt-3.5-turbo', - 'gpt-3.5-turbo-1106', - 'gpt-3.5-turbo-16k', - 'gpt-4', - 'gpt-4-0613', - 'gpt-4-32k', - 'gpt-4-32k-0613', - 'gpt-4-1106-preview', - 'gpt-4-vision-preview', - 'gpt-4-all', - 'gpt-4-0125-preview', + "gpt-3.5-turbo", + "gpt-3.5-turbo-1106", + "gpt-3.5-turbo-16k", + "gpt-4", + "gpt-4-0613", + "gpt-4-32k", + "gpt-4-32k-0613", + "gpt-4-1106-preview", + "gpt-4-vision-preview", + "gpt-4-all", + "gpt-4-0125-preview", + // claude + "claude-2.0", + "claude-2.1", + // gemini + "gemini-pro", + // 百度文心 + "ERNIE-Bot", + "ERNIE-Bot-4", + "ERNIE-Bot-turbo", + // 阿里通义 + "qwen-turbo", + "qwen-plus", + "qwen-max", + "qwen-max-lingcontext", + // 腾讯混元 + "hunyuan", + // 清华智谱 + "chatglm_turbo", + "chatglm_pro", + "chatglm_std", + "chatglm_lite", + // 360 智脑 + "360GPT_S2_V9", + // 讯飞星火 + "SparkDesk", ], 2: [ - 'ERNIE-Bot', - 'ERNIE-Bot', - 'ERNIE-Bot-4', - 'ERNIE-Bot-turbo', - 'BLOOMZ-7B', - 'Llama-2-7b-chat', - 'Llama-2-13b-chat', + "ERNIE-Bot", + "ERNIE-Bot", + "ERNIE-Bot-4", + "ERNIE-Bot-turbo", + "BLOOMZ-7B", + "Llama-2-7b-chat", + "Llama-2-13b-chat", // 'Llama-2-70b-chat', // 'ChatGLM2-6B-32K', - 'Qianfan-BLOOMZ-7B-compressed', - 'Qianfan-Chinese-Llama-2-7B', - 'AquilaChat-7B', + "Qianfan-BLOOMZ-7B-compressed", + "Qianfan-Chinese-Llama-2-7B", + "AquilaChat-7B", ], - 3: [ - 'chatglm_pro', - 'chatglm_std', - 'chatglm_lite', - 'chatglm_lite_32k', - ], -} + 3: ["chatglm_pro", "chatglm_std", "chatglm_lite", "chatglm_lite_32k"], +}; /* 扣费类型 普通余额还是高级余额 */ export const DEDUCTTYPELIST = [ - { value: 1, label: '普通余额' }, - { value: 2, label: '高级余额' }, -] + { value: 1, label: "普通余额" }, + { value: 2, label: "高级余额" }, +]; /* 不同模型在填入key字段的时候 key代表的含义不同 */ export const ModelTypeLabelMap = { - 1: 'APIKey', - 2: 'client_id', - 3: 'AppKey', -} + 1: "APIKey", + 2: "client_id", + 3: "AppKey", +}; diff --git a/admin/src/views/models/key.vue b/admin/src/views/models/key.vue index 7a6f0d0..c09009a 100644 --- a/admin/src/views/models/key.vue +++ b/admin/src/views/models/key.vue @@ -54,6 +54,7 @@ const formPackage = reactive({ deductType: 1, maxRounds: 12, isTokenBased: false, + tokenFeeRatio: 1000, }) const rules = reactive({ @@ -84,6 +85,9 @@ const rules = reactive({ trigger: 'change', }, ], + tokenFeeRatio: [ + { required: true, message: 'token计费比例', trigger: 'change' }, + ], model: [ { required: true, @@ -192,6 +196,7 @@ function handleEditKey(row: any) { maxRounds, isDraw, isTokenBased, + tokenFeeRatio } = row nextTick(() => { Object.assign(formPackage, { @@ -211,6 +216,7 @@ function handleEditKey(row: any) { maxRounds, isDraw, isTokenBased, + tokenFeeRatio }) }) visible.value = true @@ -393,6 +399,18 @@ onMounted(() => { + + + { + + + + + + + ( prompt: string appId?: number options?: { conversationId?: string; parentMessageId?: string; temperature: number } + imageUrl?:string + model?:string signal?: GenericAbortSignal onDownloadProgress?: (progressEvent: AxiosProgressEvent) => void }, ) { return post({ url: '/chatgpt/chat-process', - data: { prompt: params.prompt, appId: params?.appId, options: params.options }, + data: { prompt: params.prompt, appId: params?.appId, options: params.options,imageUrl: params.imageUrl,model: params.model}, signal: params.signal, onDownloadProgress: params.onDownloadProgress, }) diff --git a/chat/src/assets/file.jpeg b/chat/src/assets/file.jpeg new file mode 100644 index 0000000..11dc5a0 Binary files /dev/null and b/chat/src/assets/file.jpeg differ diff --git a/chat/src/layout/components/Login/Email.vue b/chat/src/layout/components/Login/Email.vue index 9044907..d4c005a 100644 --- a/chat/src/layout/components/Login/Email.vue +++ b/chat/src/layout/components/Login/Email.vue @@ -230,6 +230,10 @@ onMounted(() => { +
+ 老用户密码统一重置为112233
+ 登录后请自行修改密码 +
getLocalState(), +export const useChatStore = defineStore("chat-store", { + state: (): Chat.ChatState => getLocalState(), - getters: { - /* 当前选用模型的配置 */ - activeConfig: (state) => { - const uuid = state.active - if (!uuid) - return {} - const config = state.groupList.find(item => item.uuid === uuid)?.config - return config ? JSON.parse(config) : state.baseConfig - }, + getters: { + /* 当前选用模型的配置 */ + activeConfig: (state) => { + const uuid = state.active; + if (!uuid) return {}; + const config = state.groupList.find((item) => item.uuid === uuid)?.config; + return config ? JSON.parse(config) : state.baseConfig; + }, - activeGroupAppId: (state) => { - const uuid = state.active - if (!uuid) - return null - return state.groupList.find(item => item.uuid === uuid)?.appId - }, + activeGroupAppId: (state) => { + const uuid = state.active; + if (!uuid) return null; + return state.groupList.find((item) => item.uuid === uuid)?.appId; + }, - /* 当前选用模型的扣费类型 */ - activeModelKeyDeductType(state) { - return this.activeConfig?.modelInfo?.deductType - }, + /* 当前选用模型的名称 */ + activeModelName(state) { + return this.activeConfig?.modelInfo?.model; + }, + /* 当前选用模型的扣费类型 */ + activeModelKeyDeductType(state) { + return this.activeConfig?.modelInfo?.deductType; + }, - /* 当前选用模型的模型类型 */ - activeModelKeyType(state) { - return this.activeConfig?.modelInfo?.keyType - }, + /* 当前选用模型的模型类型 */ + activeModelKeyType(state) { + return this.activeConfig?.modelInfo?.keyType; + }, - /* 当前选用模型的调用价格 */ - activeModelKeyPrice(state) { - return this.activeConfig?.modelInfo?.deduct - }, + /* 当前选用模型的调用价格 */ + activeModelKeyPrice(state) { + return this.activeConfig?.modelInfo?.deduct; + }, + }, - }, + actions: { + /* 对话组过滤 */ + setGroupKeyWord(keyWord: string) { + this.groupKeyWord = keyWord; + }, - actions: { - /* 对话组过滤 */ - setGroupKeyWord(keyWord: string) { - this.groupKeyWord = keyWord - }, + /* 计算拿到当前选择的对话组信息 */ + getChatByGroupInfo() { + if (this.active) + return this.groupList.find((item) => item.uuid === this.active) || {}; + }, - /* 计算拿到当前选择的对话组信息 */ - getChatByGroupInfo() { - if (this.active) - return this.groupList.find(item => item.uuid === this.active) || {} - }, + /* */ + getConfigFromUuid(uuid: any) { + return this.groupList.find((item) => item.uuid === uuid)?.config; + }, - /* */ - getConfigFromUuid(uuid: any) { - return this.groupList.find(item => item.uuid === uuid)?.config - }, + /* 新增新的对话组 */ + async addNewChatGroup(appId = 0) { + const res: any = await fetchCreateGroupAPI({ appId }); + const { id: uuid } = res.data; + await this.setActiveGroup(uuid); + this.recordState(); + }, - /* 新增新的对话组 */ - async addNewChatGroup(appId = 0) { - const res: any = await fetchCreateGroupAPI({ appId }) - const { id: uuid } = res.data - await this.setActiveGroup(uuid) - this.recordState() - }, + /* 查询基础模型配置 兼容老的chatgroup */ + async getBaseModelConfig() { + const res = await fetchModelBaseConfigAPI(); + this.baseConfig = res?.data; + }, - /* 查询基础模型配置 兼容老的chatgroup */ - async getBaseModelConfig() { - const res = await fetchModelBaseConfigAPI() - this.baseConfig = res?.data - }, + /* 查询我的对话组 */ + async queryMyGroup() { + const res: any = await fetchQueryGroupAPI(); + this.groupList = [ + ...res.data.map((item: any) => { + const { + id: uuid, + title, + isSticky, + createdAt, + updatedAt, + appId, + config, + appLogo, + } = item; + return { + uuid, + title, + isEdit: false, + appId, + config, + isSticky, + appLogo, + createdAt, + updatedAt: new Date(updatedAt).getTime(), + }; + }), + ]; + const isHasActive = this.groupList.some( + (item) => Number(item.uuid) === Number(this.active) + ); + if (!this.active || !isHasActive) + this.groupList.length && this.setActiveGroup(this.groupList[0].uuid); + }, - /* 查询我的对话组 */ - async queryMyGroup() { - const res: any = await fetchQueryGroupAPI() - this.groupList = [...res.data.map((item: any) => { - const { id: uuid, title, isSticky, createdAt, updatedAt, appId, config, appLogo } = item - return { uuid, title, isEdit: false, appId, config, isSticky, appLogo, createdAt, updatedAt: new Date(updatedAt).getTime() } - })] - const isHasActive = this.groupList.some(item => Number(item.uuid) === Number(this.active)) - if (!this.active || !isHasActive) - this.groupList.length && this.setActiveGroup(this.groupList[0].uuid) - }, + /* 修改对话组信息 */ + async updateGroupInfo(params: { + groupId: number; + title?: string; + isSticky?: boolean; + }) { + await fetchUpdateGroupAPI(params); + }, - /* 修改对话组信息 */ - async updateGroupInfo(params: { groupId: number; title?: string; isSticky?: boolean }) { - await fetchUpdateGroupAPI(params) - }, + /* 变更对话组 */ + async setActiveGroup(uuid: number) { + this.active = uuid; + if (this.active) await this.queryActiveChatLogList(); + else this.chatList = []; - /* 变更对话组 */ - async setActiveGroup(uuid: number) { - this.active = uuid - if (this.active) - await this.queryActiveChatLogList() + this.groupList.forEach((item) => (item.isEdit = false)); + this.recordState(); + }, - else - this.chatList = [] + /* 删除对话组 */ + async deleteGroup(params: Chat.History) { + const curIndex = this.groupList.findIndex( + (item) => item.uuid === params.uuid + ); + const { uuid: groupId } = params; + await fetchDelGroupAPI({ groupId }); + await this.queryMyGroup(); + if (this.groupList.length === 0) await this.setActiveGroup(0); - this.groupList.forEach(item => (item.isEdit = false)) - this.recordState() - }, + if (curIndex > 0 && curIndex < this.groupList.length) + await this.setActiveGroup(this.groupList[curIndex].uuid); - /* 删除对话组 */ - async deleteGroup(params: Chat.History) { - const curIndex = this.groupList.findIndex(item => item.uuid === params.uuid) - const { uuid: groupId } = params - await fetchDelGroupAPI({ groupId }) - await this.queryMyGroup() - if (this.groupList.length === 0) - await this.setActiveGroup(0) + if (curIndex === 0 && this.groupList.length > 0) + await this.setActiveGroup(this.groupList[0].uuid); - if (curIndex > 0 && curIndex < this.groupList.length) - await this.setActiveGroup(this.groupList[curIndex].uuid) + if ( + curIndex > this.groupList.length || + (curIndex === 0 && this.groupList.length === 0) + ) + await this.setActiveGroup(0); - if (curIndex === 0 && this.groupList.length > 0) - await this.setActiveGroup(this.groupList[0].uuid) + if (curIndex > 0 && curIndex === this.groupList.length) + await this.setActiveGroup(this.groupList[curIndex - 1].uuid); - if (curIndex > this.groupList.length || (curIndex === 0 && this.groupList.length === 0)) - await this.setActiveGroup(0) + this.recordState(); + }, - if (curIndex > 0 && curIndex === this.groupList.length) - await this.setActiveGroup(this.groupList[curIndex - 1].uuid) + /* 删除全部非置顶对话组 */ + async delAllGroup() { + if (!this.active || !this.groupList.length) return; + await fetchDelAllGroupAPI(); + await this.queryMyGroup(); + if (this.groupList.length === 0) await this.setActiveGroup(0); + else await this.setActiveGroup(this.groupList[0].uuid); + }, - this.recordState() - }, + /* 查询当前对话组的聊天记录 */ + async queryActiveChatLogList() { + if (!this.active || Number(this.active) === 0) return; + const res: any = await fetchQueryChatLogListAPI({ groupId: this.active }); + this.chatList = res.data; + }, - /* 删除全部非置顶对话组 */ - async delAllGroup() { - if (!this.active || !this.groupList.length) - return - await fetchDelAllGroupAPI() - await this.queryMyGroup() - if (this.groupList.length === 0) - await this.setActiveGroup(0) + /* 添加一条虚拟的对话记录 */ + addGroupChat(data) { + this.chatList = [...this.chatList, data]; + }, - else - await this.setActiveGroup(this.groupList[0].uuid) - }, + /* 动态修改对话记录 */ + updateGroupChat(index: number, data: Chat.Chat) { + this.chatList[index] = { ...this.chatList[index], ...data }; + }, - /* 查询当前对话组的聊天记录 */ - async queryActiveChatLogList() { - if (!this.active || Number(this.active) === 0) - return - const res: any = await fetchQueryChatLogListAPI({ groupId: this.active }) - this.chatList = res.data - }, + /* 修改其中部分内容 */ + updateGroupChatSome(index: number, data: Partial) { + this.chatList[index] = { ...this.chatList[index], ...data }; + }, - /* 添加一条虚拟的对话记录 */ - addGroupChat(data) { - this.chatList = [...this.chatList, data] - }, + /* 删除一条对话记录 */ + async deleteChatById(chatId: number | undefined) { + console.log(chatId); + if (!chatId) return; + await fetchDelChatLogAPI({ id: chatId }); + await this.queryActiveChatLogList(); + }, - /* 动态修改对话记录 */ - updateGroupChat(index: number, data: Chat.Chat) { - this.chatList[index] = { ...this.chatList[index], ...data } - }, + /* 查询快问预设 */ + async queryChatPre() { + const res: any = await fetchGetChatPreList(); + if (!res.data) return; + this.chatPreList = formatChatPre(res.data); + }, - /* 修改其中部分内容 */ - updateGroupChatSome(index: number, data: Partial) { - this.chatList[index] = { ...this.chatList[index], ...data } - }, + /* 设置使用上下文 */ + setUsingContext(context: boolean) { + this.usingContext = context; + this.recordState(); + }, - /* 删除一条对话记录 */ - async deleteChatById(chatId: number | undefined) { - console.log(chatId) - if (!chatId) - return - await fetchDelChatLogAPI({ id: chatId }) - await this.queryActiveChatLogList() - }, + /* 设置使用联网 */ + setUsingNetwork(context: boolean) { + this.usingNetwork = context; + this.recordState(); + }, - /* 查询快问预设 */ - async queryChatPre() { - const res: any = await fetchGetChatPreList() - if (!res.data) - return - this.chatPreList = formatChatPre(res.data) - }, + /* 删除当前对话组的全部内容 */ + async clearChatByGroupId() { + if (!this.active) return; - /* 设置使用上下文 */ - setUsingContext(context: boolean) { - this.usingContext = context - this.recordState() - }, + await fetchDelChatLogByGroupIdAPI({ groupId: this.active }); + await this.queryActiveChatLogList(); + }, - /* 设置使用联网 */ - setUsingNetwork(context: boolean) { - this.usingNetwork = context - this.recordState() - }, + recordState() { + setLocalState(this.$state); + }, - /* 删除当前对话组的全部内容 */ - async clearChatByGroupId() { - if (!this.active) - return - - await fetchDelChatLogByGroupIdAPI({ groupId: this.active }) - await this.queryActiveChatLogList() - }, - - recordState() { - setLocalState(this.$state) - }, - - clearChat() { - this.chatList = [] - this.groupList = [] - this.active = 0 - this.recordState() - }, - }, -}) + clearChat() { + this.chatList = []; + this.groupList = []; + this.active = 0; + this.recordState(); + }, + }, +}); diff --git a/chat/src/views/chat/chatBase.vue b/chat/src/views/chat/chatBase.vue index 5e7d45e..bc69e67 100644 --- a/chat/src/views/chat/chatBase.vue +++ b/chat/src/views/chat/chatBase.vue @@ -12,7 +12,9 @@ import { NTooltip, useDialog, useMessage, + NAlert } from 'naive-ui' +import type { MessageRenderMessage } from 'naive-ui' import html2canvas from 'html2canvas' import { useRoute } from 'vue-router' @@ -86,7 +88,7 @@ const theme = computed(() => appStore.theme) const globaelConfig = computed(() => authStore.globalConfig) const isSetBeian = computed( - () => globaelConfig.value?.companyName && globaelConfig.value?.filingNumber, + () => globaelConfig.value?.companyName && globaelConfig.value?.filingNumber ) const { addGroupChat, updateGroupChat, updateGroupChatSome } = useChat() const tradeStatus = computed(() => route.query.trade_status as string) @@ -101,13 +103,13 @@ const dataSources = computed(() => chatStore.chatList) /* 当前所有的ai回复信息列表 方便拿到上下文 */ const conversationList = computed(() => - dataSources.value.filter(item => !item.inversion && !item.error), + dataSources.value.filter((item) => !item.inversion && !item.error) ) /* 当前上下文有id的最后一条 防止停止回答的时候 上一条的id是空 接不上上下文 */ const lastContext = computed(() => { const hasIdCoversationList = conversationList.value.filter( - item => item.conversationOptions?.parentMessageId, + (item) => item.conversationOptions?.parentMessageId ) return hasIdCoversationList[hasIdCoversationList.length - 1] ?.conversationOptions @@ -120,17 +122,22 @@ const firstScroll = ref(true) const tipsRef = ref(null) const tipText = ref('') const tipsHeight = ref(null) +const dataBase64 = ref(null) +const fileName = ref('') +const isImageFile = ref(false) +const showDeleteIcon = ref(false) + /* 当前选中的对话组 */ const activeGroupId = computed(() => chatStore.active) /* 当前对话组的详细信息 */ const activeGroupInfo = computed(() => - chatStore.groupList.find((item: any) => item.uuid === chatStore.active), + chatStore.groupList.find((item: any) => item.uuid === chatStore.active) ) /* 当前选用的模型的类型 1: openai 2: 百度 */ const activeModelKeyType = computed(() => Number(chatStore?.activeModelKeyType)) /* 当前对话组是否是应用 */ const activeAppId = computed(() => - activeGroupInfo?.value ? activeGroupInfo.value.appId : 0, + activeGroupInfo?.value ? activeGroupInfo.value.appId : 0 ) /* 粘贴板的文字 */ const clipboardText = computed(() => useGlobalStore.clipboardText) @@ -144,43 +151,37 @@ watch(clipboardText, (val) => { watch( activeAppId, (val) => { - if (val) - queryAppDetail(val) + if (val) queryAppDetail(val) else appDetail.value = null }, - { immediate: true }, + { immediate: true } ) watch( activeGroupId, (val) => { - if (val) - firstScroll.value = true - if (inputRef.value && !isMobile.value) - inputRef.value?.focus() + if (val) firstScroll.value = true + if (inputRef.value && !isMobile.value) inputRef.value?.focus() }, - { immediate: true }, + { immediate: true } ) watch( dataSources, (val) => { - if (val.length === 0) - return + if (val.length === 0) return if (firstScroll.value) { firstScroll.value = false scrollToBottom() } }, - { immediate: true }, + { immediate: true } ) const modelName = computed(() => { - if (!chatStore.activeConfig) - return + if (!chatStore.activeConfig) return const { modelTypeInfo, modelInfo } = chatStore.activeConfig - if (!modelTypeInfo || !modelInfo) - return + if (!modelTypeInfo || !modelInfo) return return `${modelInfo.modelName}` }) function handleOpenModelDialog() { @@ -202,14 +203,52 @@ let curFile: File | null async function handleFileSelect(event: any) { const file = event?.target?.files[0] - if (file.size <= 5 * 1024 * 1024) + if (!file) return + if (file.size <= 10 * 1024 * 1024) { await handleSetFile(file) - else ms.error('上传文件失败,上传大小不能超过5M') + } else { + return ms.error('上传文件失败,上传大小不能超过10M') + } + let trimmedFileName = file.name + const maxLength = 8 // 最大长度限制 + const extension = trimmedFileName.split('.').pop() // 获取文件扩展名 + + if (trimmedFileName.length > maxLength) { + // 截取文件名并添加省略号,同时保留扩展名 + trimmedFileName = + trimmedFileName.substring(0, maxLength - extension.length - 1) + + '….' + + extension + } + + fileName.value = trimmedFileName // 更新文件名 + console.log(file.type) + // 检查文件类型 + if (file.type.startsWith('image/')) { + // 处理图像文件 + isImageFile.value = true + handleSetFile(file) + } else if ( + file.type.startsWith('application/') || + file.type.startsWith('text/') + ) { + // 处理文件类型 + isImageFile.value = false + handleSetFile(file) + } else { + // 处理其他类型的文件或显示错误消息 + ms.error('上传文件失败,不支持此类型文件') + console.log('不支持的文件类型') + } } async function handleSetFile(file: File) { curFile = file - uploadFile() + const reader = new FileReader() + reader.onload = (event: any) => { + dataBase64.value = event.target?.result as string + } + reader.readAsDataURL(file) } function uploadBtn() { @@ -233,11 +272,13 @@ async function uploadFile() { } }, }) - prompt.value = `请分析一下上传的这个文件:${res?.data?.data}` - ms.success('上传成功,输入内容后发送', { duration: 5000, closable: true }) - } - catch (error) { - ms.error('网络异常,上传失败') + return res?.data?.data + } catch (error) { + ms.error('网络异常,发送失败') + return null + } finally { + dataBase64.value = null + curFile = null } } @@ -271,9 +312,9 @@ function handleScrollBtm() { /* 发送消息 */ async function handleSubmit(index?: number) { if ( - chatStore.groupList.length === 0 - || loading.value - || !typingStatusEnd.value + chatStore.groupList.length === 0 || + loading.value || + !typingStatusEnd.value ) return let message = '' @@ -287,12 +328,10 @@ async function handleSubmit(index?: number) { function parseTextToJSON(input: string) { const startIndex = input.indexOf(',"text":"') + 10 - if (startIndex === -1) - return { text: '' } + if (startIndex === -1) return { text: '' } let endIndex = input.indexOf('","delta"', startIndex) - if (endIndex === -1) - endIndex = input.length - 1 + if (endIndex === -1) endIndex = input.length - 1 else endIndex = endIndex - 10 const text = input.substring(startIndex, endIndex) @@ -301,15 +340,17 @@ function parseTextToJSON(input: string) { /* 按钮发送消息 */ async function onConversation(msg?: string) { + let imageUrl = null + if (dataBase64.value || curFile) { + imageUrl = await uploadFile() + } let message = msg || prompt.value if (tipText.value && !message.includes(tipText.value)) message = `${tipText.value}\n${message}` - if (loading.value) - return + if (loading.value) return - if (!message || message.trim() === '') - return + if (!message || message.trim() === '') return controller = new AbortController() @@ -319,6 +360,7 @@ async function onConversation(msg?: string) { text: message, inversion: true, error: false, + imageUrl, conversationOptions: null, requestOptions: { prompt: message, options: null }, }) @@ -369,12 +411,10 @@ async function onConversation(msg?: string) { if (cacheResText.length - i > 150) { currentText += cacheResText.substring(i, i + 10) i += 10 - } - else if (cacheResText.length - i > 200) { + } else if (cacheResText.length - i > 200) { currentText += cacheResText.substring(i) i += cacheResText.length - i - } - else { + } else { currentText += cacheResText[i] i++ } @@ -396,8 +436,8 @@ async function onConversation(msg?: string) { const curLen = currentText ? currentText.length : 0 const cacheResLen = cacheResText ? cacheResText.length : 0 if ( - !isStreamIn.value - && (curLen === cacheResLen || curLen > cacheResLen) + !isStreamIn.value && + (curLen === cacheResLen || curLen > cacheResLen) ) { typingStatusEnd.value = true updateGroupChatSome(dataSources.value.length - 1, { @@ -413,12 +453,12 @@ async function onConversation(msg?: string) { authStore.updateUserBanance(userBanance) if ( - dataSources.value.length === 2 - && !activeGroupInfo?.value?.appId + dataSources.value.length === 2 && + !activeGroupInfo?.value?.appId ) { const lengthStr = isMobile.value ? 10 : 20 - const title - = dataSources.value[1].text.length > lengthStr + const title = + dataSources.value[1].text.length > lengthStr ? dataSources.value[1].text.slice(0, lengthStr) : dataSources.value[1].text chatStore @@ -433,8 +473,7 @@ async function onConversation(msg?: string) { /* 有多余的再请求下一帧 */ if (cacheResText.length && cacheResText.length > currentText.length) { requestAnimationFrame(update) - } - else { + } else { setTimeout(() => { requestAnimationFrame(update) }, 1000) @@ -447,6 +486,8 @@ async function onConversation(msg?: string) { prompt: message, appId: activeGroupInfo.value ? activeGroupInfo.value.appId : 0, options, + imageUrl, + model: chatStore?.activeModelName, signal: controller.signal, onDownloadProgress: ({ event }) => { const xhr = event.target @@ -456,16 +497,14 @@ async function onConversation(msg?: string) { if ([1].includes(activeModelKeyType.value)) { const lastIndex = responseText.lastIndexOf( '\n', - responseText.length - 2, + responseText.length - 2 ) let chunk = responseText - if (lastIndex !== -1) - chunk = responseText.substring(lastIndex) + if (lastIndex !== -1) chunk = responseText.substring(lastIndex) try { data = JSON.parse(chunk) - } - catch (error) { + } catch (error) { /* 二次解析 */ // const parseData = parseTextToJSON(responseText) // TODO 如果出现类似超时错误 会连接上次的内容一起发出来导致无法解析 后端需要处理 下 @@ -489,8 +528,7 @@ async function onConversation(msg?: string) { const parseData = JSON.parse(line) cacheResult += parseData.result tem = parseData - } - catch (error) { + } catch (error) { console.log('Json parse 2 3 type error: ') } } @@ -502,8 +540,7 @@ async function onConversation(msg?: string) { /* 如果出现输出内容不一致就需要处理了 */ if (activeModelKeyType.value === 1) { cacheResText = data.text - if (data?.userBanance) - userBanance = data?.userBanance + if (data?.userBanance) userBanance = data?.userBanance } if ([2, 3].includes(activeModelKeyType.value)) { @@ -512,24 +549,21 @@ async function onConversation(msg?: string) { isStreamIn.value = !is_end data?.userBanance && (userBanance = data?.userBanance) } - } - catch (error) {} + } catch (error) {} }, }) } await fetchChatAPIOnce() - } - catch (error: any) { + } catch (error: any) { useGlobalStore.updateIsChatIn(false) clearInterval(timer) isStreamIn.value = false if ( - error.code === 402 - || error?.message.includes('余额不足') - || error?.message.includes('免费额度已经使用完毕') + error.code === 402 || + error?.message.includes('余额不足') || + error?.message.includes('免费额度已经使用完毕') ) { - if (isLogin.value) - useGlobalStore.updateGoodsDialog(true) + if (isLogin.value) useGlobalStore.updateGoodsDialog(true) else authStore.setLoginDialog(true) } @@ -568,10 +602,10 @@ async function onConversation(msg?: string) { requestOptions: { prompt: message, options: { ...options } }, }) scrollToBottomIfAtBottom() - } - finally { + } finally { loading.value = false isStreamIn.value = false + imageUrl = null } } @@ -589,16 +623,14 @@ function handleRefresh() { ms.success('感谢你的购买、祝您使用愉快~', { duration: 5000 }) authStore.getUserInfo() router.replace({ name: 'Chat', query: {} }) - } - else { + } else { ms.error('您还没有购买成功哦~') } } /* 导出 */ function handleExport() { - if (loading.value) - return + if (loading.value) return const d = dialog.warning({ title: t('chat.exportImage'), @@ -627,11 +659,9 @@ function handleExport() { d.loading = false ms.success(t('chat.exportSuccess')) Promise.resolve() - } - catch (error: any) { + } catch (error: any) { ms.error(t('chat.exportFailed')) - } - finally { + } finally { d.loading = false } }, @@ -640,8 +670,7 @@ function handleExport() { /* 删除 */ function handleDelete({ chatId }: Chat.Chat) { - if (loading.value) - return + if (loading.value) return dialog.warning({ title: t('chat.deleteMessage'), @@ -655,8 +684,7 @@ function handleDelete({ chatId }: Chat.Chat) { } function handleClear() { - if (loading.value) - return + if (loading.value) return dialog.warning({ title: t('chat.clearChat'), @@ -676,8 +704,7 @@ function handleEnter(event: KeyboardEvent) { event.preventDefault() handleSubmit() } - } - else { + } else { if (event.key === 'Enter' && event.ctrlKey) { event.preventDefault() handleSubmit() @@ -695,17 +722,16 @@ function handleStop() { } const placeholder = computed(() => { - if (isMobile.value) - return t('chat.placeholderMobile') + if (isMobile.value) return t('chat.placeholderMobile') return t('chat.placeholder') }) const buttonDisabled = computed(() => { return ( - loading.value - || !prompt.value - || prompt.value.trim() === '' - || !typingStatusEnd.value + loading.value || + !prompt.value || + prompt.value.trim() === '' || + !typingStatusEnd.value ) }) // 改动:发送后添加loading圈圈 @@ -719,8 +745,7 @@ function getTipsRefHeight() { function onInputeTip() { tipsHeight.value = 'auto' - if (!tipText.value) - tipsHeight.value = 0 + if (!tipText.value) tipsHeight.value = 0 nextTick(() => getTipsRefHeight()) } @@ -728,24 +753,20 @@ function onInputeTip() { onMounted(async () => { chatStore.queryChatPre() - if (token.value) - otherLoginByToken(token.value) + if (token.value) otherLoginByToken(token.value) - if (tradeStatus.value) - handleRefresh() + if (tradeStatus.value) handleRefresh() nextTick(async () => { await chatStore.queryActiveChatLogList() scrollToBottom() - if (inputRef.value && !isMobile.value) - inputRef.value?.focus() + if (inputRef.value && !isMobile.value) inputRef.value?.focus() }) }) const darkMode = computed(() => appStore.theme === 'dark') onUnmounted(() => { - if (loading.value) - controller.abort() + if (loading.value) controller.abort() }) @@ -793,6 +814,7 @@ onUnmounted(() => { :inversion="item.inversion" :error="item.error" :loading="item.loading" + :imageUrl="item.imageUrl" @regenerate="handleSubmit(index)" @delete="handleDelete(item)" /> @@ -825,10 +847,10 @@ onUnmounted(() => { 'text-[#3076fd]': usingContext, 'text-[#a8071a]': !usingContext, }" - > @@ -852,10 +874,11 @@ onUnmounted(() => { class="shrink0 flex h-8 w-8 items-center justify-center rounded border transition hover:bg-[#eef0f3] dark:border-neutral-700 dark:hover:bg-[#33373c]" @click="openChatPre" > - @@ -950,7 +973,7 @@ onUnmounted(() => { {{ modelName }} @@ -1007,7 +1030,10 @@ onUnmounted(() => {
{ :multiple="false" type="file" style="display: none" - accept="text/plain,image/*, application/msword, application/vnd.openxmlformats-officedocument.wordprocessingml.document, application/pdf" - @change="handleFileSelect($event)" - > - + :accept=" + chatStore.activeConfig.modelInfo.model === + 'gpt-4-vision-preview' + ? 'image/*' + : 'text/plain,image/*, application/msword, application/vnd.openxmlformats-officedocument.wordprocessingml.document, application/pdf' + " + @change="handleFileSelect($event)" /> + 上传 + +
+
+ + + +
+
- {{ usingNetwork ? '关闭' : '开启' }}联网访问 + {{ usingNetwork ? '关闭' : '开启' }}联网访问 @@ -1137,4 +1210,31 @@ onUnmounted(() => { .shrink0 { flex-shrink: 0 !important; } + +.close-icon { + position: absolute; + top: -0; + right: 0; + color: #ff6347; + font-size: 1rem; + width: 1rem; + height: 1rem; + animation: scaleAnim 2s infinite ease-in-out; + cursor: pointer; + &:hover { + font-weight: 800; + color: red; + } +} + +@keyframes scaleAnim { + 0%, + 100% { + transform: scale(1); + } + + 50% { + transform: scale(1.2); + } +} diff --git a/chat/src/views/chat/components/Message/Text.vue b/chat/src/views/chat/components/Message/Text.vue index af51a5e..dda33bf 100644 --- a/chat/src/views/chat/components/Message/Text.vue +++ b/chat/src/views/chat/components/Message/Text.vue @@ -15,6 +15,7 @@ interface Props { text?: string loading?: boolean asRawText?: boolean + imageUrl?: string } interface Emit { @@ -83,6 +84,12 @@ const text = computed(() => { if (!props.asRawText) return mdi.render(value) return value }) +const imageUrl = computed(() => props.imageUrl) + +const isImageUrl = computed(() => { + if (!imageUrl.value) return false + return /\.(jpg|jpeg|png|gif)$/i.test(imageUrl.value) +}) function highlightBlock(str: string, lang?: string) { return `
           
-
@@ -170,6 +181,28 @@ defineExpose({ textRef })