Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
C
CivWeb
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ReactWeb5
CivWeb
Commits
8111df5b
Commit
8111df5b
authored
1 year ago
by
xuchaozou
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: 增加结束对话
parent
9509982a
Pipeline
#86546
waiting for manual action with stages
Changes
15
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
15 changed files
with
178 additions
and
37 deletions
+178
-37
PandaUi.js
src/components/SoundAi/PandaUi.js
+1
-1
index.jsx
src/components/SoundAi/Ui/Dialog/index.jsx
+52
-5
index.jsx
src/components/SoundAi/Ui/PandaTip/index.jsx
+3
-0
config.js
src/components/SoundAi/core/config.js
+4
-0
BaseDirective.js
src/components/SoundAi/core/directive/BaseDirective.js
+5
-0
index.js
...onents/SoundAi/core/directive/CloseMenuDirective/index.js
+4
-3
CloseSessionDirective.js
...omponents/SoundAi/core/directive/CloseSessionDirective.js
+1
-1
index.js
...ponents/SoundAi/core/directive/OpenMenuDirective/index.js
+2
-1
index.js
...omponents/SoundAi/core/directive/ServerDirective/index.js
+16
-0
SparkDirective.js
src/components/SoundAi/core/directive/SparkDirective.js
+11
-1
TestDirective.js
src/components/SoundAi/core/directive/TestDirective.js
+37
-0
index.js
src/components/SoundAi/core/directive/index.js
+4
-3
index.js
src/components/SoundAi/core/index.js
+3
-1
index.js
src/components/SoundAi/index.js
+5
-12
testCommand.js
src/components/SoundAi/testCommand.js
+30
-9
No files found.
src/components/SoundAi/PandaUi.js
View file @
8111df5b
...
...
@@ -26,7 +26,7 @@ const PandaUi = props => {
return
()
=>
{
event
.
off
(
'record:changedStaus'
,
changeSwitch
);
};
},
[
changeSwitch
]);
},
[]);
const
changeSwitch
=
useCallback
(
async
({
recordData
,
e
:
checked
})
=>
{
...
...
This diff is collapsed.
Click to expand it.
src/components/SoundAi/Ui/Dialog/index.jsx
View file @
8111df5b
...
...
@@ -4,18 +4,23 @@ import { Tooltip, Typography } from 'antd'
import
{
Fragment
,
useCallback
,
useContext
,
useEffect
,
useRef
,
useState
}
from
'react'
import
{
event
}
from
'@wisdom-utils/utils'
import
moment
from
'moment'
import
{
Directive
,
AllDirectiveTypes
}
from
'../../core'
import
{
Directive
,
AllDirectiveTypes
,
CloseSessionDirective
}
from
'../../core'
import
context
from
'../../config'
import
SparkDirective
from
'../../core/directive/SparkDirective'
const
Dialog
=
props
=>
{
const
{
globalConfig
,
setGlobalConfig
}
=
useContext
(
context
)
const
{
pandaRecordWebSocketRef
,
close
}
=
props
const
ulRef
=
useRef
(
null
)
const
directiveRef
=
useRef
(
null
)
const
closeDirectiveRef
=
useRef
(
null
)
const
toolTipRef
=
useRef
(
null
)
const
timeRef
=
useRef
(
null
)
const
isDebug
=
globalConfig
.
get
(
"isDebug"
)
const
currentDirectiveRef
=
useRef
(
null
)
//是否开启系统语音
const
isOpenSystemSound
=
globalConfig
.
getIn
([
'key'
,
'isOpenSystemSound'
])
const
[
data
,
setData
]
=
useState
(()
=>
[{
role
:
"system"
,
...
...
@@ -39,8 +44,12 @@ const Dialog = props => {
sparkModelConfig
:
globalConfig
.
getIn
([
'key'
]).
shortSound
}
})
closeDirectiveRef
.
current
=
new
Directive
({
directiveTypes
:
[
CloseSessionDirective
]
})
if
(
globalConfig
.
get
(
'key'
).
isOpenSparkModel
)
{
directiveRef
.
current
.
directiveTypes
.
push
(
SparkDirective
)
directiveRef
.
current
.
_directiveTypes
.
push
(
SparkDirective
)
}
event
.
on
(
"aiSound:finish"
,
finish
)
event
.
on
(
"aiSound:frame"
,
frame
)
...
...
@@ -53,11 +62,14 @@ const Dialog = props => {
const
finish
=
useCallback
(
async
({
resultText
})
=>
{
if
(
!
resultText
)
return
!
isDebug
&&
pandaRecordWebSocketRef
.
current
.
setStatus
(
"pause"
)
if
(
isOpenSystemSound
)
{
pandaRecordWebSocketRef
.
current
&&
pandaRecordWebSocketRef
.
current
.
setStatus
(
"pause"
)
}
const
directive
=
directiveRef
.
current
.
parse
({
text
:
resultText
})
if
(
directive
)
{
currentDirectiveRef
.
current
=
directive
sendContent
({
role
:
"system"
,
content
:
"系统正在思考中,请稍后..."
...
...
@@ -71,20 +83,55 @@ const Dialog = props => {
})
}
})
!
isDebug
&&
pandaRecordWebSocketRef
.
current
.
setStatus
(
"playing"
)
if
(
isOpenSystemSound
)
{
pandaRecordWebSocketRef
.
current
&&
pandaRecordWebSocketRef
.
current
.
setStatus
(
"playing"
)
}
currentDirectiveRef
.
current
=
null
return
}
sendContent
({
role
:
"system"
,
content
:
"亲,我暂时还未理解你的意思,请换一种方式表达或者描述更加具体"
})
!
isDebug
&&
pandaRecordWebSocketRef
.
current
.
setStatus
(
"playing"
)
if
(
isOpenSystemSound
)
{
pandaRecordWebSocketRef
.
current
&&
pandaRecordWebSocketRef
.
current
.
setStatus
(
"playing"
)
}
},
[])
const
frame
=
useCallback
((
data
)
=>
{
const
{
resultText
,
resultTextTemp
}
=
data
console
.
log
(
resultTextTemp
)
if
(
!
resultTextTemp
)
return
const
hasCloseSessionDirective
=
closeDirectiveRef
.
current
.
parse
({
text
:
resultTextTemp
})
!
currentDirectiveRef
.
current
&&
updateUserData
({
resultTextTemp
})
if
(
hasCloseSessionDirective
)
{
closeSession
({
resultText
:
resultTextTemp
})
}
},
[])
const
closeSession
=
({
resultText
})
=>
{
if
(
currentDirectiveRef
.
current
)
{
currentDirectiveRef
.
current
.
closeResponse
()
pandaRecordWebSocketRef
.
current
.
wsClose
()
pandaRecordWebSocketRef
.
current
.
setStatus
(
"pause"
)
setTimeout
(()
=>
{
pandaRecordWebSocketRef
.
current
.
setStatus
(
"playing"
)
},
500
)
}
else
{
if
(
!
isDebug
)
{
pandaRecordWebSocketRef
.
current
.
wsClose
()
event
.
emit
(
"aiSound:finish"
,
{
resultText
})
}
}
}
const
updateUserData
=
({
resultTextTemp
})
=>
{
setData
(
data
=>
{
const
length
=
data
.
length
const
lastData
=
data
.
at
(
-
1
)
...
...
@@ -109,7 +156,7 @@ const Dialog = props => {
})
}
})
}
,
[])
}
const
updateLastData
=
({
content
,
...
params
})
=>
{
setData
(
data
=>
data
.
map
((
item
,
index
)
=>
{
...
...
This diff is collapsed.
Click to expand it.
src/components/SoundAi/Ui/PandaTip/index.jsx
View file @
8111df5b
...
...
@@ -17,6 +17,9 @@ const PandaTip = props => {
const
timeRef
=
useRef
(
null
)
const
frame
=
useCallback
(({
resultTextTemp
})
=>
{
if
(
status
==
"close"
)
{
console
.
log
(
resultTextTemp
)
}
if
(
isDebug
)
return
const
directive
=
directiveRef
.
current
.
parse
({
text
:
resultTextTemp
...
...
This diff is collapsed.
Click to expand it.
src/components/SoundAi/core/config.js
0 → 100644
View file @
8111df5b
export
default
{
punctuationMark
:
"。,、;:?!”“,.!:"
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
src/components/SoundAi/core/directive/BaseDirective.js
View file @
8111df5b
...
...
@@ -15,6 +15,10 @@ class BaseDirective {
})
{
}
closeResponse
()
{
}
}
export
default
BaseDirective
\ No newline at end of file
This diff is collapsed.
Click to expand it.
src/components/SoundAi/core/directive/CloseMenuDirective/index.js
View file @
8111df5b
import
{
store
,
event
}
from
'@wisdom-utils/utils'
;
import
BaseDirective
from
'../BaseDirective'
;
import
CloseSingleDirective
from
'./CloseSingleDirective'
;
import
config
from
'../../config'
;
class
CloseMenuDirective
extends
BaseDirective
{
static
name
=
'关闭菜单或者模糊匹配关闭菜单'
;
...
...
@@ -8,15 +9,15 @@ class CloseMenuDirective extends BaseDirective {
match
()
{
const
{
text
}
=
this
;
let
result
=
null
;
result
=
text
.
match
(
/关闭
(
所有
)
.*
(?=(?:
,|,|。
))
/
);
result
=
new
RegExp
(
`关闭(所有).*(?=(?:[
${
config
.
punctuationMark
}
]?))`
)
if
(
!
result
)
{
result
=
text
.
match
(
/关闭
(
当前
)
.*
(?=(?:
,|,|。
))
/
);
result
=
new
RegExp
(
`关闭(当前).*(?=(?:[
${
config
.
punctuationMark
}
]?))`
)
}
if
(
!
result
)
{
result
=
text
.
match
(
/关闭
(
.*
)(?=(?:
菜单|功能|路径
))
/
);
}
if
(
!
result
)
{
result
=
text
.
match
(
/关闭
(
.*
)(?=(?:
,|,|。
))
/
);
result
=
new
RegExp
(
`关闭(.*)(?=(?:[
${
config
.
punctuationMark
}
]?))`
)
}
if
(
result
&&
result
.
length
>=
2
&&
!
this
.
matchResult
)
{
this
.
matchResult
=
result
[
1
];
...
...
This diff is collapsed.
Click to expand it.
src/components/SoundAi/core/directive/CloseSessionDirective.js
View file @
8111df5b
...
...
@@ -3,7 +3,7 @@ import BaseDirective from './BaseDirective'
class
CloseSessionDirective
extends
BaseDirective
{
match
(){
const
{
text
}
=
this
if
(
/结束
对
话/
.
test
(
text
))
{
if
(
/结束
(
.*
)[
的对
]
话/
.
test
(
text
))
{
return
true
}
return
false
...
...
This diff is collapsed.
Click to expand it.
src/components/SoundAi/core/directive/OpenMenuDirective/index.js
View file @
8111df5b
...
...
@@ -3,6 +3,7 @@ import { cut, extract } from '@congcongcai/jieba.js'
import
Utils
from
"../../utils/Utils"
;
import
{
uniq
}
from
"lodash"
;
import
OpenSingleDirective
from
"./OpenSingleDirective"
;
import
config
from
"../../config"
;
class
OpenMenuDirective
extends
BaseDirective
{
static
name
=
"打开菜单或者模糊匹配打开菜单"
...
...
@@ -14,7 +15,7 @@ class OpenMenuDirective extends BaseDirective {
result
=
text
.
match
(
/打开
(
.*
)(?=(?:
菜单|功能|路径
))
/
)
}
if
(
!
result
)
{
result
=
text
.
match
(
/打开
(
.*
)(?=(?:
,|,|。
))
/
)
result
=
new
RegExp
(
`打开(.*)(?=(?:[
${
config
.
punctuationMark
}
]?))`
)
}
if
(
result
&&
result
.
length
>=
2
&&
!
this
.
matchResult
)
{
this
.
matchResult
=
result
[
1
]
...
...
This diff is collapsed.
Click to expand it.
src/components/SoundAi/core/directive/ServerDirective/index.js
0 → 100644
View file @
8111df5b
import
BaseDirective
from
"../BaseDirective"
;
class
ServerDirective
extends
BaseDirective
{
match
()
{
}
async
excute
({
sendMsg
=
function
()
{}
})
{
}
}
export
default
ServerDirective
\ No newline at end of file
This diff is collapsed.
Click to expand it.
src/components/SoundAi/core/directive/SparkDirective.js
View file @
8111df5b
...
...
@@ -18,17 +18,27 @@ class SparkDirective extends BaseDirective {
sendMsg
=
function
()
{}
})
{
return
new
Promise
(
async
(
resolve
,
reject
)
=>
{
this
.
resolve
=
resolve
this
.
sendMsg
=
sendMsg
const
data
=
await
this
.
pandaSparkWebSocket
.
sendMessag
({
content
:
this
.
text
,
isLinkContext
:
false
,
frame
({
resultTextTemp
,
resultText
})
{
sendMsg
(
resultTextTemp
)
sendMsg
?.
(
resultTextTemp
)
}
})
resolve
(
data
.
resultText
)
})
}
closeResponse
()
{
if
(
this
.
pandaSparkWebSocket
)
{
this
.
pandaSparkWebSocket
.
stop
()
}
this
.
resolve
(
""
)
this
.
sendMsg
=
null
}
destroy
(){
if
(
this
.
pandaSparkWebSocket
)
{
this
.
pandaSparkWebSocket
.
destroy
()
...
...
This diff is collapsed.
Click to expand it.
src/components/SoundAi/core/directive/TestDirective.js
0 → 100644
View file @
8111df5b
import
BaseDirective
from
"./BaseDirective"
;
class
TestDirective
extends
BaseDirective
{
match
()
{
const
{
text
}
=
this
if
(
/熊猫测试指令/
.
test
(
text
))
{
return
true
}
return
false
}
async
excute
({
sendMsg
=
function
()
{},
})
{
return
new
Promise
((
resolve
,
reject
)
=>
{
this
.
resolve
=
resolve
this
.
reject
=
reject
this
.
testCloseSession
({
sendMsg
})
})
}
closeResponse
()
{
if
(
this
.
timer
)
{
clearInterval
(
this
.
timer
)
this
.
timer
=
null
}
this
.
resolve
&&
this
.
resolve
()
}
testCloseSession
({
sendMsg
})
{
this
.
timer
=
setInterval
(()
=>
{
sendMsg
(
parseInt
(
Math
.
random
()
*
10
))
},
100
)
}
}
export
default
TestDirective
\ No newline at end of file
This diff is collapsed.
Click to expand it.
src/components/SoundAi/core/directive/index.js
View file @
8111df5b
...
...
@@ -3,13 +3,14 @@ import HomePageDirective from "./HomePageDirective"
import
CloseMenuDirective
from
"./CloseMenuDirective/index"
import
ByeDirective
from
"./ByeDirective"
import
OpenMenuDirective
from
"./OpenMenuDirective/index"
import
TestDirective
from
"./TestDirective"
const
DirectiveTypes
=
[
AwakenDirective
,
const
DirectiveTypes
=
(
process
.
env
.
NODE_ENV
==
"development"
?
[
TestDirective
]
:
[]).
concat
(
[
//
AwakenDirective,
HomePageDirective
,
OpenMenuDirective
,
CloseMenuDirective
]
]
)
const
AllDirectiveTypes
=
DirectiveTypes
.
concat
(
ByeDirective
)
class
Directive
{
...
...
This diff is collapsed.
Click to expand it.
src/components/SoundAi/core/index.js
View file @
8111df5b
...
...
@@ -6,6 +6,7 @@ import PandaSparkWebSocket from './core/sockets/PandaSparkWebSocket';
import
Directive
,
{
DirectiveTypes
,
AllDirectiveTypes
}
from
'./directive'
;
import
AwakenDirective
from
'./directive/AwakenDirective'
;
import
ByeDirective
from
'./directive/ByeDirective'
;
import
CloseSessionDirective
from
'./directive/CloseSessionDirective'
;
export
{
RecorderManager
,
...
...
@@ -17,5 +18,6 @@ export {
AwakenDirective
,
ByeDirective
,
DirectiveTypes
,
AllDirectiveTypes
AllDirectiveTypes
,
CloseSessionDirective
};
This diff is collapsed.
Click to expand it.
src/components/SoundAi/index.js
View file @
8111df5b
...
...
@@ -24,7 +24,7 @@ const SoundAi = props => {
request
(
"/PandaOMS/OMS/DataManger/GetDicConfigs"
,
{
params
:
{
ParentName
:
"智能语音"
,
ChilName
:
"是否开启,是否开启人机交互"
ChilName
:
"是否开启,是否开启人机交互
,是否开启系统语音
"
}
}).
then
(
res
=>
{
if
(
res
.
code
!=
0
)
{
...
...
@@ -42,17 +42,10 @@ const SoundAi = props => {
return
}
const
spark
=
data
.
find
(
item
=>
item
.
nodeName
==
"是否开启人机交互"
)
if
(
spark
&&
spark
.
nodeValue
==
"开"
)
{
setGlobalConfig
(
globalConfig
=>
globalConfig
.
set
(
"key"
,
{
...
keyRef
.
current
,
isOpenSparkModel
:
true
}))
}
else
{
setGlobalConfig
(
globalConfig
=>
globalConfig
.
set
(
"key"
,
{
...
keyRef
.
current
,
isOpenSparkModel
:
false
}))
}
keyRef
.
current
[
'isOpenSparkModel'
]
=
!!
(
spark
&&
spark
.
nodeValue
==
"开"
)
const
systemSound
=
data
.
find
(
item
=>
item
.
nodeName
==
"是否开启系统语音"
)
keyRef
.
current
[
'isOpenSystemSound'
]
=
!!
(
systemSound
&&
systemSound
.
nodeValue
==
"开"
)
setGlobalConfig
(
globalConfig
=>
globalConfig
.
set
(
"key"
,
{...
keyRef
.
current
}))
resolve
()
}).
catch
(
error
=>
{
reject
(
error
)
...
...
This diff is collapsed.
Click to expand it.
src/components/SoundAi/testCommand.js
View file @
8111df5b
import
{
event
}
from
'@wisdom-utils/utils'
import
{
Utils
}
from
'./core'
import
{
Utils
,
CloseSessionDirective
,
Directive
}
from
'./core'
const
testText
=
text
=>
new
Promise
((
resolve
,
reject
)
=>
{
...
...
@@ -20,26 +20,38 @@ const testText = text =>
const
testFrameText
=
(
text
)
=>
{
let
timer
=
null
,
_text
=
""
,
index
=
0
const
closeSessionDirective
=
new
Directive
({
directiveTypes
:
[
CloseSessionDirective
]
})
return
new
Promise
((
resolve
,
reject
)
=>
{
timer
=
setInterval
(()
=>
{
_text
+=
text
.
charAt
(
index
)
event
.
emit
(
"aiSound:frame"
,
{
resultTextTemp
:
_text
})
if
(
closeSessionDirective
.
parse
({
text
:
_text
}))
{
return
testFinishText
({
resolve
,
text
:
_text
,
timer
})
}
if
(
index
==
text
.
length
)
{
clearInterval
(
timer
)
setTimeout
(()
=>
{
event
.
emit
(
'aiSound:finish'
,
{
resultText
:
text
,
});
resolve
()
},
500
)
return
testFinishText
({
resolve
,
text
,
timer
})
}
index
++
},
100
)
})
}
const
testFinishText
=
({
resolve
,
text
,
timer
})
=>
{
clearInterval
(
timer
)
setTimeout
(()
=>
{
event
.
emit
(
'aiSound:finish'
,
{
resultText
:
text
,
});
resolve
()
},
500
)
}
const
testCommand
=
async
()
=>
{
await
Utils
.
delayTime
(
500
);
...
...
@@ -49,7 +61,15 @@ const testCommand = async () => {
// await testText("打开顺平全景图菜单。")
// await testText("关闭全景图菜单。")
// await testText("关闭第1个。");
await
testFrameText
(
"打开熊猫智慧水务实景菜单。"
)
// await testFrameText("打开铁山全景图菜单,结束对话,哈喽哈喽。")
// await testFrameText("我需要测试熊猫测试指令")
// await Utils.delayTime(5000)
// event.emit('aiSound:frame', {
// resultTextTemp: "打开铁山全景图菜单,结束对话,哈喽哈喽。",
// });
// await testFrameText("熊猫智慧水务解决方案是什么")
// await Utils.delayTime(6000)
// await testFrameText("打开场景搭建功能菜单")
}
export
default
testCommand
\ No newline at end of file
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