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
051a610e
authored
May 14, 2024
by
YunaiV
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
【新增】AI:格式化 chat 对话的代码
parent
3d15eadb
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
39 additions
and
24 deletions
+39
-24
src/api/ai/chat/conversation/index.ts
+24
-10
src/api/ai/chat/message/index.ts
+15
-14
src/views/ai/chat/index.vue
+0
-0
No files found.
src/api/ai/chat/conversation/index.ts
View file @
051a610e
import
request
from
'@/config/axios'
import
request
from
'@/config/axios'
//
聊天
VO
//
AI 聊天会话
VO
export
interface
ChatConversationVO
{
export
interface
ChatConversationVO
{
id
:
string
// 会话
编号
id
:
number
// ID
编号
userId
:
string
// 用户编号
userId
:
number
// 用户编号
title
:
string
// 会话标题
title
:
string
// 会话标题
pinned
:
string
// 是否置顶
pinned
:
boolean
// 是否置顶
roleId
:
string
// 角色编号
roleId
:
number
// 角色编号
model
:
number
// 模型标志
modelId
:
number
// 模型编号
modelId
:
number
// 模型编号
temperature
:
string
// 温度参数
model
:
string
// 模型标志
maxTokens
:
string
// 单条回复的最大 Token 数量
temperature
:
number
// 温度参数
maxContexts
:
string
// 上下文的最大 Message 数量
maxTokens
:
number
// 单条回复的最大 Token 数量
maxContexts
:
number
// 上下文的最大 Message 数量
// 额外字段
roleAvatar
?:
string
// 角色头像
modelMaxTokens
?:
string
// 模型的单条回复的最大 Token 数量
modelMaxContexts
?:
string
// 模型的上下文的最大 Message 数量
}
}
export
interface
ChatConversationUpdateVO
{
export
interface
ChatConversationUpdateVO
{
...
@@ -24,7 +28,7 @@ export interface ChatConversationUpdateVO {
...
@@ -24,7 +28,7 @@ export interface ChatConversationUpdateVO {
maxContexts
:
string
// 上下文的最大 Message 数量
maxContexts
:
string
// 上下文的最大 Message 数量
}
}
// AI
chat 聊天
// AI
聊天会话 API
export
const
ChatConversationApi
=
{
export
const
ChatConversationApi
=
{
// 获取 Conversation
// 获取 Conversation
get
:
async
(
id
:
string
)
=>
{
get
:
async
(
id
:
string
)
=>
{
...
@@ -34,4 +38,14 @@ export const ChatConversationApi = {
...
@@ -34,4 +38,14 @@ export const ChatConversationApi = {
update
:
async
(
data
:
ChatConversationUpdateVO
)
=>
{
update
:
async
(
data
:
ChatConversationUpdateVO
)
=>
{
return
await
request
.
put
({
url
:
`/ai/chat/conversation/update`
,
data
})
return
await
request
.
put
({
url
:
`/ai/chat/conversation/update`
,
data
})
},
},
// 新增【我的】聊天会话
createChatConversationMy
:
async
(
data
?:
ChatConversationVO
)
=>
{
return
await
request
.
post
({
url
:
`/ai/chat/conversation/create-my`
,
data
})
},
// 获得【我的】聊天会话列表
getChatConversationMyList
:
async
()
=>
{
return
await
request
.
get
({
url
:
`/ai/chat/conversation/my-list`
})
}
}
}
src/api/ai/chat/message/index.ts
View file @
051a610e
import
request
from
'@/config/axios'
import
request
from
'@/config/axios'
import
{
fetchEventSource
}
from
'@microsoft/fetch-event-source'
;
import
{
fetchEventSource
}
from
'@microsoft/fetch-event-source'
import
{
getAccessToken
}
from
'@/utils/auth'
import
{
getAccessToken
}
from
'@/utils/auth'
import
{
config
}
from
'@/config/axios/config'
import
{
config
}
from
'@/config/axios/config'
// 聊天VO
// 聊天VO
export
interface
ChatMessageVO
{
export
interface
ChatMessageVO
{
...
@@ -24,26 +24,28 @@ export interface ChatMessageSendVO {
...
@@ -24,26 +24,28 @@ export interface ChatMessageSendVO {
// AI chat 聊天
// AI chat 聊天
export
const
ChatMessageApi
=
{
export
const
ChatMessageApi
=
{
// 消息列表
// 消息列表
messageList
:
async
(
conversationId
:
string
)
=>
{
messageList
:
async
(
conversationId
:
string
)
=>
{
return
await
request
.
get
({
url
:
`/ai/chat/message/list-by-conversation-id?conversationId=
${
conversationId
}
`
})
return
await
request
.
get
({
url
:
`/ai/chat/message/list-by-conversation-id?conversationId=
${
conversationId
}
`
})
},
},
// 发送 add 消息
// 发送 add 消息
add
:
async
(
data
:
ChatMessageSendVO
)
=>
{
add
:
async
(
data
:
ChatMessageSendVO
)
=>
{
return
await
request
.
post
({
url
:
`/ai/chat/message/add`
,
data
})
return
await
request
.
post
({
url
:
`/ai/chat/message/add`
,
data
})
},
},
// 发送 send 消息
// 发送 send 消息
send
:
async
(
data
:
ChatMessageSendVO
)
=>
{
send
:
async
(
data
:
ChatMessageSendVO
)
=>
{
return
await
request
.
post
({
url
:
`/ai/chat/message/send`
,
data
})
return
await
request
.
post
({
url
:
`/ai/chat/message/send`
,
data
})
},
},
// 发送 send stream 消息
// 发送 send stream 消息
// TODO axios 可以么? https://apifox.com/apiskills/how-to-create-axios-stream/
sendStream
:
async
(
id
:
string
,
ctrl
,
onMessage
,
onError
,
onClose
)
=>
{
sendStream
:
async
(
id
:
string
,
ctrl
,
onMessage
,
onError
,
onClose
)
=>
{
const
token
=
getAccessToken
()
const
token
=
getAccessToken
()
return
fetchEventSource
(
`
${
config
.
base_url
}
/ai/chat/message/send-stream`
,
{
return
fetchEventSource
(
`
${
config
.
base_url
}
/ai/chat/message/send-stream`
,
{
method
:
'post'
,
method
:
'post'
,
headers
:
{
headers
:
{
'Content-Type'
:
'application/json'
,
'Content-Type'
:
'application/json'
,
...
@@ -51,18 +53,17 @@ export const ChatMessageApi = {
...
@@ -51,18 +53,17 @@ export const ChatMessageApi = {
},
},
openWhenHidden
:
true
,
openWhenHidden
:
true
,
body
:
JSON
.
stringify
({
body
:
JSON
.
stringify
({
id
:
id
,
id
:
id
}),
}),
onmessage
:
onMessage
,
onmessage
:
onMessage
,
onerror
:
onError
,
onerror
:
onError
,
onclose
:
onClose
,
onclose
:
onClose
,
signal
:
ctrl
.
signal
,
signal
:
ctrl
.
signal
})
;
})
},
},
// 发送 send 消息
// 发送 send 消息
delete
:
async
(
id
:
string
)
=>
{
delete
:
async
(
id
:
string
)
=>
{
return
await
request
.
delete
({
url
:
`/ai/chat/message/delete?id=
${
id
}
`
})
return
await
request
.
delete
({
url
:
`/ai/chat/message/delete?id=
${
id
}
`
})
},
}
}
}
src/views/ai/chat/index.vue
View file @
051a610e
This diff is collapsed.
Click to expand it.
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