From 18e87cf9678d624f6990c58cd50d97d236a459c7 Mon Sep 17 00:00:00 2001 From: hhhero Date: Sun, 7 Jul 2024 18:14:03 +0800 Subject: [PATCH 1/2] =?UTF-8?q?[=E6=96=B0=E5=A2=9E]ai=E5=86=99=E4=BD=9C?= =?UTF-8?q?=E9=A1=B5=E9=9D=A2=E5=AE=8C=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/ai/writer/index.ts | 53 +++++++ src/views/ai/writer/components/Left.vue | 175 +++++++++++++++++++++++ src/views/ai/writer/components/Right.vue | 25 ++++ src/views/ai/writer/components/Tag.vue | 32 +++++ src/views/ai/writer/index.vue | 20 +++ 5 files changed, 305 insertions(+) create mode 100644 src/api/ai/writer/index.ts create mode 100644 src/views/ai/writer/components/Left.vue create mode 100644 src/views/ai/writer/components/Right.vue create mode 100644 src/views/ai/writer/components/Tag.vue create mode 100644 src/views/ai/writer/index.vue diff --git a/src/api/ai/writer/index.ts b/src/api/ai/writer/index.ts new file mode 100644 index 00000000..4ce4e2d0 --- /dev/null +++ b/src/api/ai/writer/index.ts @@ -0,0 +1,53 @@ +import request from '@/config/axios' +import { fetchEventSource } from '@microsoft/fetch-event-source' + +import { getAccessToken } from '@/utils/auth' +import { config } from '@/config/axios/config' + +export interface WriteParams { + /** + * 1:撰写 2:回复 + */ + type: 1 | 2 + /** + * 写作内容提示 1。撰写 2回复 + */ + prompt: string + /** + * 原文 + */ + originalContent: string + /** + * 长度 + */ + length: number + /** + * 格式 + */ + format: number + /** + * 语气 + */ + tone: number + /** + * 语言 + */ + language: number +} +export const writeStream = (data: WriteParams, onMessage, onError, onClose, ctrl) => { + // return request.post({ url: '/ai/write/generate-stream', data }) + 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 + }) +} diff --git a/src/views/ai/writer/components/Left.vue b/src/views/ai/writer/components/Left.vue new file mode 100644 index 00000000..9c3031ae --- /dev/null +++ b/src/views/ai/writer/components/Left.vue @@ -0,0 +1,175 @@ + + + diff --git a/src/views/ai/writer/components/Right.vue b/src/views/ai/writer/components/Right.vue new file mode 100644 index 00000000..a11b7c24 --- /dev/null +++ b/src/views/ai/writer/components/Right.vue @@ -0,0 +1,25 @@ + + + + + diff --git a/src/views/ai/writer/components/Tag.vue b/src/views/ai/writer/components/Tag.vue new file mode 100644 index 00000000..4a32e572 --- /dev/null +++ b/src/views/ai/writer/components/Tag.vue @@ -0,0 +1,32 @@ + + + + + diff --git a/src/views/ai/writer/index.vue b/src/views/ai/writer/index.vue new file mode 100644 index 00000000..3cb4a7d7 --- /dev/null +++ b/src/views/ai/writer/index.vue @@ -0,0 +1,20 @@ + + + + + From f72e4f47f477de320dbb75fd7df2ff9ba57965da Mon Sep 17 00:00:00 2001 From: hhhero Date: Mon, 8 Jul 2024 00:41:20 +0800 Subject: [PATCH 2/2] =?UTF-8?q?[=E6=96=B0=E5=A2=9E]=E5=AE=8C=E5=96=84AI?= =?UTF-8?q?=E5=86=99=E4=BD=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/ai/writer/index.ts | 15 ++++- src/views/ai/writer/components/Left.vue | 38 ++++++++--- src/views/ai/writer/components/Right.vue | 85 ++++++++++++++++++++---- src/views/ai/writer/data.json | 11 +++ src/views/ai/writer/index.vue | 55 +++++++++++++-- 5 files changed, 174 insertions(+), 30 deletions(-) create mode 100644 src/views/ai/writer/data.json diff --git a/src/api/ai/writer/index.ts b/src/api/ai/writer/index.ts index 4ce4e2d0..01664b3d 100644 --- a/src/api/ai/writer/index.ts +++ b/src/api/ai/writer/index.ts @@ -1,4 +1,3 @@ -import request from '@/config/axios' import { fetchEventSource } from '@microsoft/fetch-event-source' import { getAccessToken } from '@/utils/auth' @@ -34,7 +33,19 @@ export interface WriteParams { */ language: number } -export const writeStream = (data: WriteParams, onMessage, onError, onClose, ctrl) => { +export const writeStream = ({ + data, + onClose, + onMessage, + onError, + ctrl +}: { + data: WriteParams + onMessage?: (res: any) => void + onError?: (...args: any[]) => void + onClose?: (...args: any[]) => void + ctrl: AbortController +}) => { // return request.post({ url: '/ai/write/generate-stream', data }) const token = getAccessToken() return fetchEventSource(`${config.base_url}/ai/write/generate-stream`, { diff --git a/src/views/ai/writer/components/Left.vue b/src/views/ai/writer/components/Left.vue index 9c3031ae..af808b15 100644 --- a/src/views/ai/writer/components/Left.vue +++ b/src/views/ai/writer/components/Left.vue @@ -13,7 +13,11 @@

{{ label }} - + {{ hint }} @@ -43,7 +47,7 @@ >