Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
D
dify
Project
Project
Details
Activity
Releases
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
ai-tech
dify
Commits
ba9e2ea9
Commit
ba9e2ea9
authored
Jul 19, 2023
by
Joel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: can get agent thought
parent
2374af61
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
26 additions
and
13 deletions
+26
-13
index.tsx
web/app/components/explore/universal-chat/index.tsx
+9
-4
base.ts
web/service/base.ts
+16
-8
universal-chat.ts
web/service/universal-chat.ts
+1
-1
No files found.
web/app/components/explore/universal-chat/index.tsx
View file @
ba9e2ea9
...
...
@@ -35,7 +35,6 @@ import { replaceStringWithValues } from '@/app/components/app/configuration/prom
import
{
userInputsFormToPromptVariables
}
from
'@/utils/model-config'
import
Confirm
from
'@/app/components/base/confirm'
import
type
{
DataSet
}
from
'@/models/datasets'
import
{
UNIVERSAL_CHAT_MODEL_LIST
as
MODEL_LIST
}
from
'@/config'
const
APP_ID
=
'universal-chat'
const
isUniversalChat
=
true
...
...
@@ -384,9 +383,14 @@ const Main: FC<IMainProps> = () => {
return
}
const
data
=
{
inputs
:
currInputs
,
query
:
message
,
conversation_id
:
isNewConversation
?
null
:
currConversationId
,
model
:
modelId
,
tools
:
Object
.
keys
(
plugins
).
map
(
key
=>
({
[
key
]:
{
enabled
:
plugins
[
key
],
},
})),
}
// qustion
...
...
@@ -419,6 +423,7 @@ const Main: FC<IMainProps> = () => {
setHasStopResponded
(
false
)
setResponsingTrue
()
setIsShowSuggestion
(
false
)
sendChatMessage
(
data
,
{
getAbortController
:
(
abortController
)
=>
{
setAbortController
(
abortController
)
...
...
@@ -514,8 +519,8 @@ const Main: FC<IMainProps> = () => {
)
}
const
[
modelId
,
setModeId
]
=
useState
(
'
gpt-3.5-turbo'
)
const
currModel
=
MODEL_LIST
.
find
(
item
=>
item
.
id
===
modelId
)
const
[
modelId
,
setModeId
]
=
useState
(
'
claude-2'
)
// gpt-4, claude-2
//
const currModel = MODEL_LIST.find(item => item.id === modelId)
const
[
plugins
,
setPlugins
]
=
useState
<
Record
<
string
,
boolean
>>
({
google_search
:
false
,
...
...
web/service/base.ts
View file @
ba9e2ea9
...
...
@@ -45,6 +45,9 @@ type IOtherOptions = {
}
function
unicodeToChar
(
text
:
string
)
{
if
(
!
text
)
return
''
return
text
.
replace
(
/
\\
u
[
0-9a-f
]{4}
/g
,
(
_match
,
p1
)
=>
{
return
String
.
fromCharCode
(
parseInt
(
p1
,
16
))
})
...
...
@@ -101,13 +104,18 @@ const handleStream = (response: any, onData: IOnData, onCompleted?: IOnCompleted
onCompleted
&&
onCompleted
(
true
)
return
}
// can not use format here. Because message is splited.
onData
(
unicodeToChar
(
bufferObj
.
answer
),
isFirstMessage
,
{
conversationId
:
bufferObj
.
conversation_id
,
taskId
:
bufferObj
.
task_id
,
messageId
:
bufferObj
.
id
,
})
isFirstMessage
=
false
if
(
bufferObj
.
event
===
'message'
)
{
// can not use format here. Because message is splited.
onData
(
unicodeToChar
(
bufferObj
.
answer
),
isFirstMessage
,
{
conversationId
:
bufferObj
.
conversation_id
,
taskId
:
bufferObj
.
task_id
,
messageId
:
bufferObj
.
id
,
})
isFirstMessage
=
false
}
else
if
(
bufferObj
.
event
===
'agent_thought'
)
{
console
.
log
(
bufferObj
)
}
}
})
buffer
=
lines
[
lines
.
length
-
1
]
...
...
@@ -333,6 +341,7 @@ export const ssePost = (url: string, fetchOptions: any, { isPublicAPI = false, o
}
return
handleStream
(
res
,
(
str
:
string
,
isFirstMessage
:
boolean
,
moreInfo
:
IOnDataMoreInfo
)
=>
{
if
(
moreInfo
.
errorMessage
)
{
// debugger
onError
?.(
moreInfo
.
errorMessage
)
if
(
moreInfo
.
errorMessage
!==
'AbortError: The user aborted a request.'
)
Toast
.
notify
({
type
:
'error'
,
message
:
moreInfo
.
errorMessage
})
...
...
@@ -343,7 +352,6 @@ export const ssePost = (url: string, fetchOptions: any, { isPublicAPI = false, o
}).
catch
((
e
)
=>
{
if
(
e
.
toString
()
!==
'AbortError: The user aborted a request.'
)
Toast
.
notify
({
type
:
'error'
,
message
:
e
})
onError
?.(
e
)
})
}
...
...
web/service/universal-chat.ts
View file @
ba9e2ea9
...
...
@@ -16,7 +16,7 @@ export const sendChatMessage = async (body: Record<string, any>, { onData, onCom
onError
:
IOnError
getAbortController
?:
(
abortController
:
AbortController
)
=>
void
})
=>
{
return
ssePost
(
getUrl
(
'
chat-
messages'
),
{
return
ssePost
(
getUrl
(
'messages'
),
{
body
:
{
...
body
,
response_mode
:
'streaming'
,
...
...
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