Skip to content

Commit ae632ac

Browse files
committed
【代码重构】AI:“聊天模型”重构为“模型”,支持 type 模型类型
1 parent 0f4216f commit ae632ac

File tree

13 files changed

+276
-184
lines changed

13 files changed

+276
-184
lines changed

src/api/ai/image/index.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,8 @@ export interface ImageVO {
2020
}
2121

2222
export interface ImageDrawReqVO {
23-
platform: string // 平台
2423
prompt: string // 提示词
25-
model: string // 模型
24+
modelId: number // 模型
2625
style: string // 图像生成的风格
2726
width: string // 图片宽度
2827
height: string // 图片高度
@@ -31,7 +30,7 @@ export interface ImageDrawReqVO {
3130

3231
export interface ImageMidjourneyImagineReqVO {
3332
prompt: string // 提示词
34-
model: string // 模型 mj nijj
33+
modelId: number // 模型
3534
base64Array: string[] // size不能为空
3635
width: string // 图片宽度
3736
height: string // 图片高度

src/api/ai/model/chatModel/index.ts

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

src/api/ai/model/model/index.ts

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import request from '@/config/axios'
2+
3+
// AI 聊天模型 VO
4+
export interface ModelVO {
5+
id: number // 编号
6+
keyId: number // API 秘钥编号
7+
name: string // 模型名字
8+
model: string // 模型标识
9+
platform: string // 模型平台
10+
type: number // 模型类型
11+
sort: number // 排序
12+
status: number // 状态
13+
temperature?: number // 温度参数
14+
maxTokens?: number // 单条回复的最大 Token 数量
15+
maxContexts?: number // 上下文的最大 Message 数量
16+
}
17+
18+
// AI 模型 API
19+
export const ModelApi = {
20+
// 查询模型分页
21+
getModelPage: async (params: any) => {
22+
return await request.get({ url: `/ai/model/page`, params })
23+
},
24+
25+
// 获得模型列表
26+
getModelSimpleList: async (type?: number) => {
27+
return await request.get({
28+
url: `/ai/model/simple-list`,
29+
params: {
30+
type
31+
}
32+
})
33+
},
34+
35+
// 查询模型详情
36+
getModel: async (id: number) => {
37+
return await request.get({ url: `/ai/model/get?id=` + id })
38+
},
39+
40+
// 新增模型
41+
createModel: async (data: ModelVO) => {
42+
return await request.post({ url: `/ai/model/create`, data })
43+
},
44+
45+
// 修改聊天模型
46+
updateModel: async (data: ModelVO) => {
47+
return await request.put({ url: `/ai/model/update`, data })
48+
},
49+
50+
// 删除聊天模型
51+
deleteModel: async (id: number) => {
52+
return await request.delete({ url: `/ai/model/delete?id=` + id })
53+
}
54+
}

src/utils/dict.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,7 @@ export enum DICT_TYPE {
219219

220220
// ========== AI - 人工智能模块 ==========
221221
AI_PLATFORM = 'ai_platform', // AI 平台
222+
AI_MODEL_TYPE = 'ai_model_type', // AI 模型类型
222223
AI_IMAGE_STATUS = 'ai_image_status', // AI 图片状态
223224
AI_MUSIC_STATUS = 'ai_music_status', // AI 音乐状态
224225
AI_GENERATE_MODE = 'ai_generate_mode', // AI 生成模式

src/views/ai/chat/index/components/conversation/ConversationUpdateForm.vue

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,9 @@
5858
</Dialog>
5959
</template>
6060
<script setup lang="ts">
61-
import { CommonStatusEnum } from '@/utils/constants'
62-
import { ChatModelApi, ChatModelVO } from '@/api/ai/model/chatModel'
61+
import { ModelApi, ModelVO } from '@/api/ai/model/model'
6362
import { ChatConversationApi, ChatConversationVO } from '@/api/ai/chat/conversation'
63+
import { AiModelTypeEnum } from '@/views/ai/utils/constants'
6464
6565
/** AI 聊天对话的更新表单 */
6666
defineOptions({ name: 'ChatConversationUpdateForm' })
@@ -85,7 +85,7 @@ const formRules = reactive({
8585
maxContexts: [{ required: true, message: '上下文数量不能为空', trigger: 'blur' }]
8686
})
8787
const formRef = ref() // 表单 Ref
88-
const chatModelList = ref([] as ChatModelVO[]) // 聊天模型列表
88+
const chatModelList = ref([] as ModelVO[]) // 聊天模型列表
8989
9090
/** 打开弹窗 */
9191
const open = async (id: number) => {
@@ -107,7 +107,7 @@ const open = async (id: number) => {
107107
}
108108
}
109109
// 获得下拉数据
110-
chatModelList.value = await ChatModelApi.getChatModelSimpleList(CommonStatusEnum.ENABLE)
110+
chatModelList.value = await ModelApi.getModelSimpleList(AiModelTypeEnum.CHAT)
111111
}
112112
defineExpose({ open }) // 提供 open 方法,用于打开弹窗
113113

src/views/ai/chat/index/components/role/RoleList.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@
4141
</template>
4242

4343
<script setup lang="ts">
44-
import {ChatRoleVO} from '@/api/ai/model/chatRole'
45-
import {PropType, ref} from 'vue'
46-
import {More} from '@element-plus/icons-vue'
44+
import { ChatRoleVO } from '@/api/ai/model/chatRole'
45+
import { PropType, ref } from 'vue'
46+
import { More } from '@element-plus/icons-vue'
4747
4848
const tabsRef = ref<any>() // tabs ref
4949

src/views/ai/image/index/components/other/index.vue renamed to src/views/ai/image/index/components/common/index.vue

Lines changed: 48 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
<template>
33
<div class="prompt">
44
<el-text tag="b">画面描述</el-text>
5-
<el-text tag="p">建议使用“形容词+动词+风格”的格式,使用“,”隔开</el-text>
5+
<el-text tag="p">建议使用“形容词 + 动词 + 风格”的格式,使用“,”隔开</el-text>
66
<el-input
77
v-model="prompt"
88
maxlength="1024"
9-
rows="5"
9+
:rows="5"
1010
class="w-100% mt-15px"
1111
input-style="border-radius: 7px;"
1212
placeholder="例如:童话里的小屋应该是什么样子?"
@@ -57,8 +57,13 @@
5757
<el-text tag="b">模型</el-text>
5858
</div>
5959
<el-space wrap class="group-item-body">
60-
<el-select v-model="model" placeholder="Select" size="large" class="!w-350px">
61-
<el-option v-for="item in models" :key="item.key" :label="item.name" :value="item.key" />
60+
<el-select v-model="modelId" placeholder="Select" size="large" class="!w-350px">
61+
<el-option
62+
v-for="item in platformModels"
63+
:key="item.id"
64+
:label="item.name"
65+
:value="item.id"
66+
/>
6267
</el-select>
6368
</el-space>
6469
</div>
@@ -72,25 +77,34 @@
7277
</el-space>
7378
</div>
7479
<div class="btns">
75-
<el-button type="primary" size="large" round :loading="drawIn" @click="handleGenerateImage">
80+
<el-button
81+
type="primary"
82+
size="large"
83+
round
84+
:loading="drawIn"
85+
:disabled="prompt.length === 0"
86+
@click="handleGenerateImage"
87+
>
7688
{{ drawIn ? '生成中' : '生成内容' }}
7789
</el-button>
7890
</div>
7991
</template>
8092
<script setup lang="ts">
8193
import { ImageApi, ImageDrawReqVO, ImageVO } from '@/api/ai/image'
82-
import {
83-
AiPlatformEnum,
84-
ChatGlmModels,
85-
ImageHotWords,
86-
ImageModelVO,
87-
OtherPlatformEnum,
88-
QianFanModels,
89-
TongYiWanXiangModels
90-
} from '@/views/ai/utils/constants'
94+
import { AiPlatformEnum, ImageHotWords, OtherPlatformEnum } from '@/views/ai/utils/constants'
95+
import { ModelVO } from '@/api/ai/model/model'
9196
9297
const message = useMessage() // 消息弹窗
9398
99+
// 接收父组件传入的模型列表
100+
const props = defineProps({
101+
models: {
102+
type: Array<ModelVO>,
103+
default: () => [] as ModelVO[]
104+
}
105+
})
106+
const emits = defineEmits(['onDrawStart', 'onDrawComplete']) // 定义 emits
107+
94108
// 定义属性
95109
const drawIn = ref<boolean>(false) // 生成中
96110
const selectHotWord = ref<string>('') // 选中的热词
@@ -99,10 +113,8 @@ const prompt = ref<string>('') // 提示词
99113
const width = ref<number>(512) // 图片宽度
100114
const height = ref<number>(512) // 图片高度
101115
const otherPlatform = ref<string>(AiPlatformEnum.TONG_YI) // 平台
102-
const models = ref<ImageModelVO[]>(TongYiWanXiangModels) // 模型 TongYiWanXiangModels、QianFanModels
103-
const model = ref<string>(models.value[0].key) // 模型
104-
105-
const emits = defineEmits(['onDrawStart', 'onDrawComplete']) // 定义 emits
116+
const platformModels = ref<ModelVO[]>([]) // 模型列表
117+
const modelId = ref<number>() // 选中的模型
106118
107119
/** 选择热词 */
108120
const handleHotWordClick = async (hotWord: string) => {
@@ -125,11 +137,11 @@ const handleGenerateImage = async () => {
125137
// 加载中
126138
drawIn.value = true
127139
// 回调
128-
emits('onDrawStart', AiPlatformEnum.STABLE_DIFFUSION)
140+
emits('onDrawStart', otherPlatform.value)
129141
// 发送请求
130142
const form = {
131143
platform: otherPlatform.value,
132-
model: model.value, // 模型
144+
modelId: modelId.value, // 模型
133145
prompt: prompt.value, // 提示词
134146
width: width.value, // 图片宽度
135147
height: height.value, // 图片高度
@@ -138,7 +150,7 @@ const handleGenerateImage = async () => {
138150
await ImageApi.drawImage(form)
139151
} finally {
140152
// 回调
141-
emits('onDrawComplete', AiPlatformEnum.STABLE_DIFFUSION)
153+
emits('onDrawComplete', otherPlatform.value)
142154
// 加载结束
143155
drawIn.value = false
144156
}
@@ -153,33 +165,29 @@ const settingValues = async (detail: ImageVO) => {
153165
154166
/** 平台切换 */
155167
const handlerPlatformChange = async (platform: string) => {
156-
// 切换平台,切换模型、风格
157-
if (AiPlatformEnum.TONG_YI === platform) {
158-
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
163-
} else {
164-
models.value = []
165-
}
166-
// 切换平台,默认选择一个风格
167-
if (models.value.length > 0) {
168-
model.value = models.value[0].key
168+
// 根据选择的平台筛选模型
169+
platformModels.value = props.models.filter((item: ModelVO) => item.platform === platform)
170+
171+
// 切换平台,默认选择一个模型
172+
if (platformModels.value.length > 0) {
173+
modelId.value = platformModels.value[0].id // 使用 model 属性作为值
169174
} else {
170-
model.value = ''
175+
modelId.value = undefined
171176
}
172177
}
173178
179+
/** 监听 models 变化 */
180+
watch(
181+
() => props.models,
182+
() => {
183+
handlerPlatformChange(otherPlatform.value)
184+
},
185+
{ immediate: true, deep: true }
186+
)
174187
/** 暴露组件方法 */
175188
defineExpose({ settingValues })
176189
</script>
177190
<style scoped lang="scss">
178-
// 提示词
179-
.prompt {
180-
}
181-
182-
// 热词
183191
.hot-words {
184192
display: flex;
185193
flex-direction: column;

0 commit comments

Comments
 (0)