Skip to content

Commit 10f6a2b

Browse files
author
xiaohong
committed
2 parents 806888c + 35b2708 commit 10f6a2b

File tree

12 files changed

+227
-181
lines changed

12 files changed

+227
-181
lines changed

src/api/ai/write/index.ts

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
import { fetchEventSource } from '@microsoft/fetch-event-source'
2+
3+
import { getAccessToken } from '@/utils/auth'
4+
import { config } from '@/config/axios/config'
5+
import { AiWriteTypeEnum } from '@/views/ai/utils/constants'
6+
import request from '@/config/axios'
7+
8+
export interface WriteVO {
9+
type: AiWriteTypeEnum.WRITING | AiWriteTypeEnum.REPLY // 1:撰写 2:回复
10+
prompt: string // 写作内容提示 1。撰写 2回复
11+
originalContent: string // 原文
12+
length: number // 长度
13+
format: number // 格式
14+
tone: number // 语气
15+
language: number // 语言
16+
userId?: number // 用户编号
17+
platform?: string // 平台
18+
model?: string // 模型
19+
generatedContent?: string // 生成的内容
20+
errorMessage: string // 错误信息
21+
createTime?: Date // 创建时间
22+
}
23+
24+
export interface AiWritePageReqVO extends PageParam {
25+
userId?: number // 用户编号
26+
type?: AiWriteTypeEnum // 写作类型
27+
platform?: string // 平台
28+
createTime?: [string, string] // 创建时间
29+
}
30+
31+
export interface AiWriteRespVo {
32+
id: number
33+
userId: number
34+
type: number
35+
platform: string
36+
model: string
37+
prompt: string
38+
generatedContent: string
39+
originalContent: string
40+
length: number
41+
format: number
42+
tone: number
43+
language: number
44+
errorMessage: string
45+
createTime: string
46+
}
47+
48+
export const WriteApi = {
49+
writeStream: ({
50+
data,
51+
onClose,
52+
onMessage,
53+
onError,
54+
ctrl
55+
}: {
56+
data: WriteVO
57+
onMessage?: (res: any) => void
58+
onError?: (...args: any[]) => void
59+
onClose?: (...args: any[]) => void
60+
ctrl: AbortController
61+
}) => {
62+
const token = getAccessToken()
63+
return fetchEventSource(`${config.base_url}/ai/write/generate-stream`, {
64+
method: 'post',
65+
headers: {
66+
'Content-Type': 'application/json',
67+
Authorization: `Bearer ${token}`
68+
},
69+
openWhenHidden: true,
70+
body: JSON.stringify(data),
71+
onmessage: onMessage,
72+
onerror: onError,
73+
onclose: onClose,
74+
signal: ctrl.signal
75+
})
76+
},
77+
// 获取写作列表
78+
getWritePage: (params: AiWritePageReqVO) => {
79+
return request.get<PageResult<AiWriteRespVo[]>>({ url: `/ai/write/page`, params })
80+
},
81+
// 删除写作
82+
deleteWrite(id: number) {
83+
return request.delete({ url: `/ai/write/delete`, params: { id } })
84+
}
85+
}

src/api/ai/writer/index.ts

Lines changed: 0 additions & 65 deletions
This file was deleted.

src/views/ai/image/index/components/other/index.vue

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,13 @@
3636
<el-text tag="b">平台</el-text>
3737
</div>
3838
<el-space wrap class="group-item-body">
39-
<el-select v-model="otherPlatform" placeholder="Select" size="large" class="!w-350px" @change="handlerPlatformChange">
39+
<el-select
40+
v-model="otherPlatform"
41+
placeholder="Select"
42+
size="large"
43+
class="!w-350px"
44+
@change="handlerPlatformChange"
45+
>
4046
<el-option
4147
v-for="item in OtherPlatformEnum"
4248
:key="item.key"
@@ -52,12 +58,7 @@
5258
</div>
5359
<el-space wrap class="group-item-body">
5460
<el-select v-model="model" placeholder="Select" size="large" class="!w-350px">
55-
<el-option
56-
v-for="item in models"
57-
:key="item.key"
58-
:label="item.name"
59-
:value="item.key"
60-
/>
61+
<el-option v-for="item in models" :key="item.key" :label="item.name" :value="item.key" />
6162
</el-select>
6263
</el-space>
6364
</div>
@@ -77,12 +78,14 @@
7778
</div>
7879
</template>
7980
<script setup lang="ts">
80-
import {ImageApi, ImageDrawReqVO, ImageVO} from '@/api/ai/image'
81+
import { ImageApi, ImageDrawReqVO, ImageVO } from '@/api/ai/image'
8182
import {
8283
AiPlatformEnum,
84+
ChatGlmModels,
8385
ImageHotWords,
8486
ImageModelVO,
8587
OtherPlatformEnum,
88+
QianFanModels,
8689
TongYiWanXiangModels
8790
} from '@/views/ai/utils/constants'
8891
@@ -96,10 +99,9 @@ const prompt = ref<string>('') // 提示词
9699
const width = ref<number>(512) // 图片宽度
97100
const height = ref<number>(512) // 图片高度
98101
const otherPlatform = ref<string>(AiPlatformEnum.TONG_YI) // 平台
99-
const models = ref<ImageModelVO[]>(TongYiWanXiangModels) // 模型
102+
const models = ref<ImageModelVO[]>(TongYiWanXiangModels) // 模型 TongYiWanXiangModels、QianFanModels
100103
const model = ref<string>(models.value[0].key) // 模型
101104
102-
103105
const emits = defineEmits(['onDrawStart', 'onDrawComplete']) // 定义 emits
104106
105107
/** 选择热词 */
@@ -131,9 +133,8 @@ const handleGenerateImage = async () => {
131133
prompt: prompt.value, // 提示词
132134
width: width.value, // 图片宽度
133135
height: height.value, // 图片高度
134-
options: {
135-
}
136-
} as ImageDrawReqVO
136+
options: {}
137+
} as unknown as ImageDrawReqVO
137138
await ImageApi.drawImage(form)
138139
} finally {
139140
// 回调
@@ -148,21 +149,24 @@ const settingValues = async (detail: ImageVO) => {
148149
prompt.value = detail.prompt
149150
width.value = detail.width
150151
height.value = detail.height
151-
152152
}
153153
154154
/** 平台切换 */
155-
const handlerPlatformChange = async (platform) => {
155+
const handlerPlatformChange = async (platform: string) => {
156156
// 切换平台,切换模型、风格
157-
if (AiPlatformEnum.YI_YAN === platform) {
157+
if (AiPlatformEnum.TONG_YI === platform) {
158158
models.value = TongYiWanXiangModels
159+
} else if (AiPlatformEnum.YI_YAN === platform) {
160+
models.value = QianFanModels
161+
} else if (AiPlatformEnum.ZHI_PU === platform) {
162+
models.value = ChatGlmModels
159163
} else {
160164
models.value = []
161165
}
162166
// 切换平台,默认选择一个风格
163167
if (models.value.length > 0) {
164168
model.value = models.value[0].key
165-
} else {
169+
} else {
166170
model.value = ''
167171
}
168172
}

src/views/ai/image/index/index.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ const platformOptions = [
6262
value: AiPlatformEnum.STABLE_DIFFUSION
6363
},
6464
{
65-
label: '其他',
65+
label: '其它',
6666
value: 'other'
6767
}
6868
]
@@ -88,6 +88,7 @@ const handleRegeneration = async (image: ImageVO) => {
8888
} else if (image.platform === AiPlatformEnum.STABLE_DIFFUSION) {
8989
stableDiffusionRef.value.settingValues(image)
9090
}
91+
// TODO @fan:貌似 other 重新设置不行?
9192
}
9293
</script>
9394

src/views/ai/utils/constants.ts

Lines changed: 28 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,21 @@ export const AiPlatformEnum = {
2020
Ollama: 'Ollama',
2121
STABLE_DIFFUSION: 'StableDiffusion', // Stability AI
2222
MIDJOURNEY: 'Midjourney', // Midjourney
23-
SUNO: 'Suno', // Suno AI
23+
SUNO: 'Suno' // Suno AI
2424
}
2525

26-
export const OtherPlatformEnum:ImageModelVO [] = [
26+
export const OtherPlatformEnum: ImageModelVO[] = [
2727
{
2828
key: AiPlatformEnum.TONG_YI,
2929
name: '通义万相'
3030
},
3131
{
3232
key: AiPlatformEnum.YI_YAN,
33-
name: '百度图片'
33+
name: '百度千帆'
34+
},
35+
{
36+
key: AiPlatformEnum.ZHI_PU,
37+
name: '智谱 AI'
3438
}
3539
]
3640

@@ -60,6 +64,12 @@ export enum AiWriteTypeEnum {
6064
REPLY // 回复
6165
}
6266

67+
// 表格展示对照map
68+
export const AiWriteTypeTableRender = {
69+
[AiWriteTypeEnum.WRITING]: '撰写',
70+
[AiWriteTypeEnum.REPLY]: '回复',
71+
}
72+
6373
// ========== 【图片 UI】相关的枚举 ==========
6474
export const ImageHotWords = [
6575
'中国旗袍',
@@ -200,54 +210,6 @@ export const StableDiffusionStylePresets: ImageModelVO[] = [
200210
}
201211
]
202212

203-
// todo @芋艿 这些是通义的风格,看要不要删除
204-
export const TongYiWanXiangStylePresets: ImageModelVO[] = [
205-
{
206-
key: '-1',
207-
name: '上传图像风格'
208-
},
209-
{
210-
key: '0',
211-
name: '复古漫画'
212-
},
213-
{
214-
key: '1',
215-
name: '3D童话'
216-
},
217-
{
218-
key: '2',
219-
name: '二次元'
220-
},
221-
{
222-
key: '3',
223-
name: '小清新'
224-
},
225-
{
226-
key: '4',
227-
name: '未来科技'
228-
},
229-
{
230-
key: '5',
231-
name: '国画古风'
232-
},
233-
{
234-
key: '6',
235-
name: '将军百战'
236-
},
237-
{
238-
key: '7',
239-
name: '炫彩卡通'
240-
},
241-
{
242-
key: '8',
243-
name: '清雅国风'
244-
},
245-
{
246-
key: '9',
247-
name: '喜迎新年'
248-
}
249-
]
250-
251213
export const TongYiWanXiangModels: ImageModelVO[] = [
252214
{
253215
key: 'wanx-v1',
@@ -259,6 +221,20 @@ export const TongYiWanXiangModels: ImageModelVO[] = [
259221
}
260222
]
261223

224+
export const QianFanModels: ImageModelVO[] = [
225+
{
226+
key: 'sd_xl',
227+
name: 'sd_xl'
228+
}
229+
]
230+
231+
export const ChatGlmModels: ImageModelVO[] = [
232+
{
233+
key: 'cogview-3',
234+
name: 'cogview-3'
235+
}
236+
]
237+
262238
export const StableDiffusionClipGuidancePresets: ImageModelVO[] = [
263239
{
264240
key: 'NONE',
@@ -318,7 +294,7 @@ export const Dall3StyleList: ImageModelVO[] = [
318294

319295
export interface ImageSizeVO {
320296
key: string
321-
name: string
297+
name?: string
322298
style: string
323299
width: string
324300
height: string

0 commit comments

Comments
 (0)