Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Dify.AI
Dify
提交
e65f9cb1
Dify
项目概览
Dify.AI
/
Dify
8 个月 前同步成功
通知
12
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
Dify
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
未验证
提交
e65f9cb1
编写于
9月 20, 2023
作者:
R
Rhon Joe
提交者:
GitHub
9月 19, 2023
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Complete type defined. (#1200)
上级
1367f343
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
27 addition
and
23 deletion
+27
-23
web/app/components/app/chat/copy-btn/index.tsx
web/app/components/app/chat/copy-btn/index.tsx
+5
-3
web/app/components/app/configuration/config/automatic/get-automatic-res.tsx
.../app/configuration/config/automatic/get-automatic-res.tsx
+4
-8
web/service/base.ts
web/service/base.ts
+11
-11
web/service/debug.ts
web/service/debug.ts
+7
-1
未找到文件。
web/app/components/app/chat/copy-btn/index.tsx
浏览文件 @
e65f9cb1
'
use client
'
'
use client
'
import
React
from
'
react
'
import
{
useRef
,
useState
}
from
'
react
'
import
{
t
}
from
'
i18next
'
import
{
t
}
from
'
i18next
'
import
copy
from
'
copy-to-clipboard
'
import
copy
from
'
copy-to-clipboard
'
import
s
from
'
./style.module.css
'
import
s
from
'
./style.module.css
'
import
Tooltip
from
'
@/app/components/base/tooltip
'
import
Tooltip
from
'
@/app/components/base/tooltip
'
import
{
randomString
}
from
'
@/utils
'
type
ICopyBtnProps
=
{
type
ICopyBtnProps
=
{
value
:
string
value
:
string
...
@@ -16,12 +17,13 @@ const CopyBtn = ({
...
@@ -16,12 +17,13 @@ const CopyBtn = ({
className
,
className
,
isPlain
,
isPlain
,
}:
ICopyBtnProps
)
=>
{
}:
ICopyBtnProps
)
=>
{
const
[
isCopied
,
setIsCopied
]
=
React
.
useState
(
false
)
const
[
isCopied
,
setIsCopied
]
=
useState
(
false
)
const
selector
=
useRef
(
`copy-tooltip-
${
randomString
(
4
)}
`
)
return
(
return
(
<
div
className
=
{
`
${
className
}
`
}
>
<
div
className
=
{
`
${
className
}
`
}
>
<
Tooltip
<
Tooltip
selector
=
{
`copy-btn-tooltip-
${
value
}
`
}
selector
=
{
selector
.
current
}
content
=
{
(
isCopied
?
t
(
'
appApi.copied
'
)
:
t
(
'
appApi.copy
'
))
as
string
}
content
=
{
(
isCopied
?
t
(
'
appApi.copied
'
)
:
t
(
'
appApi.copy
'
))
as
string
}
className
=
'z-10'
className
=
'z-10'
>
>
...
...
web/app/components/app/configuration/config/automatic/get-automatic-res.tsx
浏览文件 @
e65f9cb1
...
@@ -14,6 +14,8 @@ import OpeningStatement from '@/app/components/app/configuration/features/chat-g
...
@@ -14,6 +14,8 @@ import OpeningStatement from '@/app/components/app/configuration/features/chat-g
import
GroupName
from
'
@/app/components/app/configuration/base/group-name
'
import
GroupName
from
'
@/app/components/app/configuration/base/group-name
'
import
Loading
from
'
@/app/components/base/loading
'
import
Loading
from
'
@/app/components/base/loading
'
import
Confirm
from
'
@/app/components/base/confirm
'
import
Confirm
from
'
@/app/components/base/confirm
'
// type
import
type
{
AutomaticRes
}
from
'
@/service/debug
'
const
noDataIcon
=
(
const
noDataIcon
=
(
<
svg
width
=
"56"
height
=
"56"
viewBox
=
"0 0 56 56"
fill
=
"none"
xmlns
=
"http://www.w3.org/2000/svg"
>
<
svg
width
=
"56"
height
=
"56"
viewBox
=
"0 0 56 56"
fill
=
"none"
xmlns
=
"http://www.w3.org/2000/svg"
>
...
@@ -21,12 +23,6 @@ const noDataIcon = (
...
@@ -21,12 +23,6 @@ const noDataIcon = (
</
svg
>
</
svg
>
)
)
export
type
AutomaticRes
=
{
prompt
:
string
variables
:
string
[]
opening_statement
:
string
}
export
type
IGetAutomaticResProps
=
{
export
type
IGetAutomaticResProps
=
{
mode
:
AppType
mode
:
AppType
isShow
:
boolean
isShow
:
boolean
...
@@ -98,7 +94,7 @@ const GetAutomaticRes: FC<IGetAutomaticResProps> = ({
...
@@ -98,7 +94,7 @@ const GetAutomaticRes: FC<IGetAutomaticResProps> = ({
audiences
,
audiences
,
hoping_to_solve
:
hopingToSolve
,
hoping_to_solve
:
hopingToSolve
,
})
})
setRes
(
res
as
AutomaticRes
)
setRes
(
res
)
}
}
finally
{
finally
{
setLoadingFalse
()
setLoadingFalse
()
...
@@ -193,7 +189,7 @@ const GetAutomaticRes: FC<IGetAutomaticResProps> = ({
...
@@ -193,7 +189,7 @@ const GetAutomaticRes: FC<IGetAutomaticResProps> = ({
onClose
=
{
()
=>
setShowConfirmOverwrite
(
false
)
}
onClose
=
{
()
=>
setShowConfirmOverwrite
(
false
)
}
onConfirm
=
{
()
=>
{
onConfirm
=
{
()
=>
{
setShowConfirmOverwrite
(
false
)
setShowConfirmOverwrite
(
false
)
onFinished
(
res
as
AutomaticRes
)
onFinished
(
res
!
)
}
}
}
}
onCancel
=
{
()
=>
setShowConfirmOverwrite
(
false
)
}
onCancel
=
{
()
=>
setShowConfirmOverwrite
(
false
)
}
/>
/>
...
...
web/service/base.ts
浏览文件 @
e65f9cb1
...
@@ -77,18 +77,18 @@ export function format(text: string) {
...
@@ -77,18 +77,18 @@ export function format(text: string) {
return
res
.
replaceAll
(
'
\n
'
,
'
<br/>
'
).
replaceAll
(
'
```
'
,
''
)
return
res
.
replaceAll
(
'
\n
'
,
'
<br/>
'
).
replaceAll
(
'
```
'
,
''
)
}
}
const
handleStream
=
(
response
:
any
,
onData
:
IOnData
,
onCompleted
?:
IOnCompleted
,
onThought
?:
IOnThought
,
onMessageEnd
?:
IOnMessageEnd
)
=>
{
const
handleStream
=
(
response
:
Response
,
onData
:
IOnData
,
onCompleted
?:
IOnCompleted
,
onThought
?:
IOnThought
,
onMessageEnd
?:
IOnMessageEnd
)
=>
{
if
(
!
response
.
ok
)
if
(
!
response
.
ok
)
throw
new
Error
(
'
Network response was not ok
'
)
throw
new
Error
(
'
Network response was not ok
'
)
const
reader
=
response
.
body
.
getReader
()
const
reader
=
response
.
body
?
.
getReader
()
const
decoder
=
new
TextDecoder
(
'
utf-8
'
)
const
decoder
=
new
TextDecoder
(
'
utf-8
'
)
let
buffer
=
''
let
buffer
=
''
let
bufferObj
:
any
let
bufferObj
:
Record
<
string
,
any
>
let
isFirstMessage
=
true
let
isFirstMessage
=
true
function
read
()
{
function
read
()
{
let
hasError
=
false
let
hasError
=
false
reader
.
read
().
then
((
result
:
any
)
=>
{
reader
?
.
read
().
then
((
result
:
any
)
=>
{
if
(
result
.
done
)
{
if
(
result
.
done
)
{
onCompleted
&&
onCompleted
()
onCompleted
&&
onCompleted
()
return
return
...
@@ -99,7 +99,7 @@ const handleStream = (response: any, onData: IOnData, onCompleted?: IOnCompleted
...
@@ -99,7 +99,7 @@ const handleStream = (response: any, onData: IOnData, onCompleted?: IOnCompleted
lines
.
forEach
((
message
)
=>
{
lines
.
forEach
((
message
)
=>
{
if
(
message
.
startsWith
(
'
data:
'
))
{
// check if it starts with data:
if
(
message
.
startsWith
(
'
data:
'
))
{
// check if it starts with data:
try
{
try
{
bufferObj
=
JSON
.
parse
(
message
.
substring
(
6
))
// remove data: and parse as json
bufferObj
=
JSON
.
parse
(
message
.
substring
(
6
))
as
Record
<
string
,
any
>
// remove data: and parse as json
}
}
catch
(
e
)
{
catch
(
e
)
{
// mute handle message cut off
// mute handle message cut off
...
@@ -113,11 +113,11 @@ const handleStream = (response: any, onData: IOnData, onCompleted?: IOnCompleted
...
@@ -113,11 +113,11 @@ const handleStream = (response: any, onData: IOnData, onCompleted?: IOnCompleted
onData
(
''
,
false
,
{
onData
(
''
,
false
,
{
conversationId
:
undefined
,
conversationId
:
undefined
,
messageId
:
''
,
messageId
:
''
,
errorMessage
:
bufferObj
.
message
,
errorMessage
:
bufferObj
?
.
message
,
errorCode
:
bufferObj
.
code
,
errorCode
:
bufferObj
?
.
code
,
})
})
hasError
=
true
hasError
=
true
onCompleted
&&
onCompleted
(
true
)
onCompleted
?.
(
true
)
return
return
}
}
if
(
bufferObj
.
event
===
'
message
'
)
{
if
(
bufferObj
.
event
===
'
message
'
)
{
...
@@ -130,10 +130,10 @@ const handleStream = (response: any, onData: IOnData, onCompleted?: IOnCompleted
...
@@ -130,10 +130,10 @@ const handleStream = (response: any, onData: IOnData, onCompleted?: IOnCompleted
isFirstMessage
=
false
isFirstMessage
=
false
}
}
else
if
(
bufferObj
.
event
===
'
agent_thought
'
)
{
else
if
(
bufferObj
.
event
===
'
agent_thought
'
)
{
onThought
?.(
bufferObj
as
any
)
onThought
?.(
bufferObj
as
ThoughtItem
)
}
}
else
if
(
bufferObj
.
event
===
'
message_end
'
)
{
else
if
(
bufferObj
.
event
===
'
message_end
'
)
{
onMessageEnd
?.(
bufferObj
as
any
)
onMessageEnd
?.(
bufferObj
as
MessageEnd
)
}
}
}
}
})
})
...
@@ -146,7 +146,7 @@ const handleStream = (response: any, onData: IOnData, onCompleted?: IOnCompleted
...
@@ -146,7 +146,7 @@ const handleStream = (response: any, onData: IOnData, onCompleted?: IOnCompleted
errorMessage
:
`
${
e
}
`
,
errorMessage
:
`
${
e
}
`
,
})
})
hasError
=
true
hasError
=
true
onCompleted
&&
onCompleted
(
true
)
onCompleted
?.
(
true
)
return
return
}
}
if
(
!
hasError
)
if
(
!
hasError
)
...
...
web/service/debug.ts
浏览文件 @
e65f9cb1
import
type
{
IOnCompleted
,
IOnData
,
IOnError
,
IOnMessageEnd
}
from
'
./base
'
import
type
{
IOnCompleted
,
IOnData
,
IOnError
,
IOnMessageEnd
}
from
'
./base
'
import
{
get
,
post
,
ssePost
}
from
'
./base
'
import
{
get
,
post
,
ssePost
}
from
'
./base
'
export
type
AutomaticRes
=
{
prompt
:
string
variables
:
string
[]
opening_statement
:
string
}
export
const
sendChatMessage
=
async
(
appId
:
string
,
body
:
Record
<
string
,
any
>
,
{
onData
,
onCompleted
,
onError
,
getAbortController
,
onMessageEnd
}:
{
export
const
sendChatMessage
=
async
(
appId
:
string
,
body
:
Record
<
string
,
any
>
,
{
onData
,
onCompleted
,
onError
,
getAbortController
,
onMessageEnd
}:
{
onData
:
IOnData
onData
:
IOnData
onCompleted
:
IOnCompleted
onCompleted
:
IOnCompleted
...
@@ -46,7 +52,7 @@ export const fetchConvesationMessages = (appId: string, conversation_id: string)
...
@@ -46,7 +52,7 @@ export const fetchConvesationMessages = (appId: string, conversation_id: string)
}
}
export
const
generateRule
=
(
body
:
Record
<
string
,
any
>
)
=>
{
export
const
generateRule
=
(
body
:
Record
<
string
,
any
>
)
=>
{
return
post
(
'
/rule-generate
'
,
{
return
post
<
AutomaticRes
>
(
'
/rule-generate
'
,
{
body
,
body
,
})
})
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录