diff --git a/src/api/ai/write/index.ts b/src/api/ai/write/index.ts new file mode 100644 index 00000000..0b4b18a4 --- /dev/null +++ b/src/api/ai/write/index.ts @@ -0,0 +1,85 @@ +import { fetchEventSource } from '@microsoft/fetch-event-source' + +import { getAccessToken } from '@/utils/auth' +import { config } from '@/config/axios/config' +import { AiWriteTypeEnum } from '@/views/ai/utils/constants' +import request from '@/config/axios' + +export interface WriteVO { + type: AiWriteTypeEnum.WRITING | AiWriteTypeEnum.REPLY // 1:撰写 2:回复 + prompt: string // 写作内容提示 1。撰写 2回复 + originalContent: string // 原文 + length: number // 长度 + format: number // 格式 + tone: number // 语气 + language: number // 语言 + userId?: number // 用户编号 + platform?: string // 平台 + model?: string // 模型 + generatedContent?: string // 生成的内容 + errorMessage: string // 错误信息 + createTime?: Date // 创建时间 +} + +export interface AiWritePageReqVO extends PageParam { + userId?: number // 用户编号 + type?: AiWriteTypeEnum // 写作类型 + platform?: string // 平台 + createTime?: [string, string] // 创建时间 +} + +export interface AiWriteRespVo { + id: number + userId: number + type: number + platform: string + model: string + prompt: string + generatedContent: string + originalContent: string + length: number + format: number + tone: number + language: number + errorMessage: string + createTime: string +} + +export const WriteApi = { + writeStream: ({ + data, + onClose, + onMessage, + onError, + ctrl + }: { + data: WriteVO + onMessage?: (res: any) => void + onError?: (...args: any[]) => void + onClose?: (...args: any[]) => void + ctrl: AbortController + }) => { + const token = getAccessToken() + return fetchEventSource(`${config.base_url}/ai/write/generate-stream`, { + method: 'post', + headers: { + 'Content-Type': 'application/json', + Authorization: `Bearer ${token}` + }, + openWhenHidden: true, + body: JSON.stringify(data), + onmessage: onMessage, + onerror: onError, + onclose: onClose, + signal: ctrl.signal + }) + }, + // 获取写作列表 + getWritePage: (params: AiWritePageReqVO) => { + return request.get>({ url: `/ai/write/page`, params }) + }, + // 删除写作 + deleteWrite(id: number) { + return request.delete({ url: `/ai/write/delete`, params: { id } }) + } +} diff --git a/src/api/ai/writer/index.ts b/src/api/ai/writer/index.ts deleted file mode 100644 index 7494b259..00000000 --- a/src/api/ai/writer/index.ts +++ /dev/null @@ -1,65 +0,0 @@ -import { fetchEventSource } from '@microsoft/fetch-event-source' -import request from '@/config/axios' - -import { getAccessToken } from '@/utils/auth' -import { config } from '@/config/axios/config' -import { AiWriteTypeEnum } from '@/views/ai/utils/constants' - -export interface WriteVO { - type: AiWriteTypeEnum.WRITING | AiWriteTypeEnum.REPLY // 1:撰写 2:回复 - prompt: string // 写作内容提示 1。撰写 2回复 - originalContent: string // 原文 - length: number // 长度 - format: number // 格式 - tone: number // 语气 - language: number // 语言 - userId?: number // 用户编号 - platform?: string // 平台 - model?: string // 模型 - generatedContent?: string // 生成的内容 - errorMessage: string // 错误信息 - createTime?: Date // 创建时间 -} - -// TODO @hhero:搞成 WriteApi,类似 ConversationApi 一样。这样更有类的概念,后续引入某个 Api,然后调用它的方法就可以了。 -export const writeStream = ({ - data, - onClose, - onMessage, - onError, - ctrl -}: { - data: WriteVO - onMessage?: (res: any) => void - onError?: (...args: any[]) => void - onClose?: (...args: any[]) => void - ctrl: AbortController -}) => { - const token = getAccessToken() - return fetchEventSource(`${config.base_url}/ai/write/generate-stream`, { - method: 'post', - headers: { - 'Content-Type': 'application/json', - Authorization: `Bearer ${token}` - }, - openWhenHidden: true, - body: JSON.stringify(data), - onmessage: onMessage, - onerror: onError, - onclose: onClose, - signal: ctrl.signal - }) -} - -// AI 写作 API -export const WriteApi = { - // 查询AI 写作分页 - getWritePage: async (params: any) => { - return await request.get({ url: `/ai/write/page`, params }) - }, - - // 删除AI 写作 - deleteWrite: async (id: number) => { - return await request.delete({ url: `/ai/write/delete?id=` + id }) - } -} diff --git a/src/views/ai/image/index/components/other/index.vue b/src/views/ai/image/index/components/other/index.vue index 375c15b6..a688be18 100644 --- a/src/views/ai/image/index/components/other/index.vue +++ b/src/views/ai/image/index/components/other/index.vue @@ -36,7 +36,13 @@ 平台 - + - + @@ -77,12 +78,14 @@ diff --git a/src/views/ai/utils/constants.ts b/src/views/ai/utils/constants.ts index 0a88775b..4fee2dc6 100644 --- a/src/views/ai/utils/constants.ts +++ b/src/views/ai/utils/constants.ts @@ -20,17 +20,21 @@ export const AiPlatformEnum = { Ollama: 'Ollama', STABLE_DIFFUSION: 'StableDiffusion', // Stability AI MIDJOURNEY: 'Midjourney', // Midjourney - SUNO: 'Suno', // Suno AI + SUNO: 'Suno' // Suno AI } -export const OtherPlatformEnum:ImageModelVO [] = [ +export const OtherPlatformEnum: ImageModelVO[] = [ { key: AiPlatformEnum.TONG_YI, name: '通义万相' }, { key: AiPlatformEnum.YI_YAN, - name: '百度图片' + name: '百度千帆' + }, + { + key: AiPlatformEnum.ZHI_PU, + name: '智谱 AI' } ] @@ -60,6 +64,12 @@ export enum AiWriteTypeEnum { REPLY // 回复 } +// 表格展示对照map +export const AiWriteTypeTableRender = { + [AiWriteTypeEnum.WRITING]: '撰写', + [AiWriteTypeEnum.REPLY]: '回复', +} + // ========== 【图片 UI】相关的枚举 ========== export const ImageHotWords = [ '中国旗袍', @@ -200,54 +210,6 @@ export const StableDiffusionStylePresets: ImageModelVO[] = [ } ] -// todo @芋艿 这些是通义的风格,看要不要删除 -export const TongYiWanXiangStylePresets: ImageModelVO[] = [ - { - key: '-1', - name: '上传图像风格' - }, - { - key: '0', - name: '复古漫画' - }, - { - key: '1', - name: '3D童话' - }, - { - key: '2', - name: '二次元' - }, - { - key: '3', - name: '小清新' - }, - { - key: '4', - name: '未来科技' - }, - { - key: '5', - name: '国画古风' - }, - { - key: '6', - name: '将军百战' - }, - { - key: '7', - name: '炫彩卡通' - }, - { - key: '8', - name: '清雅国风' - }, - { - key: '9', - name: '喜迎新年' - } -] - export const TongYiWanXiangModels: ImageModelVO[] = [ { key: 'wanx-v1', @@ -259,6 +221,20 @@ export const TongYiWanXiangModels: ImageModelVO[] = [ } ] +export const QianFanModels: ImageModelVO[] = [ + { + key: 'sd_xl', + name: 'sd_xl' + } +] + +export const ChatGlmModels: ImageModelVO[] = [ + { + key: 'cogview-3', + name: 'cogview-3' + } +] + export const StableDiffusionClipGuidancePresets: ImageModelVO[] = [ { key: 'NONE', @@ -318,7 +294,7 @@ export const Dall3StyleList: ImageModelVO[] = [ export interface ImageSizeVO { key: string - name: string + name?: string style: string width: string height: string diff --git a/src/views/ai/writer/index/components/Left.vue b/src/views/ai/write/index/components/Left.vue similarity index 81% rename from src/views/ai/writer/index/components/Left.vue rename to src/views/ai/write/index/components/Left.vue index 7e7744c7..05cc04a5 100644 --- a/src/views/ai/writer/index/components/Left.vue +++ b/src/views/ai/write/index/components/Left.vue @@ -24,26 +24,28 @@ -
+
-
-
- +
+
+
+ +