Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
phsl
/
admin
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
3d83f492
authored
May 15, 2024
by
YunaiV
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
【新增】AI:聊天对话的更新模型
parent
c06bc710
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
67 additions
and
66 deletions
+67
-66
src/api/ai/chat/conversation/index.ts
+1
-1
src/views/ai/chat/components/ChatConversationUpdateForm.vue
+56
-39
src/views/ai/chat/index.vue
+10
-26
No files found.
src/api/ai/chat/conversation/index.ts
View file @
3d83f492
...
@@ -21,7 +21,7 @@ export interface ChatConversationVO {
...
@@ -21,7 +21,7 @@ export interface ChatConversationVO {
// AI 聊天会话 API
// AI 聊天会话 API
export
const
ChatConversationApi
=
{
export
const
ChatConversationApi
=
{
// 获得【我的】聊天会话
// 获得【我的】聊天会话
getChatConversationMy
:
async
(
id
:
string
)
=>
{
getChatConversationMy
:
async
(
id
:
number
)
=>
{
return
await
request
.
get
({
url
:
`/ai/chat/conversation/get-my?id=
${
id
}
`
})
return
await
request
.
get
({
url
:
`/ai/chat/conversation/get-my?id=
${
id
}
`
})
},
},
// 更新【我的】聊天会话
// 更新【我的】聊天会话
...
...
src/views/ai/chat/components/ChatConversationUpdateForm.vue
View file @
3d83f492
...
@@ -4,23 +4,46 @@
...
@@ -4,23 +4,46 @@
ref=
"formRef"
ref=
"formRef"
:model=
"formData"
:model=
"formData"
:rules=
"formRules"
:rules=
"formRules"
label-width=
"1
0
0px"
label-width=
"1
3
0px"
v-loading=
"formLoading"
v-loading=
"formLoading"
>
>
<el-form-item
label=
"角色设定"
prop=
"system
Context
"
>
<el-form-item
label=
"角色设定"
prop=
"system
Message
"
>
<el-input
type=
"textarea"
v-model=
"formData.system
Context
"
placeholder=
"请输入角色设定"
/>
<el-input
type=
"textarea"
v-model=
"formData.system
Message
"
placeholder=
"请输入角色设定"
/>
</el-form-item>
</el-form-item>
<el-form-item
label=
"模型"
prop=
"modelId"
>
<el-form-item
label=
"模型"
prop=
"modelId"
>
<UploadImg
v-model=
"formData.modelId"
/>
<el-select
v-model=
"formData.modelId"
placeholder=
"请选择模型"
>
<el-option
v-for=
"chatModel in chatModelList"
:key=
"chatModel.id"
:label=
"chatModel.name"
:value=
"chatModel.id"
/>
</el-select>
</el-form-item>
</el-form-item>
<el-form-item
label=
"上下文数量"
prop=
"category"
>
<el-form-item
label=
"温度参数"
prop=
"temperature"
>
<el-input
v-model=
"formData.category"
placeholder=
"请输入角色类别"
/>
<el-input-number
v-model=
"formData.temperature"
placeholder=
"请输入温度参数"
:min=
"0"
:max=
"2"
:precision=
"2"
/>
</el-form-item>
</el-form-item>
<el-form-item
label=
"话题随机性"
prop=
"description"
>
<el-form-item
label=
"回复数 Token 数"
prop=
"maxTokens"
>
<el-input
type=
"textarea"
v-model=
"formData.description"
placeholder=
"请输入角色描述"
/>
<el-input-number
v-model=
"formData.maxTokens"
placeholder=
"请输入回复数 Token 数"
:min=
"0"
:max=
"4096"
/>
</el-form-item>
</el-form-item>
<el-form-item
label=
"回复数"
prop=
"systemMessage"
>
<el-form-item
label=
"上下文数量"
prop=
"maxContexts"
>
<el-input
type=
"textarea"
v-model=
"formData.systemMessage"
placeholder=
"请输入角色设定"
/>
<el-input-number
v-model=
"formData.maxContexts"
placeholder=
"请输入上下文数量"
:min=
"0"
:max=
"20"
/>
</el-form-item>
</el-form-item>
</el-form>
</el-form>
<template
#
footer
>
<template
#
footer
>
...
@@ -30,7 +53,6 @@
...
@@ -30,7 +53,6 @@
</Dialog>
</Dialog>
</template>
</template>
<
script
setup
lang=
"ts"
>
<
script
setup
lang=
"ts"
>
import
{
ChatRoleApi
,
ChatRoleVO
}
from
'@/api/ai/model/chatRole'
import
{
CommonStatusEnum
}
from
'@/utils/constants'
import
{
CommonStatusEnum
}
from
'@/utils/constants'
import
{
ChatModelApi
,
ChatModelVO
}
from
'@/api/ai/model/chatModel'
import
{
ChatModelApi
,
ChatModelVO
}
from
'@/api/ai/model/chatModel'
import
{
ChatConversationApi
,
ChatConversationVO
}
from
'@/api/ai/chat/conversation'
import
{
ChatConversationApi
,
ChatConversationVO
}
from
'@/api/ai/chat/conversation'
...
@@ -45,25 +67,18 @@ const dialogVisible = ref(false) // 弹窗的是否展示
...
@@ -45,25 +67,18 @@ const dialogVisible = ref(false) // 弹窗的是否展示
const
formLoading
=
ref
(
false
)
// 表单的加载中:1)修改时的数据加载;2)提交的按钮禁用
const
formLoading
=
ref
(
false
)
// 表单的加载中:1)修改时的数据加载;2)提交的按钮禁用
const
formData
=
ref
({
const
formData
=
ref
({
id
:
undefined
,
id
:
undefined
,
systemContext
:
undefined
,
modelId
:
undefined
,
name
:
undefined
,
avatar
:
undefined
,
category
:
undefined
,
sort
:
undefined
,
description
:
undefined
,
systemMessage
:
undefined
,
systemMessage
:
undefined
,
publicStatus
:
true
,
modelId
:
undefined
,
status
:
CommonStatusEnum
.
ENABLE
temperature
:
undefined
,
maxTokens
:
undefined
,
maxContexts
:
undefined
})
})
const
formRules
=
reactive
({
const
formRules
=
reactive
({
name
:
[{
required
:
true
,
message
:
'角色名称不能为空'
,
trigger
:
'blur'
}],
modelId
:
[{
required
:
true
,
message
:
'模型不能为空'
,
trigger
:
'blur'
}],
avatar
:
[{
required
:
true
,
message
:
'角色头像不能为空'
,
trigger
:
'blur'
}],
status
:
[{
required
:
true
,
message
:
'状态不能为空'
,
trigger
:
'blur'
}],
category
:
[{
required
:
true
,
message
:
'角色类别不能为空'
,
trigger
:
'blur'
}],
temperature
:
[{
required
:
true
,
message
:
'温度参数不能为空'
,
trigger
:
'blur'
}],
sort
:
[{
required
:
true
,
message
:
'角色排序不能为空'
,
trigger
:
'blur'
}],
maxTokens
:
[{
required
:
true
,
message
:
'回复数 Token 数不能为空'
,
trigger
:
'blur'
}],
description
:
[{
required
:
true
,
message
:
'角色描述不能为空'
,
trigger
:
'blur'
}],
maxContexts
:
[{
required
:
true
,
message
:
'上下文数量不能为空'
,
trigger
:
'blur'
}]
systemMessage
:
[{
required
:
true
,
message
:
'角色设定不能为空'
,
trigger
:
'blur'
}],
publicStatus
:
[{
required
:
true
,
message
:
'是否公开不能为空'
,
trigger
:
'blur'
}]
})
})
const
formRef
=
ref
()
// 表单 Ref
const
formRef
=
ref
()
// 表单 Ref
const
chatModelList
=
ref
([]
as
ChatModelVO
[])
// 聊天模型列表
const
chatModelList
=
ref
([]
as
ChatModelVO
[])
// 聊天模型列表
...
@@ -76,7 +91,13 @@ const open = async (id: number) => {
...
@@ -76,7 +91,13 @@ const open = async (id: number) => {
if
(
id
)
{
if
(
id
)
{
formLoading
.
value
=
true
formLoading
.
value
=
true
try
{
try
{
formData
.
value
=
await
ChatConversationApi
.
getChatConversationMy
(
id
)
const
data
=
await
ChatConversationApi
.
getChatConversationMy
(
id
)
formData
.
value
=
Object
.
keys
(
formData
.
value
).
reduce
((
obj
,
key
)
=>
{
if
(
data
.
hasOwnProperty
(
key
))
{
obj
[
key
]
=
data
[
key
]
}
return
obj
},
{})
}
finally
{
}
finally
{
formLoading
.
value
=
false
formLoading
.
value
=
false
}
}
...
@@ -94,9 +115,9 @@ const submitForm = async () => {
...
@@ -94,9 +115,9 @@ const submitForm = async () => {
// 提交请求
// 提交请求
formLoading
.
value
=
true
formLoading
.
value
=
true
try
{
try
{
const
data
=
formData
.
value
as
unknown
as
Chat
Role
VO
const
data
=
formData
.
value
as
unknown
as
Chat
Conversation
VO
await
Chat
RoleApi
.
updateChatRole
(
data
)
await
Chat
ConversationApi
.
updateChatConversationMy
(
data
)
message
.
success
(
t
(
'common.updateSuccess'
)
)
message
.
success
(
'对话配置已更新'
)
dialogVisible
.
value
=
false
dialogVisible
.
value
=
false
// 发送操作成功的事件
// 发送操作成功的事件
emit
(
'success'
)
emit
(
'success'
)
...
@@ -109,15 +130,11 @@ const submitForm = async () => {
...
@@ -109,15 +130,11 @@ const submitForm = async () => {
const
resetForm
=
()
=>
{
const
resetForm
=
()
=>
{
formData
.
value
=
{
formData
.
value
=
{
id
:
undefined
,
id
:
undefined
,
modelId
:
undefined
,
name
:
undefined
,
avatar
:
undefined
,
category
:
undefined
,
sort
:
undefined
,
description
:
undefined
,
systemMessage
:
undefined
,
systemMessage
:
undefined
,
publicStatus
:
true
,
modelId
:
undefined
,
status
:
CommonStatusEnum
.
ENABLE
temperature
:
undefined
,
maxTokens
:
undefined
,
maxContexts
:
undefined
}
}
formRef
.
value
?.
resetFields
()
formRef
.
value
?.
resetFields
()
}
}
...
...
src/views/ai/chat/index.vue
View file @
3d83f492
...
@@ -68,17 +68,10 @@
...
@@ -68,17 +68,10 @@
</div>
</div>
<div>
<div>
<!-- TODO @fan:样式改下;这里我已经改成点击后,弹出了 -->
<!-- TODO @fan:样式改下;这里我已经改成点击后,弹出了 -->
<el-dropdown
style=
"margin-right: 12px"
@
command=
"openChatConversationUpdateForm"
>
<el-button
type=
"primary"
@
click=
"openChatConversationUpdateForm"
>
<el-button
type=
"primary"
>
<span
v-html=
"useModal?.name"
></span>
<span
v-html=
"useModal?.name"
></span>
<Icon
icon=
"ep:setting"
style=
"margin-left: 10px"
/>
<Icon
icon=
"ep:setting"
style=
"margin-left: 10px"
/>
</el-button>
</el-button>
<
template
#
dropdown
>
<el-dropdown-menu
v-for=
"(item, index) in modalList"
:key=
"index"
>
<el-dropdown-item
:command=
"item"
>
{{
item
.
name
}}
</el-dropdown-item>
</el-dropdown-menu>
</
template
>
</el-dropdown>
<el-button>
<el-button>
<Icon
icon=
"ep:user"
/>
<Icon
icon=
"ep:user"
/>
</el-button>
</el-button>
...
@@ -187,16 +180,15 @@
...
@@ -187,16 +180,15 @@
</el-container>
</el-container>
</el-container>
</el-container>
<ChatConversationUpdateForm
ref=
"chatConversationUpdateFormRef"
/>
<ChatConversationUpdateForm
ref=
"chatConversationUpdateFormRef"
@
success=
"getChatConversationList"
/>
</template>
</template>
<
script
setup
lang=
"ts"
>
<
script
setup
lang=
"ts"
>
import
{
ChatMessageApi
,
ChatMessageSendVO
,
ChatMessageVO
}
from
'@/api/ai/chat/message'
import
{
ChatMessageApi
,
ChatMessageSendVO
,
ChatMessageVO
}
from
'@/api/ai/chat/message'
import
{
import
{
ChatConversationApi
,
ChatConversationVO
}
from
'@/api/ai/chat/conversation'
ChatConversationApi
,
ChatConversationUpdateVO
,
ChatConversationVO
}
from
'@/api/ai/chat/conversation'
import
ChatConversationUpdateForm
from
'./components/ChatConversationUpdateForm.vue'
import
ChatConversationUpdateForm
from
'./components/ChatConversationUpdateForm.vue'
import
{
ChatModelApi
,
ChatModelVO
}
from
'@/api/ai/model/chatModel'
import
{
ChatModelApi
,
ChatModelVO
}
from
'@/api/ai/model/chatModel'
import
{
formatDate
}
from
'@/utils/formatTime'
import
{
formatDate
}
from
'@/utils/formatTime'
...
@@ -460,15 +452,7 @@ const stopStream = async () => {
...
@@ -460,15 +452,7 @@ const stopStream = async () => {
/** 修改聊天会话 */
/** 修改聊天会话 */
const
chatConversationUpdateFormRef
=
ref
()
const
chatConversationUpdateFormRef
=
ref
()
const
openChatConversationUpdateForm
=
async
(
command
)
=>
{
const
openChatConversationUpdateForm
=
async
()
=>
{
// const update = {
// id: conversationId.value,
// modelId: command.id
// } as unknown as ChatConversationUpdateVO
// // 切换 modal
// useModal.value = command
// // 更新
// await ChatConversationApi.updateChatConversationMy(update)
chatConversationUpdateFormRef
.
value
.
open
(
conversationId
.
value
)
chatConversationUpdateFormRef
.
value
.
open
(
conversationId
.
value
)
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment