Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
C
center-book
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
EzijingWeb
center-book
Commits
e8fff8e5
提交
e8fff8e5
authored
1月 17, 2025
作者:
王鹏飞
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
chore: update
上级
4ac31a11
隐藏空白字符变更
内嵌
并排
正在显示
6 个修改的文件
包含
87 行增加
和
154 行删除
+87
-154
ai.js
src/api/ai.js
+0
-16
AIChatDrawer.jsx
src/common/wangeditor-customer/menu/common/AIChatDrawer.jsx
+12
-5
component.js
src/config/component.js
+61
-63
useAI.js
src/hooks/useAI.js
+0
-58
useBaiduAI.js
src/hooks/useBaiduAI.js
+2
-2
useTiangongAI.js
src/hooks/useTiangongAI.js
+12
-10
没有找到文件。
src/api/ai.js
浏览文件 @
e8fff8e5
import
axios
from
'@/utils/axios'
import
axios
from
'@/utils/axios'
import
fetchEventSource
from
'@/utils/fetchEventSource'
// 流式编辑接口
export
function
aiEdit
(
options
)
{
return
fetchEventSource
(
'/api/ai/sky3/edit'
,
options
)
}
// 流式对话接口
export
function
aiChat
(
data
)
{
return
axios
.
post
(
'/api/ai/sky3/chat'
,
data
)
}
// 文本生成图片接口
export
function
aiGenerateImage
(
data
)
{
return
axios
.
post
(
'/api/ai/sky3/generateImage'
,
data
)
}
// 百度聊天接口
// 百度聊天接口
export
function
baiduAIChat
(
data
)
{
export
function
baiduAIChat
(
data
)
{
...
...
src/common/wangeditor-customer/menu/common/AIChatDrawer.jsx
浏览文件 @
e8fff8e5
...
@@ -2,13 +2,13 @@ import { useState, useEffect } from 'react'
...
@@ -2,13 +2,13 @@ import { useState, useEffect } from 'react'
import
{
SendOutlined
}
from
'@ant-design/icons'
import
{
SendOutlined
}
from
'@ant-design/icons'
import
{
Drawer
,
Input
,
Button
,
message
}
from
'antd'
import
{
Drawer
,
Input
,
Button
,
message
}
from
'antd'
import
dayjs
from
'dayjs'
import
dayjs
from
'dayjs'
import
{
useAIChat
}
from
'
./useAIChat
'
import
{
useAIChat
}
from
'
@/hooks/useTiangongAI
'
import
normalAvatar
from
'@/assets/images/icon-normal-avatar.png'
import
normalAvatar
from
'@/assets/images/icon-normal-avatar.png'
import
'./AIChatDrawer.less'
import
'./AIChatDrawer.less'
const
AIChatDrawer
=
props
=>
{
const
AIChatDrawer
=
(
props
)
=>
{
const
selectText
=
props
.
editor
.
getSelectionText
()
const
selectText
=
props
.
editor
.
getSelectionText
()
const
[
open
,
setOpen
]
=
useState
(
true
)
const
[
open
,
setOpen
]
=
useState
(
true
)
...
@@ -58,7 +58,9 @@ const AIChatDrawer = props => {
...
@@ -58,7 +58,9 @@ const AIChatDrawer = props => {
{
messages
.
map
((
item
,
index
)
=>
{
{
messages
.
map
((
item
,
index
)
=>
{
return
(
return
(
<
div
className=
{
`chat-content-item`
}
key=
{
index
}
>
<
div
className=
{
`chat-content-item`
}
key=
{
index
}
>
{
item
.
role_type
===
'user'
&&
<
div
className=
"time"
>
{
dayjs
(
item
.
time
).
format
(
'YYYY-MM-DD HH:mm'
)
}
</
div
>
}
{
item
.
role_type
===
'user'
&&
(
<
div
className=
"time"
>
{
dayjs
(
item
.
time
).
format
(
'YYYY-MM-DD HH:mm'
)
}
</
div
>
)
}
{
item
.
role_type
===
'ai'
&&
(
{
item
.
role_type
===
'ai'
&&
(
<
div
className=
"inside"
>
<
div
className=
"inside"
>
<
div
className=
"ai-in-content"
>
<
div
className=
"ai-in-content"
>
...
@@ -92,12 +94,17 @@ const AIChatDrawer = props => {
...
@@ -92,12 +94,17 @@ const AIChatDrawer = props => {
defaultValue=
{
value
}
defaultValue=
{
value
}
allowClear
allowClear
disabled=
{
isLoading
}
disabled=
{
isLoading
}
onChange=
{
e
=>
setValue
(
e
.
target
.
value
)
}
onChange=
{
(
e
)
=>
setValue
(
e
.
target
.
value
)
}
placeholder=
"请输入内容"
placeholder=
"请输入内容"
style=
{
{
height
:
'80px'
,
resize
:
'none'
}
}
></
Input
.
TextArea
>
style=
{
{
height
:
'80px'
,
resize
:
'none'
}
}
></
Input
.
TextArea
>
</
div
>
</
div
>
<
div
className=
"button"
>
<
div
className=
"button"
>
<
Button
type=
"primary"
icon=
{
<
SendOutlined
/>
}
loading=
{
isLoading
}
size=
"large"
onClick=
{
targetChat
}
></
Button
>
<
Button
type=
"primary"
icon=
{
<
SendOutlined
/>
}
loading=
{
isLoading
}
size=
"large"
onClick=
{
targetChat
}
></
Button
>
</
div
>
</
div
>
</
div
>
</
div
>
</
div
>
</
div
>
...
...
src/config/component.js
浏览文件 @
e8fff8e5
...
@@ -4,193 +4,193 @@ export default [
...
@@ -4,193 +4,193 @@ export default [
name
:
'books'
,
name
:
'books'
,
key
:
'/books'
,
key
:
'/books'
,
title
:
'书籍管理'
,
title
:
'书籍管理'
,
component
:
'books/index'
component
:
'books/index'
,
},
},
{
{
name
:
'books-classify'
,
name
:
'books-classify'
,
key
:
'/books/classify'
,
key
:
'/books/classify'
,
title
:
'书籍分类'
,
title
:
'书籍分类'
,
component
:
'books/classify/index'
component
:
'books/classify/index'
,
},
},
{
{
name
:
'books-audit'
,
name
:
'books-audit'
,
key
:
'/books/audit'
,
key
:
'/books/audit'
,
title
:
'书籍审核'
,
title
:
'书籍审核'
,
component
:
'books/audit/index'
,
component
:
'books/audit/index'
,
isChild
:
true
isChild
:
true
,
},
},
{
{
name
:
'books-label'
,
name
:
'books-label'
,
key
:
'/books/label'
,
key
:
'/books/label'
,
title
:
'书籍标签'
,
title
:
'书籍标签'
,
component
:
'books/label/index'
component
:
'books/label/index'
,
},
},
{
{
name
:
'books-management'
,
name
:
'books-management'
,
key
:
'/books/management'
,
key
:
'/books/management'
,
title
:
'写书管理'
,
title
:
'写书管理'
,
component
:
'books/management/index'
,
component
:
'books/management/index'
,
isChild
:
true
isChild
:
true
,
},
},
{
{
name
:
'books-sale'
,
name
:
'books-sale'
,
key
:
'/books/sale'
,
key
:
'/books/sale'
,
title
:
'在售书籍'
,
title
:
'在售书籍'
,
component
:
'books/sale/index'
,
component
:
'books/sale/index'
,
isChild
:
true
isChild
:
true
,
},
},
{
{
name
:
'books-question-bank'
,
name
:
'books-question-bank'
,
key
:
'/books/question-bank'
,
key
:
'/books/question-bank'
,
title
:
'题库管理'
,
title
:
'题库管理'
,
component
:
'books/question-bank/index'
component
:
'books/question-bank/index'
,
},
},
{
{
name
:
'books-discussion'
,
name
:
'books-discussion'
,
key
:
'/books/discussion'
,
key
:
'/books/discussion'
,
title
:
'讨论互动'
,
title
:
'讨论互动'
,
component
:
'books/discussion/index'
component
:
'books/discussion/index'
,
},
},
{
{
name
:
'order-management'
,
name
:
'order-management'
,
key
:
'/books/order-management'
,
key
:
'/books/order-management'
,
title
:
'订单管理'
,
title
:
'订单管理'
,
component
:
'books/order-management/index'
,
component
:
'books/order-management/index'
,
isChild
:
true
isChild
:
true
,
},
},
{
{
name
:
'books-design'
,
name
:
'books-design'
,
key
:
'/books/design'
,
key
:
'/books/design'
,
title
:
'在线设计'
,
title
:
'在线设计'
,
component
:
'books/design/index'
component
:
'books/design/index'
,
},
},
// 用户管理
// 用户管理
{
{
name
:
'member'
,
name
:
'member'
,
key
:
'/member'
,
key
:
'/member'
,
title
:
'用户管理'
,
title
:
'用户管理'
,
component
:
'member/index'
component
:
'member/index'
,
},
},
{
{
name
:
'memberlist'
,
name
:
'memberlist'
,
key
:
'/member/list'
,
key
:
'/member/list'
,
title
:
'用户管理'
,
title
:
'用户管理'
,
component
:
'member/list/index'
,
component
:
'member/list/index'
,
isChild
:
true
isChild
:
true
,
},
},
{
{
name
:
'userlevel'
,
name
:
'userlevel'
,
key
:
'/member/userlevel'
,
key
:
'/member/userlevel'
,
title
:
'用户等级'
,
title
:
'用户等级'
,
component
:
'member/userlevel/index'
component
:
'member/userlevel/index'
,
},
},
// 广告管理
// 广告管理
{
{
name
:
'advertisement'
,
name
:
'advertisement'
,
key
:
'/advertisement'
,
key
:
'/advertisement'
,
title
:
'广告管理'
,
title
:
'广告管理'
,
component
:
'advertisement/index'
component
:
'advertisement/index'
,
},
},
{
{
name
:
'advert'
,
name
:
'advert'
,
key
:
'/advertisement/advert'
,
key
:
'/advertisement/advert'
,
title
:
'广告管理'
,
title
:
'广告管理'
,
component
:
'advertisement/advert/index'
component
:
'advertisement/advert/index'
,
},
},
{
{
name
:
'adsense'
,
name
:
'adsense'
,
key
:
'/advertisement/adsense'
,
key
:
'/advertisement/adsense'
,
title
:
'广告位管理'
,
title
:
'广告位管理'
,
component
:
'advertisement/adsense/index'
component
:
'advertisement/adsense/index'
,
},
},
// 系统设置
// 系统设置
{
{
name
:
'setting'
,
name
:
'setting'
,
key
:
'/setting'
,
key
:
'/setting'
,
title
:
'系统设置'
,
title
:
'系统设置'
,
component
:
'setting/index'
component
:
'setting/index'
,
},
},
{
{
name
:
'settingHelp'
,
name
:
'settingHelp'
,
key
:
'/setting/help'
,
key
:
'/setting/help'
,
title
:
'帮助中心'
,
title
:
'帮助中心'
,
component
:
'setting/help/index'
,
component
:
'setting/help/index'
,
isChild
:
true
isChild
:
true
,
},
},
{
{
name
:
'applied'
,
name
:
'applied'
,
key
:
'/setting/applied'
,
key
:
'/setting/applied'
,
title
:
'应用管理'
,
title
:
'应用管理'
,
component
:
'setting/applied/index'
component
:
'setting/applied/index'
,
},
},
{
{
name
:
'personalized'
,
name
:
'personalized'
,
key
:
'/setting/personalized-setting'
,
key
:
'/setting/personalized-setting'
,
title
:
'个性化设置'
,
title
:
'个性化设置'
,
component
:
'setting/personalized-setting/index'
component
:
'setting/personalized-setting/index'
,
},
},
{
{
name
:
'point'
,
name
:
'point'
,
key
:
'/setting/point-management'
,
key
:
'/setting/point-management'
,
title
:
'积分管理'
,
title
:
'积分管理'
,
component
:
'setting/point-management/index'
component
:
'setting/point-management/index'
,
},
},
{
{
name
:
'appversion'
,
name
:
'appversion'
,
key
:
'/setting/app-version'
,
key
:
'/setting/app-version'
,
title
:
'APP版本管理'
,
title
:
'APP版本管理'
,
component
:
'setting/app-version/index'
component
:
'setting/app-version/index'
,
},
},
{
{
name
:
'coupon'
,
name
:
'coupon'
,
key
:
'/setting/coupon'
,
key
:
'/setting/coupon'
,
title
:
'优惠卷管理'
,
title
:
'优惠卷管理'
,
component
:
'setting/coupon/index'
component
:
'setting/coupon/index'
,
},
},
{
{
name
:
'sensitive'
,
name
:
'sensitive'
,
key
:
'/setting/sensitive'
,
key
:
'/setting/sensitive'
,
title
:
'敏感词搜索'
,
title
:
'敏感词搜索'
,
component
:
'setting/sensitive/index'
component
:
'setting/sensitive/index'
,
},
},
{
{
name
:
'feedback'
,
name
:
'feedback'
,
key
:
'/setting/feedback'
,
key
:
'/setting/feedback'
,
title
:
'意见反馈'
,
title
:
'意见反馈'
,
component
:
'setting/feedback/index'
component
:
'setting/feedback/index'
,
},
},
// 权限管理
// 权限管理
{
{
name
:
'jurisdiction'
,
name
:
'jurisdiction'
,
key
:
'/jurisdiction'
,
key
:
'/jurisdiction'
,
title
:
'权限管理'
,
title
:
'权限管理'
,
component
:
'jurisdiction/index'
component
:
'jurisdiction/index'
,
},
},
{
{
name
:
'jurisdictionadmin'
,
name
:
'jurisdictionadmin'
,
key
:
'/jurisdiction/admin'
,
key
:
'/jurisdiction/admin'
,
title
:
'管理员管理'
,
title
:
'管理员管理'
,
component
:
'jurisdiction/admin/index'
component
:
'jurisdiction/admin/index'
,
},
},
{
{
name
:
'jurisdictionrole'
,
name
:
'jurisdictionrole'
,
key
:
'/jurisdiction/role'
,
key
:
'/jurisdiction/role'
,
title
:
'角色管理'
,
title
:
'角色管理'
,
component
:
'jurisdiction/role/index'
component
:
'jurisdiction/role/index'
,
},
},
// 老师管理
// 老师管理
{
{
name
:
'teacher'
,
name
:
'teacher'
,
key
:
'/teacher'
,
key
:
'/teacher'
,
title
:
'老师管理'
,
title
:
'老师管理'
,
component
:
'teacher/index'
component
:
'teacher/index'
,
},
},
{
{
name
:
'teacherlist'
,
name
:
'teacherlist'
,
key
:
'/teacher/list'
,
key
:
'/teacher/list'
,
title
:
'老师管理'
,
title
:
'老师管理'
,
component
:
'teacher/query/index'
component
:
'teacher/query/index'
,
}
}
,
]
]
const
childThirdRoutes
=
{
const
childThirdRoutes
=
{
...
@@ -202,7 +202,7 @@ const childThirdRoutes = {
...
@@ -202,7 +202,7 @@ const childThirdRoutes = {
name
:
'managementlist'
,
name
:
'managementlist'
,
meta
:
{
title
:
''
},
meta
:
{
title
:
''
},
hidden
:
true
,
hidden
:
true
,
component
:
'books/management/list/index'
component
:
'books/management/list/index'
,
},
},
{
{
path
:
'/books/management/add-edit'
,
path
:
'/books/management/add-edit'
,
...
@@ -211,7 +211,7 @@ const childThirdRoutes = {
...
@@ -211,7 +211,7 @@ const childThirdRoutes = {
meta
:
{
title
:
''
},
meta
:
{
title
:
''
},
hidden
:
true
,
hidden
:
true
,
back
:
true
,
back
:
true
,
component
:
'books/management/addedit/index'
component
:
'books/management/addedit/index'
,
},
},
{
{
path
:
'/books/management/chapter'
,
path
:
'/books/management/chapter'
,
...
@@ -220,8 +220,8 @@ const childThirdRoutes = {
...
@@ -220,8 +220,8 @@ const childThirdRoutes = {
meta
:
{
title
:
''
},
meta
:
{
title
:
''
},
hidden
:
true
,
hidden
:
true
,
back
:
true
,
back
:
true
,
component
:
'books/section/index'
component
:
'books/section/index'
,
}
}
,
],
],
// 书籍基本信息
// 书籍基本信息
'/books/audit'
:
[
'/books/audit'
:
[
...
@@ -230,22 +230,21 @@ const childThirdRoutes = {
...
@@ -230,22 +230,21 @@ const childThirdRoutes = {
key
:
'/books/audit/dataset'
,
key
:
'/books/audit/dataset'
,
name
:
'dataset'
,
name
:
'dataset'
,
meta
:
{
meta
:
{
title
:
''
title
:
''
,
},
},
hidden
:
true
,
hidden
:
true
,
component
:
'books/audit/table'
component
:
'books/audit/table'
,
},
},
{
{
path
:
'/books/audit/detail'
,
path
:
'/books/audit/detail'
,
path
:
'/books/audit/detail'
,
key
:
'dataset'
,
key
:
'dataset'
,
meta
:
{
meta
:
{
title
:
''
title
:
''
,
},
},
hidden
:
true
,
hidden
:
true
,
back
:
true
,
back
:
true
,
component
:
'books/audit/detail'
component
:
'books/audit/detail'
,
}
}
,
],
],
// 书籍审核
// 书籍审核
'/books/sale'
:
[
'/books/sale'
:
[
...
@@ -254,44 +253,43 @@ const childThirdRoutes = {
...
@@ -254,44 +253,43 @@ const childThirdRoutes = {
key
:
'/books/sale/dataset'
,
key
:
'/books/sale/dataset'
,
name
:
'dataset'
,
name
:
'dataset'
,
meta
:
{
meta
:
{
title
:
''
title
:
''
,
},
},
hidden
:
true
,
hidden
:
true
,
component
:
'books/sale/table'
component
:
'books/sale/table'
,
},
},
{
{
path
:
'/books/sale/detail'
,
path
:
'/books/sale/detail'
,
key
:
'/books/sale/detail'
,
key
:
'/books/sale/detail'
,
name
:
'detail'
,
name
:
'detail'
,
meta
:
{
meta
:
{
title
:
''
title
:
''
,
},
},
hidden
:
true
,
hidden
:
true
,
back
:
true
,
back
:
true
,
component
:
'books/sale/edit'
component
:
'books/sale/edit'
,
},
},
{
{
path
:
'/books/sale/discussP'
,
path
:
'/books/sale/discussP'
,
key
:
'/books/sale/discussP'
,
key
:
'/books/sale/discussP'
,
name
:
'discussP'
,
name
:
'discussP'
,
meta
:
{
meta
:
{
title
:
''
title
:
''
,
},
},
hidden
:
true
,
hidden
:
true
,
back
:
true
,
back
:
true
,
component
:
'books/sale/discussList/index'
component
:
'books/sale/discussList/index'
,
},
},
{
{
path
:
'/books/sale/discuss-detail'
,
path
:
'/books/sale/discuss-detail'
,
key
:
'/books/sale/discuss-detail'
,
key
:
'/books/sale/discuss-detail'
,
key
:
'discuss-detail'
,
meta
:
{
meta
:
{
title
:
''
title
:
''
,
},
},
hidden
:
true
,
hidden
:
true
,
back
:
true
,
back
:
true
,
component
:
'books/sale/discussDetail/index'
component
:
'books/sale/discussDetail/index'
,
}
}
,
],
],
// 订单管理
// 订单管理
'/books/order-management'
:
[
'/books/order-management'
:
[
...
@@ -300,21 +298,21 @@ const childThirdRoutes = {
...
@@ -300,21 +298,21 @@ const childThirdRoutes = {
key
:
'/books/order-management/dataset'
,
key
:
'/books/order-management/dataset'
,
name
:
'dataset'
,
name
:
'dataset'
,
meta
:
{
meta
:
{
title
:
''
title
:
''
,
},
},
hidden
:
true
,
hidden
:
true
,
component
:
'books/order-management/tab/table'
component
:
'books/order-management/tab/table'
,
},
},
{
{
path
:
'/books/order-management/sale-statistics'
,
path
:
'/books/order-management/sale-statistics'
,
key
:
'/books/order-management/sale-statistics'
,
key
:
'/books/order-management/sale-statistics'
,
name
:
'sale-statistics'
,
name
:
'sale-statistics'
,
meta
:
{
meta
:
{
title
:
''
title
:
''
,
},
},
hidden
:
true
,
hidden
:
true
,
component
:
'books/order-management/tab/salesStatistics'
component
:
'books/order-management/tab/salesStatistics'
,
}
}
,
],
],
// 用户管理
// 用户管理
'/member/list'
:
[
'/member/list'
:
[
...
@@ -324,7 +322,7 @@ const childThirdRoutes = {
...
@@ -324,7 +322,7 @@ const childThirdRoutes = {
name
:
'member-query'
,
name
:
'member-query'
,
hidden
:
true
,
hidden
:
true
,
meta
:
{},
meta
:
{},
component
:
'member/list/list'
component
:
'member/list/list'
,
},
},
{
{
path
:
'/member/list/detail'
,
path
:
'/member/list/detail'
,
...
@@ -332,8 +330,8 @@ const childThirdRoutes = {
...
@@ -332,8 +330,8 @@ const childThirdRoutes = {
name
:
'member-detail'
,
name
:
'member-detail'
,
hidden
:
true
,
hidden
:
true
,
meta
:
{},
meta
:
{},
component
:
'member/detail/index'
component
:
'member/detail/index'
,
}
}
,
],
],
// 帮助中心
// 帮助中心
'/setting/help'
:
[
'/setting/help'
:
[
...
@@ -343,7 +341,7 @@ const childThirdRoutes = {
...
@@ -343,7 +341,7 @@ const childThirdRoutes = {
anme
:
'help-list'
,
anme
:
'help-list'
,
meta
:
{},
meta
:
{},
hidden
:
true
,
hidden
:
true
,
component
:
'setting/help/table'
component
:
'setting/help/table'
,
},
},
{
{
path
:
'/setting/help/addedit'
,
path
:
'/setting/help/addedit'
,
...
@@ -352,9 +350,9 @@ const childThirdRoutes = {
...
@@ -352,9 +350,9 @@ const childThirdRoutes = {
meta
:
{},
meta
:
{},
hidden
:
true
,
hidden
:
true
,
back
:
true
,
back
:
true
,
component
:
'setting/help/addedit/index'
component
:
'setting/help/addedit/index'
,
}
}
,
]
]
,
}
}
export
{
childThirdRoutes
}
export
{
childThirdRoutes
}
src/hooks/useAI.js
deleted
100644 → 0
浏览文件 @
4ac31a11
import
{
useState
}
from
'react'
import
{
aiEdit
,
aiChat
,
aiGenerateImage
}
from
'@/api/ai'
export
function
useAIEdit
()
{
const
[
messages
,
setMessages
]
=
useState
([])
const
[
isLoading
,
setIsLoading
]
=
useState
(
false
)
const
latestMessage
=
messages
[
messages
.
length
-
1
]
||
{}
const
{
text
=
''
}
=
latestMessage
const
fetch
=
async
params
=>
{
setIsLoading
(
true
)
try
{
const
res
=
await
aiEdit
({
body
:
JSON
.
stringify
({
params
}),
onmessage
:
res
=>
{
let
message
=
JSON
.
parse
(
res
.
data
)
message
=
{
...
message
.
data
,
request_id
:
message
.
request_id
}
setMessages
(
prevMessages
=>
{
const
messageIndex
=
prevMessages
.
findIndex
(
m
=>
m
.
request_id
===
message
.
request_id
)
if
(
messageIndex
===
-
1
)
{
return
[...
prevMessages
,
message
]
}
else
{
return
prevMessages
.
map
(
m
=>
(
m
.
request_id
===
message
.
request_id
?
message
:
m
))
}
})
}
})
}
catch
(
error
)
{
console
.
error
(
'Error fetching AI edit:'
,
error
)
}
finally
{
setIsLoading
(
false
)
}
}
return
{
messages
,
text
,
setMessages
,
fetch
,
isLoading
}
}
export
function
useAIChat
()
{
const
[
messages
,
setMessages
]
=
useState
([])
const
fetch
=
async
params
=>
{
const
res
=
await
aiChat
({
body
:
JSON
.
stringify
({
params
}),
onmessage
:
res
=>
{
const
message
=
JSON
.
parse
(
res
.
data
)
console
.
log
(
message
)
setMessages
(
messages
=>
[...
messages
,
message
])
}
})
}
}
export
function
useAIGenerateImage
()
{
const
[
messages
,
setMessages
]
=
useState
([])
const
fetch
=
async
params
=>
{
const
res
=
await
aiGenerateImage
(
params
)
setMessages
(
res
)
}
}
src/hooks/useBaiduAI.js
浏览文件 @
e8fff8e5
...
@@ -7,13 +7,13 @@ export function useAIEdit() {
...
@@ -7,13 +7,13 @@ export function useAIEdit() {
const
latestMessage
=
messages
[
messages
.
length
-
1
]
||
{}
const
latestMessage
=
messages
[
messages
.
length
-
1
]
||
{}
const
text
=
latestMessage
?.
content
||
''
const
text
=
latestMessage
?.
content
||
''
const
fetch
=
useCallback
(
async
params
=>
{
const
fetch
=
useCallback
(
async
(
params
)
=>
{
setIsLoading
(
true
)
setIsLoading
(
true
)
try
{
try
{
const
defaultParams
=
{
ernie_name
:
'ERNIE-4.0-8K-Preview'
,
stream
:
false
}
const
defaultParams
=
{
ernie_name
:
'ERNIE-4.0-8K-Preview'
,
stream
:
false
}
const
res
=
await
baiduAIChat
({
...
defaultParams
,
params
})
const
res
=
await
baiduAIChat
({
...
defaultParams
,
params
})
const
message
=
{
role
:
'assistant'
,
content
:
res
.
data
.
result
}
const
message
=
{
role
:
'assistant'
,
content
:
res
.
data
.
result
}
setMessages
(
prevMessages
=>
[...
prevMessages
,
message
])
setMessages
(
(
prevMessages
)
=>
[...
prevMessages
,
message
])
}
catch
(
error
)
{
}
catch
(
error
)
{
console
.
error
(
'Error fetching data:'
,
error
)
console
.
error
(
'Error fetching data:'
,
error
)
}
finally
{
}
finally
{
...
...
src/
common/wangeditor-customer/menu/common/useAIChat
.js
→
src/
hooks/useTiangongAI
.js
浏览文件 @
e8fff8e5
...
@@ -10,19 +10,21 @@ export function useAIChat() {
...
@@ -10,19 +10,21 @@ export function useAIChat() {
const
[
chatId
,
setChatId
]
=
useState
(
null
)
const
[
chatId
,
setChatId
]
=
useState
(
null
)
const
[
isLoading
,
setIsLoading
]
=
useState
(
false
)
const
[
isLoading
,
setIsLoading
]
=
useState
(
false
)
const
addMessage
=
useCallback
(
message
=>
{
const
addMessage
=
useCallback
(
(
message
)
=>
{
setMessages
(
prevMessages
=>
[...
prevMessages
,
message
])
setMessages
(
(
prevMessages
)
=>
[...
prevMessages
,
message
])
},
[])
},
[])
const
updateMessages
=
useCallback
(
newMessage
=>
{
const
updateMessages
=
useCallback
(
(
newMessage
)
=>
{
setMessages
(
prevMessages
=>
{
setMessages
(
(
prevMessages
)
=>
{
const
existingMessage
=
prevMessages
.
find
(
msg
=>
msg
.
conversationId
===
newMessage
.
conversationId
)
const
existingMessage
=
prevMessages
.
find
(
(
msg
)
=>
msg
.
conversationId
===
newMessage
.
conversationId
)
const
content
=
newMessage
.
content
===
'
\
n'
?
'<br/>'
:
newMessage
.
content
||
''
const
content
=
newMessage
.
content
===
'
\
n'
?
'<br/>'
:
newMessage
.
content
||
''
if
(
existingMessage
)
{
if
(
existingMessage
)
{
// 更新现有消息
// 更新现有消息
return
prevMessages
.
map
(
msg
=>
(
msg
.
conversationId
===
newMessage
.
conversationId
?
{
...
msg
,
content
:
msg
.
content
+
content
}
:
msg
))
return
prevMessages
.
map
((
msg
)
=>
msg
.
conversationId
===
newMessage
.
conversationId
?
{
...
msg
,
content
:
msg
.
content
+
content
}
:
msg
)
}
else
{
}
else
{
// 新增消息
// 新增消息
return
[...
prevMessages
,
{
...
newMessage
,
content
,
role_type
:
'ai'
,
time
:
Date
.
now
()
}]
return
[...
prevMessages
,
{
...
newMessage
,
content
,
role_type
:
'ai'
,
time
:
Date
.
now
()
}]
...
@@ -31,7 +33,7 @@ export function useAIChat() {
...
@@ -31,7 +33,7 @@ export function useAIChat() {
},
[])
},
[])
const
post
=
useCallback
(
const
post
=
useCallback
(
async
data
=>
{
async
(
data
)
=>
{
const
timestamp
=
Date
.
now
()
const
timestamp
=
Date
.
now
()
const
sign
=
md5
(
`
${
authKey
}${
authSecret
}${
timestamp
}
`
)
const
sign
=
md5
(
`
${
authKey
}${
authSecret
}${
timestamp
}
`
)
...
@@ -40,7 +42,7 @@ export function useAIChat() {
...
@@ -40,7 +42,7 @@ export function useAIChat() {
role_type
:
'user'
,
role_type
:
'user'
,
content
:
data
.
userChatInput
,
content
:
data
.
userChatInput
,
conversationId
:
`user-
${
timestamp
}
`
,
// 生成一个唯一的 conversationId
conversationId
:
`user-
${
timestamp
}
`
,
// 生成一个唯一的 conversationId
time
:
Date
.
now
()
time
:
Date
.
now
()
,
})
})
setIsLoading
(
true
)
setIsLoading
(
true
)
...
@@ -52,7 +54,7 @@ export function useAIChat() {
...
@@ -52,7 +54,7 @@ export function useAIChat() {
authKey
,
authKey
,
timestamp
,
timestamp
,
sign
,
sign
,
'Content-Type'
:
'application/json'
'Content-Type'
:
'application/json'
,
},
},
body
:
JSON
.
stringify
({
...
data
,
chatId
,
agentId
:
authKey
}),
body
:
JSON
.
stringify
({
...
data
,
chatId
,
agentId
:
authKey
}),
onopen
(
response
)
{
onopen
(
response
)
{
...
@@ -70,7 +72,7 @@ export function useAIChat() {
...
@@ -70,7 +72,7 @@ export function useAIChat() {
},
},
onclose
()
{
onclose
()
{
setIsLoading
(
false
)
setIsLoading
(
false
)
}
}
,
})
})
}
catch
(
error
)
{
}
catch
(
error
)
{
console
.
error
(
'Post error:'
,
error
)
console
.
error
(
'Post error:'
,
error
)
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论