Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
赵月辉
/
fastgpt-migrated
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
Unverified
Commit
98ce5103
authored
Oct 07, 2023
by
Archer
Committed by
GitHub
Oct 07, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
v4.4.6 (#377)
parent
c65a36d3
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
56 changed files
with
609 additions
and
246 deletions
+609
-246
docSite/content/docs/installation/upgrading/40.md
+1
-1
docSite/content/docs/installation/upgrading/41.md
+1
-1
docSite/content/docs/installation/upgrading/42.md
+1
-1
docSite/content/docs/installation/upgrading/421.md
+1
-1
docSite/content/docs/installation/upgrading/43.md
+1
-1
docSite/content/docs/installation/upgrading/44.md
+1
-1
docSite/content/docs/installation/upgrading/441.md
+1
-1
docSite/content/docs/installation/upgrading/442.md
+1
-1
docSite/content/docs/installation/upgrading/445.md
+1
-1
docSite/content/docs/installation/upgrading/446.md
+15
-0
packages/core/ai/config.ts
+0
-0
packages/core/ai/constant.ts
+0
-0
packages/core/ai/functions/createQuestionGuide.ts
+57
-0
packages/core/ai/type.d.ts
+0
-0
pnpm-lock.yaml
+1
-1
projects/app/package.json
+1
-1
projects/app/public/docs/versionIntro.md
+8
-9
projects/app/public/imgs/module/app.png
+0
-0
projects/app/public/locales/en/common.json
+1
-0
projects/app/public/locales/zh/common.json
+1
-0
projects/app/src/api/core/ai/agent/type.d.ts
+2
-1
projects/app/src/components/ChatBox/ResponseTags.tsx
+19
-24
projects/app/src/components/ChatBox/index.tsx
+6
-11
projects/app/src/components/Markdown/chat/Guide.tsx
+13
-14
projects/app/src/constants/chat.ts
+2
-1
projects/app/src/constants/flow/ModuleTemplate.ts
+0
-0
projects/app/src/constants/flow/index.ts
+4
-2
projects/app/src/pages/api/core/ai/agent/createQuestionGuide.ts
+18
-50
projects/app/src/pages/api/openapi/plugin/vector.ts
+1
-1
projects/app/src/pages/api/user/account/update.ts
+1
-1
projects/app/src/pages/api/v1/chat/completions.ts
+17
-10
projects/app/src/pages/app/detail/components/AdEdit/components/Nodes/NodeAPP.tsx
+25
-0
projects/app/src/pages/app/detail/components/AdEdit/components/Provider.tsx
+4
-2
projects/app/src/pages/app/detail/components/AdEdit/components/render/RenderInput.tsx
+62
-2
projects/app/src/pages/app/detail/components/AdEdit/index.tsx
+14
-3
projects/app/src/pages/app/detail/components/DatasetSelectModal.tsx
+6
-1
projects/app/src/pages/app/detail/components/Logs.tsx
+0
-1
projects/app/src/pages/app/detail/components/SelectAppModal.tsx
+110
-0
projects/app/src/pages/app/list/index.tsx
+1
-1
projects/app/src/pages/chat/components/ToolMenu.tsx
+3
-4
projects/app/src/pages/chat/index.tsx
+0
-1
projects/app/src/pages/chat/share.tsx
+58
-57
projects/app/src/service/events/generateQA.ts
+2
-2
projects/app/src/service/moduleDispatch/agent/classifyQuestion.ts
+9
-9
projects/app/src/service/moduleDispatch/agent/extract.ts
+9
-9
projects/app/src/service/moduleDispatch/chat/oneapi.ts
+8
-6
projects/app/src/service/moduleDispatch/index.ts
+1
-0
projects/app/src/service/moduleDispatch/tools/answer.ts
+0
-2
projects/app/src/service/moduleDispatch/tools/runApp.ts
+80
-0
projects/app/src/service/support/outLink/auth.ts
+17
-2
projects/app/src/service/utils/auth.ts
+13
-4
projects/app/src/types/core/app/flow.d.ts
+6
-0
projects/app/src/types/core/chat/type.d.ts
+2
-2
projects/app/src/utils/adapt.ts
+1
-1
projects/app/src/utils/common/adapt/message.ts
+1
-1
projects/app/src/utils/common/tiktoken/index.ts
+1
-1
No files found.
docSite/content/docs/installation/upgrading/40.md
View file @
98ce5103
...
@@ -4,7 +4,7 @@ description: 'FastGPT 从旧版本升级到 V4.0 操作指南'
...
@@ -4,7 +4,7 @@ description: 'FastGPT 从旧版本升级到 V4.0 操作指南'
icon
:
'
upgrade'
icon
:
'
upgrade'
draft
:
false
draft
:
false
toc
:
true
toc
:
true
weight
:
100
0
weight
:
85
0
---
---
如果您是
**从旧版本升级到 V4**
,由于新版 MongoDB 表变更比较大,需要按照本文档的说明执行一些初始化脚本。
如果您是
**从旧版本升级到 V4**
,由于新版 MongoDB 表变更比较大,需要按照本文档的说明执行一些初始化脚本。
...
...
docSite/content/docs/installation/upgrading/41.md
View file @
98ce5103
...
@@ -4,7 +4,7 @@ description: 'FastGPT 从旧版本升级到 V4.1 操作指南'
...
@@ -4,7 +4,7 @@ description: 'FastGPT 从旧版本升级到 V4.1 操作指南'
icon
:
'
upgrade'
icon
:
'
upgrade'
draft
:
false
draft
:
false
toc
:
true
toc
:
true
weight
:
99
9
weight
:
84
9
---
---
如果您是
**从旧版本升级到 V4.1**
,由于新版重新设置了对话存储结构,需要初始化原来的存储内容。
如果您是
**从旧版本升级到 V4.1**
,由于新版重新设置了对话存储结构,需要初始化原来的存储内容。
...
...
docSite/content/docs/installation/upgrading/42.md
View file @
98ce5103
...
@@ -4,7 +4,7 @@ description: 'FastGPT 从旧版本升级到 V4.2 操作指南'
...
@@ -4,7 +4,7 @@ description: 'FastGPT 从旧版本升级到 V4.2 操作指南'
icon
:
'
upgrade'
icon
:
'
upgrade'
draft
:
false
draft
:
false
toc
:
true
toc
:
true
weight
:
99
8
weight
:
84
8
---
---
99.
9%用户不影响,升级 4.2 主要是修改了配置文件中 QAModel 的格式。从原先的数组改成对象:
99.
9%用户不影响,升级 4.2 主要是修改了配置文件中 QAModel 的格式。从原先的数组改成对象:
...
...
docSite/content/docs/installation/upgrading/421.md
View file @
98ce5103
...
@@ -4,7 +4,7 @@ description: 'FastGPT 从旧版本升级到 V4.2.1 操作指南'
...
@@ -4,7 +4,7 @@ description: 'FastGPT 从旧版本升级到 V4.2.1 操作指南'
icon
:
'
upgrade'
icon
:
'
upgrade'
draft
:
false
draft
:
false
toc
:
true
toc
:
true
weight
:
99
7
weight
:
84
7
---
---
私有部署,如果添加了配置文件,需要在配置文件中修改
`VectorModels`
字段。增加 defaultToken 和 maxToken,分别对应直接分段时的默认 token 数量和该模型支持的 token 上限(通常不建议超过 3000)
私有部署,如果添加了配置文件,需要在配置文件中修改
`VectorModels`
字段。增加 defaultToken 和 maxToken,分别对应直接分段时的默认 token 数量和该模型支持的 token 上限(通常不建议超过 3000)
...
...
docSite/content/docs/installation/upgrading/43.md
View file @
98ce5103
...
@@ -4,7 +4,7 @@ description: 'FastGPT 从旧版本升级到 V4.3 操作指南'
...
@@ -4,7 +4,7 @@ description: 'FastGPT 从旧版本升级到 V4.3 操作指南'
icon
:
'
upgrade'
icon
:
'
upgrade'
draft
:
false
draft
:
false
toc
:
true
toc
:
true
weight
:
99
6
weight
:
84
6
---
---
## 执行初始化 API
## 执行初始化 API
...
...
docSite/content/docs/installation/upgrading/44.md
View file @
98ce5103
...
@@ -4,7 +4,7 @@ description: 'FastGPT 从旧版本升级到 V4.4 操作指南'
...
@@ -4,7 +4,7 @@ description: 'FastGPT 从旧版本升级到 V4.4 操作指南'
icon
:
'
upgrade'
icon
:
'
upgrade'
draft
:
false
draft
:
false
toc
:
true
toc
:
true
weight
:
99
5
weight
:
84
5
---
---
## 执行初始化 API
## 执行初始化 API
...
...
docSite/content/docs/installation/upgrading/441.md
View file @
98ce5103
...
@@ -4,7 +4,7 @@ description: 'FastGPT 从旧版本升级到 V4.4.1 操作指南'
...
@@ -4,7 +4,7 @@ description: 'FastGPT 从旧版本升级到 V4.4.1 操作指南'
icon
:
'
upgrade'
icon
:
'
upgrade'
draft
:
false
draft
:
false
toc
:
true
toc
:
true
weight
:
99
4
weight
:
84
4
---
---
## 执行初始化 API
## 执行初始化 API
...
...
docSite/content/docs/installation/upgrading/442.md
View file @
98ce5103
...
@@ -4,7 +4,7 @@ description: 'FastGPT 从旧版本升级到 V4.4.2 操作指南'
...
@@ -4,7 +4,7 @@ description: 'FastGPT 从旧版本升级到 V4.4.2 操作指南'
icon
:
'
upgrade'
icon
:
'
upgrade'
draft
:
false
draft
:
false
toc
:
true
toc
:
true
weight
:
99
3
weight
:
84
3
---
---
## 执行初始化 API
## 执行初始化 API
...
...
docSite/content/docs/installation/upgrading/445.md
View file @
98ce5103
...
@@ -4,7 +4,7 @@ description: 'FastGPT V4.4.5 更新(需执行升级脚本)'
...
@@ -4,7 +4,7 @@ description: 'FastGPT V4.4.5 更新(需执行升级脚本)'
icon
:
'
upgrade'
icon
:
'
upgrade'
draft
:
false
draft
:
false
toc
:
true
toc
:
true
weight
:
99
2
weight
:
84
2
---
---
## 执行初始化 API
## 执行初始化 API
...
...
docSite/content/docs/installation/upgrading/446.md
0 → 100644
View file @
98ce5103
---
title
:
'
V4.4.6'
description
:
'
FastGPT
V4.4.6
更新'
icon
:
'
upgrade'
draft
:
false
toc
:
true
weight
:
841
---
## 功能介绍
1.
高级编排新增模块 - 应用调用,可调用其他应用。
2.
新增 - 必要连接校验
3.
修复 - 下一步指引在免登录中身份问题。
\ No newline at end of file
packages/core/ai
Api
/config.ts
→
packages/core/ai/config.ts
View file @
98ce5103
File moved
packages/core/ai
Api
/constant.ts
→
packages/core/ai/constant.ts
View file @
98ce5103
File moved
packages/core/ai/functions/createQuestionGuide.ts
0 → 100644
View file @
98ce5103
import
{
ChatCompletionRequestMessage
}
from
'../type'
;
import
{
getAIChatApi
}
from
'../config'
;
export
const
Prompt_QuestionGuide
=
`我不太清楚问你什么问题,请帮我生成 3 个问题,引导我继续提问。问题的长度应小于20个字符,按 JSON 格式返回: ["问题1", "问题2", "问题3"]`
;
export
async
function
createQuestionGuide
({
messages
,
model
}:
{
messages
:
ChatCompletionRequestMessage
[];
model
:
string
;
})
{
const
chatAPI
=
getAIChatApi
();
const
{
data
}
=
await
chatAPI
.
createChatCompletion
({
model
:
model
,
temperature
:
0
,
max_tokens
:
200
,
messages
:
[
...
messages
,
{
role
:
'user'
,
content
:
Prompt_QuestionGuide
}
],
stream
:
false
});
const
answer
=
data
.
choices
?.[
0
].
message
?.
content
||
''
;
const
totalTokens
=
data
.
usage
?.
total_tokens
||
0
;
const
start
=
answer
.
indexOf
(
'['
);
const
end
=
answer
.
lastIndexOf
(
']'
);
if
(
start
===
-
1
||
end
===
-
1
)
{
return
{
result
:
[],
tokens
:
totalTokens
};
}
const
jsonStr
=
answer
.
substring
(
start
,
end
+
1
)
.
replace
(
/
(\\
n|
\\)
/g
,
''
)
.
replace
(
/ /g
,
''
);
try
{
return
{
result
:
JSON
.
parse
(
jsonStr
),
tokens
:
totalTokens
};
}
catch
(
error
)
{
return
{
result
:
[],
tokens
:
totalTokens
};
}
}
packages/core/ai
Api
/type.d.ts
→
packages/core/ai/type.d.ts
View file @
98ce5103
File moved
pnpm-lock.yaml
View file @
98ce5103
lockfileVersion
:
'
6.
0
'
lockfileVersion
:
'
6.
1
'
settings
:
settings
:
autoInstallPeers
:
true
autoInstallPeers
:
true
...
...
projects/app/package.json
View file @
98ce5103
{
{
"name"
:
"
app
"
,
"name"
:
"
app
"
,
"version"
:
"4.4.
5
"
,
"version"
:
"4.4.
6
"
,
"private"
:
false
,
"private"
:
false
,
"scripts"
:
{
"scripts"
:
{
"dev"
:
"next dev"
,
"dev"
:
"next dev"
,
...
...
projects/app/public/docs/versionIntro.md
View file @
98ce5103
### Fast GPT V4.4.
5
### Fast GPT V4.4.
6
1.
新增 - 下一步指引选项,可以通过模型生成 3 个预测问题。
1.
高级编排新增模块 - 应用调用
2.
新增 - 分享链接 hook 身份校验。
2.
新增 - 必要连接校验
3.
新增 - Api Key 使用。增加别名、额度限制和过期时间。自带 appId,无需额外连接。
3.
新增 - 下一步指引选项,可以通过模型生成 3 个预测问题。
4.
去除 - 限定词。目前旧应用仍生效,9/25 后全面去除,请及时替换。
4.
新增 - 分享链接 hook 身份校验。
5.
新增 - 引用模板/引用提示词设置,可以 DIY 引用内容的格式,从而更好的适配场景。
[
参考文档
](
https://doc.fastgpt.run/docs/use-cases/prompt/
)
5.
[
使用文档
](
https://doc.fastgpt.run/docs/intro/
)
6.
[
使用文档
](
https://doc.fastgpt.run/docs/intro/
)
6.
[
点击查看高级编排介绍文档
](
https://doc.fastgpt.run/docs/workflow
)
7.
[
点击查看高级编排介绍文档
](
https://doc.fastgpt.run/docs/workflow
)
7.
[
点击查看商业版
](
https://doc.fastgpt.run/docs/commercial/
)
8.
[
点击查看商业版
](
https://doc.fastgpt.run/docs/commercial/
)
projects/app/public/imgs/module/app.png
0 → 100644
View file @
98ce5103
2.21 KB
projects/app/public/locales/en/common.json
View file @
98ce5103
...
@@ -96,6 +96,7 @@
...
@@ -96,6 +96,7 @@
"module question"
:
"Question"
,
"module question"
:
"Question"
,
"module quoteList"
:
"Quotes"
,
"module quoteList"
:
"Quotes"
,
"module runningTime"
:
"Time"
,
"module runningTime"
:
"Time"
,
"module search response"
:
"Search Result"
,
"module similarity"
:
"Similarity"
,
"module similarity"
:
"Similarity"
,
"module temperature"
:
"Temperature"
,
"module temperature"
:
"Temperature"
,
"module time"
:
"Running Time"
,
"module time"
:
"Running Time"
,
...
...
projects/app/public/locales/zh/common.json
View file @
98ce5103
...
@@ -96,6 +96,7 @@
...
@@ -96,6 +96,7 @@
"module question"
:
"问题"
,
"module question"
:
"问题"
,
"module quoteList"
:
"引用内容"
,
"module quoteList"
:
"引用内容"
,
"module runningTime"
:
"运行时长"
,
"module runningTime"
:
"运行时长"
,
"module search response"
:
"搜索结果"
,
"module similarity"
:
"相似度"
,
"module similarity"
:
"相似度"
,
"module temperature"
:
"温度"
,
"module temperature"
:
"温度"
,
"module time"
:
"运行时长"
,
"module time"
:
"运行时长"
,
...
...
projects/app/src/api/core/ai/agent/type.d.ts
View file @
98ce5103
import
{
ChatCompletionRequestMessage
}
from
'@fastgpt/core/ai
Api
/type'
;
import
{
ChatCompletionRequestMessage
}
from
'@fastgpt/core/ai/type'
;
export
type
CreateQuestionGuideProps
=
{
export
type
CreateQuestionGuideProps
=
{
messages
:
ChatCompletionRequestMessage
[];
messages
:
ChatCompletionRequestMessage
[];
shareId
?:
string
;
};
};
projects/app/src/components/ChatBox/ResponseTags.tsx
View file @
98ce5103
...
@@ -12,15 +12,7 @@ const QuoteModal = dynamic(() => import('./QuoteModal'), { ssr: false });
...
@@ -12,15 +12,7 @@ const QuoteModal = dynamic(() => import('./QuoteModal'), { ssr: false });
const
ContextModal
=
dynamic
(()
=>
import
(
'./ContextModal'
),
{
ssr
:
false
});
const
ContextModal
=
dynamic
(()
=>
import
(
'./ContextModal'
),
{
ssr
:
false
});
const
WholeResponseModal
=
dynamic
(()
=>
import
(
'./WholeResponseModal'
),
{
ssr
:
false
});
const
WholeResponseModal
=
dynamic
(()
=>
import
(
'./WholeResponseModal'
),
{
ssr
:
false
});
const
ResponseTags
=
({
const
ResponseTags
=
({
responseData
=
[]
}:
{
responseData
?:
ChatHistoryItemResType
[]
})
=>
{
chatId
,
contentId
,
responseData
=
[]
}:
{
chatId
?:
string
;
contentId
?:
string
;
responseData
?:
ChatHistoryItemResType
[];
})
=>
{
const
{
isPc
}
=
useGlobalStore
();
const
{
isPc
}
=
useGlobalStore
();
const
{
t
}
=
useTranslation
();
const
{
t
}
=
useTranslation
();
const
[
quoteModalData
,
setQuoteModalData
]
=
useState
<
QuoteItemType
[]
>
();
const
[
quoteModalData
,
setQuoteModalData
]
=
useState
<
QuoteItemType
[]
>
();
...
@@ -41,9 +33,12 @@ const ResponseTags = ({
...
@@ -41,9 +33,12 @@ const ResponseTags = ({
return
{
return
{
chatAccount
:
responseData
.
filter
((
item
)
=>
item
.
moduleType
===
FlowModuleTypeEnum
.
chatNode
)
chatAccount
:
responseData
.
filter
((
item
)
=>
item
.
moduleType
===
FlowModuleTypeEnum
.
chatNode
)
.
length
,
.
length
,
quoteList
:
chatData
?.
quoteList
,
quoteList
:
responseData
.
filter
((
item
)
=>
item
.
moduleType
===
FlowModuleTypeEnum
.
chatNode
)
.
map
((
item
)
=>
item
.
quoteList
)
.
flat
(),
historyPreview
:
chatData
?.
historyPreview
,
historyPreview
:
chatData
?.
historyPreview
,
runningTime
:
responseData
.
reduce
((
sum
,
item
)
=>
sum
+
(
item
.
runningTime
||
0
),
0
).
toFixed
(
2
)
runningTime
:
+
responseData
.
reduce
((
sum
,
item
)
=>
sum
+
(
item
.
runningTime
||
0
),
0
).
toFixed
(
2
)
};
};
},
[
responseData
]);
},
[
responseData
]);
...
@@ -56,20 +51,20 @@ const ResponseTags = ({
...
@@ -56,20 +51,20 @@ const ResponseTags = ({
return
responseData
.
length
===
0
?
null
:
(
return
responseData
.
length
===
0
?
null
:
(
<
Flex
alignItems=
{
'center'
}
mt=
{
2
}
flexWrap=
{
'wrap'
}
>
<
Flex
alignItems=
{
'center'
}
mt=
{
2
}
flexWrap=
{
'wrap'
}
>
{
quoteList
.
length
>
0
&&
(
<
MyTooltip
label=
"查看引用"
>
<
Tag
colorSchema=
"blue"
cursor=
{
'pointer'
}
{
...
TagStyles
}
onClick=
{
()
=>
setQuoteModalData
(
quoteList
)
}
>
{
quoteList
.
length
}
条引用
</
Tag
>
</
MyTooltip
>
)
}
{
chatAccount
===
1
&&
(
{
chatAccount
===
1
&&
(
<>
<>
{
quoteList
.
length
>
0
&&
(
<
MyTooltip
label=
"查看引用"
>
<
Tag
colorSchema=
"blue"
cursor=
{
'pointer'
}
{
...
TagStyles
}
onClick=
{
()
=>
setQuoteModalData
(
quoteList
)
}
>
{
quoteList
.
length
}
条引用
</
Tag
>
</
MyTooltip
>
)
}
{
historyPreview
.
length
>
0
&&
(
{
historyPreview
.
length
>
0
&&
(
<
MyTooltip
label=
{
'点击查看完整对话记录'
}
>
<
MyTooltip
label=
{
'点击查看完整对话记录'
}
>
<
Tag
<
Tag
...
@@ -120,4 +115,4 @@ const ResponseTags = ({
...
@@ -120,4 +115,4 @@ const ResponseTags = ({
);
);
};
};
export
default
Re
sponseTags
;
export
default
Re
act
.
memo
(
ResponseTags
)
;
projects/app/src/components/ChatBox/index.tsx
View file @
98ce5103
...
@@ -34,7 +34,7 @@ import { feConfigs } from '@/store/static';
...
@@ -34,7 +34,7 @@ import { feConfigs } from '@/store/static';
import
{
event
}
from
'@/utils/plugin/eventbus'
;
import
{
event
}
from
'@/utils/plugin/eventbus'
;
import
{
adaptChat2GptMessages
}
from
'@/utils/common/adapt/message'
;
import
{
adaptChat2GptMessages
}
from
'@/utils/common/adapt/message'
;
import
{
useMarkdown
}
from
'@/hooks/useMarkdown'
;
import
{
useMarkdown
}
from
'@/hooks/useMarkdown'
;
import
{
AppModuleItemType
,
VariableItemType
}
from
'@/types/app'
;
import
{
AppModuleItemType
}
from
'@/types/app'
;
import
{
VariableInputEnum
}
from
'@/constants/app'
;
import
{
VariableInputEnum
}
from
'@/constants/app'
;
import
{
useForm
}
from
'react-hook-form'
;
import
{
useForm
}
from
'react-hook-form'
;
import
type
{
MessageItemType
}
from
'@/types/core/chat/type'
;
import
type
{
MessageItemType
}
from
'@/types/core/chat/type'
;
...
@@ -81,7 +81,7 @@ export type StartChatFnProps = {
...
@@ -81,7 +81,7 @@ export type StartChatFnProps = {
export
type
ComponentRef
=
{
export
type
ComponentRef
=
{
getChatHistory
:
()
=>
ChatSiteItemType
[];
getChatHistory
:
()
=>
ChatSiteItemType
[];
resetVariables
:
(
data
?:
Record
<
string
,
any
>
)
=>
void
;
resetVariables
:
(
data
?:
Record
<
string
,
any
>
)
=>
void
;
resetHistory
:
(
chatId
:
ChatSiteItemType
[])
=>
void
;
resetHistory
:
(
history
:
ChatSiteItemType
[])
=>
void
;
scrollToBottom
:
(
behavior
?:
'smooth'
|
'auto'
)
=>
void
;
scrollToBottom
:
(
behavior
?:
'smooth'
|
'auto'
)
=>
void
;
};
};
...
@@ -96,7 +96,6 @@ type Props = {
...
@@ -96,7 +96,6 @@ type Props = {
showMarkIcon
?:
boolean
;
// admin mark dataset
showMarkIcon
?:
boolean
;
// admin mark dataset
showVoiceIcon
?:
boolean
;
showVoiceIcon
?:
boolean
;
showEmptyIntro
?:
boolean
;
showEmptyIntro
?:
boolean
;
chatId
?:
string
;
appAvatar
?:
string
;
appAvatar
?:
string
;
userAvatar
?:
string
;
userAvatar
?:
string
;
userGuideModule
?:
AppModuleItemType
;
userGuideModule
?:
AppModuleItemType
;
...
@@ -116,7 +115,6 @@ const ChatBox = (
...
@@ -116,7 +115,6 @@ const ChatBox = (
showMarkIcon
=
false
,
showMarkIcon
=
false
,
showVoiceIcon
=
true
,
showVoiceIcon
=
true
,
showEmptyIntro
=
false
,
showEmptyIntro
=
false
,
chatId
,
appAvatar
,
appAvatar
,
userAvatar
,
userAvatar
,
userGuideModule
,
userGuideModule
,
...
@@ -265,7 +263,8 @@ const ChatBox = (
...
@@ -265,7 +263,8 @@ const ChatBox = (
const
result
=
await
postQuestionGuide
(
const
result
=
await
postQuestionGuide
(
{
{
messages
:
adaptChat2GptMessages
({
messages
:
history
,
reserveId
:
false
}).
slice
(
-
6
)
messages
:
adaptChat2GptMessages
({
messages
:
history
,
reserveId
:
false
}).
slice
(
-
6
),
shareId
:
router
.
query
.
shareId
as
string
},
},
abortSignal
abortSignal
);
);
...
@@ -277,7 +276,7 @@ const ChatBox = (
...
@@ -277,7 +276,7 @@ const ChatBox = (
}
}
}
catch
(
error
)
{}
}
catch
(
error
)
{}
},
},
[
questionGuide
,
scrollToBottom
]
[
questionGuide
,
scrollToBottom
,
router
.
query
.
shareId
]
);
);
/**
/**
...
@@ -743,11 +742,7 @@ const ChatBox = (
...
@@ -743,11 +742,7 @@ const ChatBox = (
source=
{
item
.
value
}
source=
{
item
.
value
}
isChatting=
{
index
===
chatHistory
.
length
-
1
&&
isChatting
}
isChatting=
{
index
===
chatHistory
.
length
-
1
&&
isChatting
}
/>
/>
<
ResponseTags
<
ResponseTags
responseData=
{
item
.
responseData
}
/>
chatId=
{
chatId
}
contentId=
{
item
.
dataId
}
responseData=
{
item
.
responseData
}
/>
{
/* question guide */
}
{
/* question guide */
}
{
index
===
chatHistory
.
length
-
1
&&
{
index
===
chatHistory
.
length
-
1
&&
!
isChatting
&&
!
isChatting
&&
...
...
projects/app/src/components/Markdown/chat/Guide.tsx
View file @
98ce5103
...
@@ -20,19 +20,17 @@ function MyLink(e: any) {
...
@@ -20,19 +20,17 @@ function MyLink(e: any) {
{
text
}
{
text
}
</
Link
>
</
Link
>
)
:
(
)
:
(
<
Box
as=
{
'ul'
}
mt=
{
'0 !important'
}
>
<
Box
as=
{
'li'
}
mb=
{
1
}
>
<
Box
as=
{
'li'
}
mb=
{
1
}
>
<
Box
<
Box
as=
{
'span'
}
as=
{
'span'
}
color=
{
'blue.600'
}
color=
{
'blue.600'
}
textDecoration=
{
'underline'
}
textDecoration=
{
'underline'
}
cursor=
{
'pointer'
}
cursor=
{
'pointer'
}
onClick=
{
()
=>
{
onClick=
{
()
=>
{
event
.
emit
(
'guideClick'
,
{
text
});
event
.
emit
(
'guideClick'
,
{
text
});
}
}
}
}
>
>
{
text
}
{
text
}
</
Box
>
</
Box
>
</
Box
>
</
Box
>
</
Box
>
);
);
...
@@ -40,9 +38,10 @@ function MyLink(e: any) {
...
@@ -40,9 +38,10 @@ function MyLink(e: any) {
const
Guide
=
({
text
}:
{
text
:
string
})
=>
{
const
Guide
=
({
text
}:
{
text
:
string
})
=>
{
const
formatText
=
useMemo
(
const
formatText
=
useMemo
(
()
=>
text
.
replace
(
/
\[(
.*
?)\](
$|
\n)
/g
,
'[$1]()
\n
'
).
replace
(
/
\\
n/g
,
'\n '
),
()
=>
text
.
replace
(
/
\[(
.*
?)\](
$|
\n)
/g
,
'[$1]()'
).
replace
(
/
\\
n/g
,
'\n '
),
[
text
]
[
text
]
);
);
return
(
return
(
<
ReactMarkdown
<
ReactMarkdown
className=
{
`markdown ${styles.markdown}`
}
className=
{
`markdown ${styles.markdown}`
}
...
...
projects/app/src/constants/chat.ts
View file @
98ce5103
...
@@ -15,7 +15,8 @@ export enum ChatRoleEnum {
...
@@ -15,7 +15,8 @@ export enum ChatRoleEnum {
export
enum
TaskResponseKeyEnum
{
export
enum
TaskResponseKeyEnum
{
'answerText'
=
'answerText'
,
// answer module text key
'answerText'
=
'answerText'
,
// answer module text key
'responseData'
=
'responseData'
'responseData'
=
'responseData'
,
'history'
=
'history'
}
}
export
const
ChatRoleMap
=
{
export
const
ChatRoleMap
=
{
...
...
projects/app/src/constants/flow/ModuleTemplate.ts
View file @
98ce5103
This diff is collapsed.
Click to expand it.
projects/app/src/constants/flow/index.ts
View file @
98ce5103
...
@@ -11,7 +11,8 @@ export enum FlowInputItemTypeEnum {
...
@@ -11,7 +11,8 @@ export enum FlowInputItemTypeEnum {
target
=
'target'
,
target
=
'target'
,
none
=
'none'
,
none
=
'none'
,
switch
=
'switch'
,
switch
=
'switch'
,
hidden
=
'hidden'
hidden
=
'hidden'
,
selectApp
=
'selectApp'
}
}
export
enum
FlowOutputItemTypeEnum
{
export
enum
FlowOutputItemTypeEnum
{
...
@@ -33,7 +34,8 @@ export enum FlowModuleTypeEnum {
...
@@ -33,7 +34,8 @@ export enum FlowModuleTypeEnum {
answerNode
=
'answerNode'
,
answerNode
=
'answerNode'
,
classifyQuestion
=
'classifyQuestion'
,
classifyQuestion
=
'classifyQuestion'
,
contentExtract
=
'contentExtract'
,
contentExtract
=
'contentExtract'
,
httpRequest
=
'httpRequest'
httpRequest
=
'httpRequest'
,
app
=
'app'
}
}
export
enum
SpecialInputKeyEnum
{
export
enum
SpecialInputKeyEnum
{
...
...
projects/app/src/pages/api/core/ai/agent/createQuestionGuide.ts
View file @
98ce5103
...
@@ -3,71 +3,39 @@ import { jsonRes } from '@/service/response';
...
@@ -3,71 +3,39 @@ import { jsonRes } from '@/service/response';
import
{
connectToDatabase
}
from
'@/service/mongo'
;
import
{
connectToDatabase
}
from
'@/service/mongo'
;
import
{
authUser
}
from
'@/service/utils/auth'
;
import
{
authUser
}
from
'@/service/utils/auth'
;
import
{
CreateQuestionGuideProps
}
from
'@/api/core/ai/agent/type'
;
import
{
CreateQuestionGuideProps
}
from
'@/api/core/ai/agent/type'
;
import
{
getAIChatApi
}
from
'@fastgpt/core/aiApi/config'
;
import
{
Prompt_QuestionGuide
}
from
'@/prompts/core/agent'
;
import
{
pushQuestionGuideBill
}
from
'@/service/common/bill/push'
;
import
{
pushQuestionGuideBill
}
from
'@/service/common/bill/push'
;
import
{
defaultQGModel
}
from
'@/pages/api/system/getInitData'
;
import
{
defaultQGModel
}
from
'@/pages/api/system/getInitData'
;
import
{
createQuestionGuide
}
from
'@fastgpt/core/ai/functions/createQuestionGuide'
;
export
default
async
function
handler
(
req
:
NextApiRequest
,
res
:
NextApiResponse
<
any
>
)
{
export
default
async
function
handler
(
req
:
NextApiRequest
,
res
:
NextApiResponse
<
any
>
)
{
try
{
try
{
await
connectToDatabase
();
await
connectToDatabase
();
const
{
messages
}
=
req
.
body
as
CreateQuestionGuideProps
;
const
{
messages
}
=
req
.
body
as
CreateQuestionGuideProps
;
const
{
user
}
=
await
authUser
({
req
,
authToken
:
true
,
authApiKey
:
true
,
authBalance
:
true
});
const
{
user
}
=
await
authUser
({
req
,
authOutLink
:
true
,
authToken
:
true
,
authApiKey
:
true
,
authBalance
:
true
});
if
(
!
user
)
{
if
(
!
user
)
{
throw
new
Error
(
'user not found'
);
throw
new
Error
(
'user not found'
);
}
}
const
qgModel
=
global
.
qgModel
||
defaultQGModel
;
const
chatAPI
=
getAIChatApi
(
user
.
openaiAccount
);
const
{
data
}
=
await
chatAPI
.
createChatCompletion
({
const
{
result
,
tokens
}
=
await
createQuestionGuide
({
model
:
qgModel
.
model
,
messages
,
temperature
:
0
,
model
:
(
global
.
qgModel
||
defaultQGModel
).
model
max_tokens
:
200
,
messages
:
[
...
messages
,
{
role
:
'user'
,
content
:
Prompt_QuestionGuide
}
],
stream
:
false
});
});
const
answer
=
data
.
choices
?.[
0
].
message
?.
content
||
''
;
jsonRes
(
res
,
{
const
totalTokens
=
data
.
usage
?.
total_tokens
||
0
;
data
:
result
});
const
start
=
answer
.
indexOf
(
'['
);
const
end
=
answer
.
lastIndexOf
(
']'
);
if
(
start
===
-
1
||
end
===
-
1
)
{
return
jsonRes
(
res
,
{
data
:
[]
});
}
const
jsonStr
=
answer
.
substring
(
start
,
end
+
1
)
.
replace
(
/
(\\
n|
\\)
/g
,
''
)
.
replace
(
/ /g
,
''
);
try
{
jsonRes
(
res
,
{
data
:
JSON
.
parse
(
jsonStr
)
});
pushQuestionGuideBill
({
tokens
:
totalTokens
,
userId
:
user
.
_id
});
return
;
pushQuestionGuideBill
({
}
catch
(
error
)
{
tokens
:
tokens
,
return
jsonRes
(
res
,
{
userId
:
user
.
_id
data
:
[]
});
});
}
}
catch
(
err
)
{
}
catch
(
err
)
{
jsonRes
(
res
,
{
jsonRes
(
res
,
{
code
:
500
,
code
:
500
,
...
...
projects/app/src/pages/api/openapi/plugin/vector.ts
View file @
98ce5103
...
@@ -2,7 +2,7 @@ import type { NextApiRequest, NextApiResponse } from 'next';
...
@@ -2,7 +2,7 @@ import type { NextApiRequest, NextApiResponse } from 'next';
import
{
jsonRes
}
from
'@/service/response'
;
import
{
jsonRes
}
from
'@/service/response'
;
import
{
authBalanceByUid
,
authUser
}
from
'@/service/utils/auth'
;
import
{
authBalanceByUid
,
authUser
}
from
'@/service/utils/auth'
;
import
{
withNextCors
}
from
'@/service/utils/tools'
;
import
{
withNextCors
}
from
'@/service/utils/tools'
;
import
{
getAIChatApi
,
axiosConfig
}
from
'@fastgpt/core/ai
Api
/config'
;
import
{
getAIChatApi
,
axiosConfig
}
from
'@fastgpt/core/ai/config'
;
import
{
pushGenerateVectorBill
}
from
'@/service/common/bill/push'
;
import
{
pushGenerateVectorBill
}
from
'@/service/common/bill/push'
;
type
Props
=
{
type
Props
=
{
...
...
projects/app/src/pages/api/user/account/update.ts
View file @
98ce5103
...
@@ -5,7 +5,7 @@ import { User } from '@/service/models/user';
...
@@ -5,7 +5,7 @@ import { User } from '@/service/models/user';
import
{
connectToDatabase
}
from
'@/service/mongo'
;
import
{
connectToDatabase
}
from
'@/service/mongo'
;
import
{
authUser
}
from
'@/service/utils/auth'
;
import
{
authUser
}
from
'@/service/utils/auth'
;
import
{
UserUpdateParams
}
from
'@/types/user'
;
import
{
UserUpdateParams
}
from
'@/types/user'
;
import
{
axiosConfig
,
getAIChatApi
,
openaiBaseUrl
}
from
'@fastgpt/core/ai
Api
/config'
;
import
{
axiosConfig
,
getAIChatApi
,
openaiBaseUrl
}
from
'@fastgpt/core/ai/config'
;
/* update user info */
/* update user info */
export
default
async
function
handler
(
req
:
NextApiRequest
,
res
:
NextApiResponse
<
any
>
)
{
export
default
async
function
handler
(
req
:
NextApiRequest
,
res
:
NextApiResponse
<
any
>
)
{
...
...
projects/app/src/pages/api/v1/chat/completions.ts
View file @
98ce5103
...
@@ -12,9 +12,10 @@ import {
...
@@ -12,9 +12,10 @@ import {
dispatchAnswer
,
dispatchAnswer
,
dispatchClassifyQuestion
,
dispatchClassifyQuestion
,
dispatchContentExtract
,
dispatchContentExtract
,
dispatchHttpRequest
dispatchHttpRequest
,
dispatchAppRequest
}
from
'@/service/moduleDispatch'
;
}
from
'@/service/moduleDispatch'
;
import
type
{
CreateChatCompletionRequest
}
from
'@fastgpt/core/ai
Api
/type'
;
import
type
{
CreateChatCompletionRequest
}
from
'@fastgpt/core/ai/type'
;
import
type
{
MessageItemType
}
from
'@/types/core/chat/type'
;
import
type
{
MessageItemType
}
from
'@/types/core/chat/type'
;
import
{
gptMessage2ChatType
,
textAdaptGptResponse
}
from
'@/utils/adapt'
;
import
{
gptMessage2ChatType
,
textAdaptGptResponse
}
from
'@/utils/adapt'
;
import
{
getChatHistory
}
from
'./getHistory'
;
import
{
getChatHistory
}
from
'./getHistory'
;
...
@@ -325,14 +326,19 @@ export async function dispatchModules({
...
@@ -325,14 +326,19 @@ export async function dispatchModules({
responseData
responseData
}:
{
}:
{
answerText
?:
string
;
answerText
?:
string
;
responseData
?:
ChatHistoryItemResType
;
responseData
?:
ChatHistoryItemResType
|
ChatHistoryItemResType
[]
;
})
{
})
{
const
time
=
Date
.
now
();
const
time
=
Date
.
now
();
responseData
&&
if
(
responseData
)
{
chatResponse
.
push
({
if
(
Array
.
isArray
(
responseData
))
{
...
responseData
,
chatResponse
=
chatResponse
.
concat
(
responseData
);
runningTime
:
+
((
time
-
runningTime
)
/
1000
).
toFixed
(
2
)
}
else
{
});
chatResponse
.
push
({
...
responseData
,
runningTime
:
+
((
time
-
runningTime
)
/
1000
).
toFixed
(
2
)
});
}
}
runningTime
=
time
;
runningTime
=
time
;
chatAnswerText
+=
answerText
;
chatAnswerText
+=
answerText
;
}
}
...
@@ -411,7 +417,7 @@ export async function dispatchModules({
...
@@ -411,7 +417,7 @@ export async function dispatchModules({
variables
,
variables
,
moduleName
:
module
.
name
,
moduleName
:
module
.
name
,
outputs
:
module
.
outputs
,
outputs
:
module
.
outputs
,
user
OpenaiAccount
:
user
?.
openaiAccount
,
user
,
inputs
:
params
inputs
:
params
};
};
...
@@ -424,7 +430,8 @@ export async function dispatchModules({
...
@@ -424,7 +430,8 @@ export async function dispatchModules({
[
FlowModuleTypeEnum
.
kbSearchNode
]:
dispatchKBSearch
,
[
FlowModuleTypeEnum
.
kbSearchNode
]:
dispatchKBSearch
,
[
FlowModuleTypeEnum
.
classifyQuestion
]:
dispatchClassifyQuestion
,
[
FlowModuleTypeEnum
.
classifyQuestion
]:
dispatchClassifyQuestion
,
[
FlowModuleTypeEnum
.
contentExtract
]:
dispatchContentExtract
,
[
FlowModuleTypeEnum
.
contentExtract
]:
dispatchContentExtract
,
[
FlowModuleTypeEnum
.
httpRequest
]:
dispatchHttpRequest
[
FlowModuleTypeEnum
.
httpRequest
]:
dispatchHttpRequest
,
[
FlowModuleTypeEnum
.
app
]:
dispatchAppRequest
};
};
if
(
callbackMap
[
module
.
flowType
])
{
if
(
callbackMap
[
module
.
flowType
])
{
return
callbackMap
[
module
.
flowType
](
props
);
return
callbackMap
[
module
.
flowType
](
props
);
...
...
projects/app/src/pages/app/detail/components/AdEdit/components/Nodes/NodeAPP.tsx
0 → 100644
View file @
98ce5103
import
React
from
'react'
;
import
{
NodeProps
}
from
'reactflow'
;
import
NodeCard
from
'../modules/NodeCard'
;
import
{
FlowModuleItemType
}
from
'@/types/core/app/flow'
;
import
Divider
from
'../modules/Divider'
;
import
Container
from
'../modules/Container'
;
import
RenderInput
from
'../render/RenderInput'
;
import
RenderOutput
from
'../render/RenderOutput'
;
const
NodeAPP
=
({
data
}:
NodeProps
<
FlowModuleItemType
>
)
=>
{
const
{
moduleId
,
inputs
,
outputs
}
=
data
;
return
(
<
NodeCard
minW=
{
'350px'
}
{
...
data
}
>
<
Container
borderTop=
{
'2px solid'
}
borderTopColor=
{
'myGray.200'
}
>
<
RenderInput
moduleId=
{
moduleId
}
flowInputList=
{
inputs
}
/>
</
Container
>
<
Divider
text=
"Output"
/>
<
Container
>
<
RenderOutput
moduleId=
{
moduleId
}
flowOutputList=
{
outputs
}
/>
</
Container
>
</
NodeCard
>
);
};
export
default
React
.
memo
(
NodeAPP
);
projects/app/src/pages/app/detail/components/AdEdit/components/Provider.tsx
View file @
98ce5103
...
@@ -35,6 +35,7 @@ const nanoid = customAlphabet('abcdefghijklmnopqrstuvwxyz1234567890', 6);
...
@@ -35,6 +35,7 @@ const nanoid = customAlphabet('abcdefghijklmnopqrstuvwxyz1234567890', 6);
type
OnChange
<
ChangesType
>
=
(
changes
:
ChangesType
[])
=>
void
;
type
OnChange
<
ChangesType
>
=
(
changes
:
ChangesType
[])
=>
void
;
export
type
useFlowStoreType
=
{
export
type
useFlowStoreType
=
{
appId
:
string
;
reactFlowWrapper
:
null
|
React
.
RefObject
<
HTMLDivElement
>
;
reactFlowWrapper
:
null
|
React
.
RefObject
<
HTMLDivElement
>
;
nodes
:
Node
<
FlowModuleItemType
,
string
|
undefined
>
[];
nodes
:
Node
<
FlowModuleItemType
,
string
|
undefined
>
[];
setNodes
:
Dispatch
<
SetStateAction
<
Node
<
FlowModuleItemType
,
string
|
undefined
>
[]
>>
;
setNodes
:
Dispatch
<
SetStateAction
<
Node
<
FlowModuleItemType
,
string
|
undefined
>
[]
>>
;
...
@@ -58,6 +59,7 @@ export type useFlowStoreType = {
...
@@ -58,6 +59,7 @@ export type useFlowStoreType = {
};
};
const
StateContext
=
createContext
<
useFlowStoreType
>
({
const
StateContext
=
createContext
<
useFlowStoreType
>
({
appId
:
''
,
reactFlowWrapper
:
null
,
reactFlowWrapper
:
null
,
nodes
:
[],
nodes
:
[],
setNodes
:
function
(
setNodes
:
function
(
...
@@ -109,7 +111,7 @@ const StateContext = createContext<useFlowStoreType>({
...
@@ -109,7 +111,7 @@ const StateContext = createContext<useFlowStoreType>({
});
});
export
const
useFlowStore
=
()
=>
useContext
(
StateContext
);
export
const
useFlowStore
=
()
=>
useContext
(
StateContext
);
export
const
FlowProvider
=
({
children
}:
{
children
:
React
.
ReactNode
})
=>
{
export
const
FlowProvider
=
({
appId
,
children
}:
{
appId
:
string
;
children
:
React
.
ReactNode
})
=>
{
const
reactFlowWrapper
=
useRef
<
HTMLDivElement
>
(
null
);
const
reactFlowWrapper
=
useRef
<
HTMLDivElement
>
(
null
);
const
{
t
}
=
useTranslation
();
const
{
t
}
=
useTranslation
();
const
{
toast
}
=
useToast
();
const
{
toast
}
=
useToast
();
...
@@ -209,7 +211,6 @@ export const FlowProvider = ({ children }: { children: React.ReactNode }) => {
...
@@ -209,7 +211,6 @@ export const FlowProvider = ({ children }: { children: React.ReactNode }) => {
const
reactFlowBounds
=
reactFlowWrapper
.
current
.
getBoundingClientRect
();
const
reactFlowBounds
=
reactFlowWrapper
.
current
.
getBoundingClientRect
();
const
mouseX
=
(
position
.
x
-
reactFlowBounds
.
left
-
x
)
/
zoom
-
100
;
const
mouseX
=
(
position
.
x
-
reactFlowBounds
.
left
-
x
)
/
zoom
-
100
;
const
mouseY
=
(
position
.
y
-
reactFlowBounds
.
top
-
y
)
/
zoom
;
const
mouseY
=
(
position
.
y
-
reactFlowBounds
.
top
-
y
)
/
zoom
;
console
.
log
(
template
);
setNodes
((
state
)
=>
setNodes
((
state
)
=>
state
.
concat
(
state
.
concat
(
appModule2FlowNode
({
appModule2FlowNode
({
...
@@ -328,6 +329,7 @@ export const FlowProvider = ({ children }: { children: React.ReactNode }) => {
...
@@ -328,6 +329,7 @@ export const FlowProvider = ({ children }: { children: React.ReactNode }) => {
);
);
const
value
=
{
const
value
=
{
appId
,
reactFlowWrapper
,
reactFlowWrapper
,
nodes
,
nodes
,
setNodes
,
setNodes
,
...
...
projects/app/src/pages/app/detail/components/AdEdit/components/render/RenderInput.tsx
View file @
98ce5103
import
React
,
{
useState
}
from
'react'
;
import
React
,
{
useState
}
from
'react'
;
import
type
{
FlowInputItemType
}
from
'@/types/core/app/flow'
;
import
type
{
FlowInputItemType
,
SelectAppItemType
}
from
'@/types/core/app/flow'
;
import
{
import
{
Box
,
Box
,
Textarea
,
Textarea
,
...
@@ -9,7 +9,10 @@ import {
...
@@ -9,7 +9,10 @@ import {
NumberInputStepper
,
NumberInputStepper
,
NumberIncrementStepper
,
NumberIncrementStepper
,
NumberDecrementStepper
,
NumberDecrementStepper
,
Flex
Flex
,
useDisclosure
,
Button
,
useTheme
}
from
'@chakra-ui/react'
;
}
from
'@chakra-ui/react'
;
import
{
FlowInputItemTypeEnum
}
from
'@/constants/flow'
;
import
{
FlowInputItemTypeEnum
}
from
'@/constants/flow'
;
import
{
QuestionOutlineIcon
}
from
'@chakra-ui/icons'
;
import
{
QuestionOutlineIcon
}
from
'@chakra-ui/icons'
;
...
@@ -20,7 +23,9 @@ import MyTooltip from '@/components/MyTooltip';
...
@@ -20,7 +23,9 @@ import MyTooltip from '@/components/MyTooltip';
import
TargetHandle
from
'./TargetHandle'
;
import
TargetHandle
from
'./TargetHandle'
;
import
MyIcon
from
'@/components/Icon'
;
import
MyIcon
from
'@/components/Icon'
;
const
SetInputFieldModal
=
dynamic
(()
=>
import
(
'../modules/SetInputFieldModal'
));
const
SetInputFieldModal
=
dynamic
(()
=>
import
(
'../modules/SetInputFieldModal'
));
const
SelectAppModal
=
dynamic
(()
=>
import
(
'../../../SelectAppModal'
));
import
{
useFlowStore
}
from
'../Provider'
;
import
{
useFlowStore
}
from
'../Provider'
;
import
Avatar
from
'@/components/Avatar'
;
export
const
Label
=
({
export
const
Label
=
({
moduleId
,
moduleId
,
...
@@ -141,6 +146,7 @@ const RenderInput = ({
...
@@ -141,6 +146,7 @@ const RenderInput = ({
CustomComponent
?:
Record
<
string
,
(
e
:
FlowInputItemType
)
=>
React
.
ReactNode
>
;
CustomComponent
?:
Record
<
string
,
(
e
:
FlowInputItemType
)
=>
React
.
ReactNode
>
;
})
=>
{
})
=>
{
const
{
onChangeNode
}
=
useFlowStore
();
const
{
onChangeNode
}
=
useFlowStore
();
return
(
return
(
<>
<>
{
flowInputList
.
map
(
{
flowInputList
.
map
(
...
@@ -253,6 +259,9 @@ const RenderInput = ({
...
@@ -253,6 +259,9 @@ const RenderInput = ({
{
item
.
type
===
FlowInputItemTypeEnum
.
custom
&&
CustomComponent
[
item
.
key
]
&&
(
{
item
.
type
===
FlowInputItemTypeEnum
.
custom
&&
CustomComponent
[
item
.
key
]
&&
(
<>
{
CustomComponent
[
item
.
key
]({
...
item
})
}
</>
<>
{
CustomComponent
[
item
.
key
]({
...
item
})
}
</>
)
}
)
}
{
item
.
type
===
FlowInputItemTypeEnum
.
selectApp
&&
(
<
RenderSelectApp
app=
{
item
}
moduleId=
{
moduleId
}
/>
)
}
</
Box
>
</
Box
>
</
Box
>
</
Box
>
)
)
...
@@ -262,3 +271,54 @@ const RenderInput = ({
...
@@ -262,3 +271,54 @@ const RenderInput = ({
};
};
export
default
React
.
memo
(
RenderInput
);
export
default
React
.
memo
(
RenderInput
);
function
RenderSelectApp
({
app
,
moduleId
}:
{
app
:
FlowInputItemType
;
moduleId
:
string
})
{
const
{
onChangeNode
,
appId
}
=
useFlowStore
();
const
theme
=
useTheme
();
const
{
isOpen
:
isOpenSelectApp
,
onOpen
:
onOpenSelectApp
,
onClose
:
onCloseSelectApp
}
=
useDisclosure
();
const
value
=
app
.
value
as
SelectAppItemType
|
undefined
;
return
(
<>
<
Box
onClick=
{
onOpenSelectApp
}
>
{
!
value
?
(
<
Button
variant=
{
'base'
}
w=
{
'100%'
}
>
选择应用
</
Button
>
)
:
(
<
Flex
alignItems=
{
'center'
}
border=
{
theme
.
borders
.
base
}
borderRadius=
{
'md'
}
px=
{
3
}
py=
{
2
}
>
<
Avatar
src=
{
value
?.
logo
}
/>
<
Box
fontWeight=
{
'bold'
}
ml=
{
1
}
>
{
value
?.
name
}
</
Box
>
</
Flex
>
)
}
</
Box
>
{
isOpenSelectApp
&&
(
<
SelectAppModal
defaultApps=
{
app
.
value
?.
id
?
[
app
.
value
.
id
]
:
[]
}
filterApps=
{
[
appId
]
}
onClose=
{
onCloseSelectApp
}
onSuccess=
{
(
e
)
=>
{
onChangeNode
({
moduleId
,
type
:
'inputs'
,
key
:
'app'
,
value
:
{
...
app
,
value
:
e
[
0
]
}
});
}
}
/>
)
}
</>
);
}
projects/app/src/pages/app/detail/components/AdEdit/index.tsx
View file @
98ce5103
...
@@ -38,6 +38,7 @@ const NodeVariable = dynamic(() => import('./components/Nodes/NodeVariable'));
...
@@ -38,6 +38,7 @@ const NodeVariable = dynamic(() => import('./components/Nodes/NodeVariable'));
const
NodeUserGuide
=
dynamic
(()
=>
import
(
'./components/Nodes/NodeUserGuide'
));
const
NodeUserGuide
=
dynamic
(()
=>
import
(
'./components/Nodes/NodeUserGuide'
));
const
NodeExtract
=
dynamic
(()
=>
import
(
'./components/Nodes/NodeExtract'
));
const
NodeExtract
=
dynamic
(()
=>
import
(
'./components/Nodes/NodeExtract'
));
const
NodeHttp
=
dynamic
(()
=>
import
(
'./components/Nodes/NodeHttp'
));
const
NodeHttp
=
dynamic
(()
=>
import
(
'./components/Nodes/NodeHttp'
));
const
NodeAPP
=
dynamic
(()
=>
import
(
'./components/Nodes/NodeAPP'
));
import
'reactflow/dist/style.css'
;
import
'reactflow/dist/style.css'
;
...
@@ -52,7 +53,8 @@ const nodeTypes = {
...
@@ -52,7 +53,8 @@ const nodeTypes = {
[
FlowModuleTypeEnum
.
answerNode
]:
NodeAnswer
,
[
FlowModuleTypeEnum
.
answerNode
]:
NodeAnswer
,
[
FlowModuleTypeEnum
.
classifyQuestion
]:
NodeCQNode
,
[
FlowModuleTypeEnum
.
classifyQuestion
]:
NodeCQNode
,
[
FlowModuleTypeEnum
.
contentExtract
]:
NodeExtract
,
[
FlowModuleTypeEnum
.
contentExtract
]:
NodeExtract
,
[
FlowModuleTypeEnum
.
httpRequest
]:
NodeHttp
[
FlowModuleTypeEnum
.
httpRequest
]:
NodeHttp
,
[
FlowModuleTypeEnum
.
app
]:
NodeAPP
// [FlowModuleTypeEnum.empty]: EmptyModule
// [FlowModuleTypeEnum.empty]: EmptyModule
};
};
const
edgeTypes
=
{
const
edgeTypes
=
{
...
@@ -116,8 +118,17 @@ function FlowHeader({ app, onCloseSettings }: Props & {}) {
...
@@ -116,8 +118,17 @@ function FlowHeader({ app, onCloseSettings }: Props & {}) {
const
{
mutate
:
onclickSave
,
isLoading
}
=
useRequest
({
const
{
mutate
:
onclickSave
,
isLoading
}
=
useRequest
({
mutationFn
:
()
=>
{
mutationFn
:
()
=>
{
const
modules
=
flow2AppModules
();
// check required connect
for
(
let
i
=
0
;
i
<
modules
.
length
;
i
++
)
{
const
item
=
modules
[
i
];
if
(
item
.
inputs
.
find
((
input
)
=>
input
.
required
&&
!
input
.
connected
))
{
return
Promise
.
reject
(
`【
${
item
.
name
}
】存在未连接的必填输入`
);
}
}
return
updateAppDetail
(
app
.
_id
,
{
return
updateAppDetail
(
app
.
_id
,
{
modules
:
flow2AppModules
()
,
modules
:
modules
,
type
:
AppTypeEnum
.
advanced
type
:
AppTypeEnum
.
advanced
});
});
},
},
...
@@ -314,7 +325,7 @@ const Flow = (data: Props) => {
...
@@ -314,7 +325,7 @@ const Flow = (data: Props) => {
return
(
return
(
<
Box
h=
{
'100%'
}
position=
{
'fixed'
}
zIndex=
{
999
}
top=
{
0
}
left=
{
0
}
right=
{
0
}
bottom=
{
0
}
>
<
Box
h=
{
'100%'
}
position=
{
'fixed'
}
zIndex=
{
999
}
top=
{
0
}
left=
{
0
}
right=
{
0
}
bottom=
{
0
}
>
<
ReactFlowProvider
>
<
ReactFlowProvider
>
<
FlowProvider
>
<
FlowProvider
appId=
{
data
?.
app
?.
_id
}
>
<
Flex
h=
{
'100%'
}
flexDirection=
{
'column'
}
bg=
{
'#fff'
}
>
<
Flex
h=
{
'100%'
}
flexDirection=
{
'column'
}
bg=
{
'#fff'
}
>
{
!!
data
.
app
.
_id
&&
<
AppEdit
{
...
data
}
/>
}
{
!!
data
.
app
.
_id
&&
<
AppEdit
{
...
data
}
/>
}
</
Flex
>
</
Flex
>
...
...
projects/app/src/pages/app/detail/components/DatasetSelectModal.tsx
View file @
98ce5103
...
@@ -69,7 +69,12 @@ export const DatasetSelectModal = ({
...
@@ -69,7 +69,12 @@ export const DatasetSelectModal = ({
tips=
{
'仅能选择同一个索引模型的知识库'
}
tips=
{
'仅能选择同一个索引模型的知识库'
}
onClose=
{
onClose
}
onClose=
{
onClose
}
>
>
<
ModalBody
flex=
{
[
'1 0 0'
,
'0 0 auto'
]
}
maxH=
{
'80vh'
}
overflowY=
{
'auto'
}
userSelect=
{
'none'
}
>
<
ModalBody
flex=
{
[
'1 0 0'
,
'1 0 auto'
]
}
maxH=
{
'80vh'
}
overflowY=
{
[
'auto'
,
'unset'
]
}
userSelect=
{
'none'
}
>
<
Grid
gridTemplateColumns=
{
[
'repeat(1,1fr)'
,
'repeat(2,1fr)'
,
'repeat(3,1fr)'
]
}
gridGap=
{
3
}
>
<
Grid
gridTemplateColumns=
{
[
'repeat(1,1fr)'
,
'repeat(2,1fr)'
,
'repeat(3,1fr)'
]
}
gridGap=
{
3
}
>
{
filterKbList
.
selected
.
map
((
item
)
=>
{
filterKbList
.
selected
.
map
((
item
)
=>
(()
=>
{
(()
=>
{
...
...
projects/app/src/pages/app/detail/components/Logs.tsx
View file @
98ce5103
...
@@ -287,7 +287,6 @@ function DetailLogsModal({
...
@@ -287,7 +287,6 @@ function DetailLogsModal({
<
Box
pt=
{
2
}
flex=
{
'1 0 0'
}
>
<
Box
pt=
{
2
}
flex=
{
'1 0 0'
}
>
<
ChatBox
<
ChatBox
ref=
{
ChatBoxRef
}
ref=
{
ChatBoxRef
}
chatId=
{
chatId
}
appAvatar=
{
chat
?.
app
.
avatar
}
appAvatar=
{
chat
?.
app
.
avatar
}
userAvatar=
{
HUMAN_ICON
}
userAvatar=
{
HUMAN_ICON
}
feedbackType=
{
'admin'
}
feedbackType=
{
'admin'
}
...
...
projects/app/src/pages/app/detail/components/SelectAppModal.tsx
0 → 100644
View file @
98ce5103
import
React
,
{
useMemo
}
from
'react'
;
import
{
ModalBody
,
Flex
,
Box
,
useTheme
,
ModalFooter
,
Button
}
from
'@chakra-ui/react'
;
import
MyModal
from
'@/components/MyModal'
;
import
{
getMyModels
}
from
'@/api/app'
;
import
{
useQuery
}
from
'@tanstack/react-query'
;
import
type
{
SelectAppItemType
}
from
'@/types/core/app/flow'
;
import
Avatar
from
'@/components/Avatar'
;
import
{
useTranslation
}
from
'react-i18next'
;
import
{
useLoading
}
from
'@/hooks/useLoading'
;
const
SelectAppModal
=
({
defaultApps
=
[],
filterApps
=
[],
max
=
1
,
onClose
,
onSuccess
}:
{
defaultApps
:
string
[];
filterApps
?:
string
[];
max
?:
number
;
onClose
:
()
=>
void
;
onSuccess
:
(
e
:
SelectAppItemType
[])
=>
void
;
})
=>
{
const
{
t
}
=
useTranslation
();
const
{
Loading
}
=
useLoading
();
const
theme
=
useTheme
();
const
[
selectedApps
,
setSelectedApps
]
=
React
.
useState
<
string
[]
>
(
defaultApps
);
/* 加载模型 */
const
{
data
=
[],
isLoading
}
=
useQuery
([
'loadMyApos'
],
()
=>
getMyModels
());
const
apps
=
useMemo
(
()
=>
data
.
filter
((
app
)
=>
!
filterApps
.
includes
(
app
.
_id
)),
[
data
,
filterApps
]
);
return
(
<
MyModal
isOpen
title=
{
`选择应用${max > 1 ? `
(
$
{
selectedApps
.
length
}
/${max}
)
` : ''}`
}
onClose=
{
onClose
}
w=
{
'700px'
}
position=
{
'relative'
}
>
<
ModalBody
minH=
{
'300px'
}
display=
{
'grid'
}
gridTemplateColumns=
{
[
'1fr'
,
'repeat(3,1fr)'
]
}
gridGap=
{
4
}
>
{
apps
.
map
((
app
)
=>
(
<
Flex
key=
{
app
.
_id
}
alignItems=
{
'center'
}
border=
{
theme
.
borders
.
base
}
borderRadius=
{
'md'
}
px=
{
1
}
py=
{
2
}
cursor=
{
'pointer'
}
{
...
(
selectedApps
.
includes
(
app
.
_id
)
?
{
bg
:
'
myBlue
.
200',
onClick
:
()
=
>
{
setSelectedApps
(
selectedApps
.
filter
((
e
)
=>
e
!==
app
.
_id
));
}
}
:
{
onClick
:
()
=>
{
if
(
max
===
1
)
{
setSelectedApps
([
app
.
_id
]);
}
else
if
(
selectedApps
.
length
<
max
)
{
setSelectedApps
([...
selectedApps
,
app
.
_id
]);
}
}
}
)}
>
<
Avatar
src=
{
app
.
avatar
}
w=
{
[
'16px'
,
'22px'
]
}
/>
<
Box
fontWeight=
{
'bold'
}
ml=
{
1
}
>
{
app
.
name
}
</
Box
>
</
Flex
>
))
}
</
ModalBody
>
<
ModalFooter
>
<
Button
variant=
{
'base'
}
onClick=
{
onClose
}
>
{
t
(
'Cancel'
)
}
</
Button
>
<
Button
ml=
{
2
}
onClick=
{
()
=>
{
onSuccess
(
apps
.
filter
((
app
)
=>
selectedApps
.
includes
(
app
.
_id
))
.
map
((
app
)
=>
({
id
:
app
.
_id
,
name
:
app
.
name
,
logo
:
app
.
avatar
}))
);
onClose
();
}
}
>
{
t
(
'Confirm'
)
}
</
Button
>
</
ModalFooter
>
<
Loading
loading=
{
isLoading
}
fixed=
{
false
}
/>
</
MyModal
>
);
};
export
default
React
.
memo
(
SelectAppModal
);
projects/app/src/pages/app/list/index.tsx
View file @
98ce5103
...
@@ -64,7 +64,7 @@ const MyApps = () => {
...
@@ -64,7 +64,7 @@ const MyApps = () => {
);
);
/* 加载模型 */
/* 加载模型 */
useQuery
([
'load
Model
s'
],
()
=>
loadMyApps
(
true
),
{
useQuery
([
'load
App
s'
],
()
=>
loadMyApps
(
true
),
{
refetchOnMount
:
true
refetchOnMount
:
true
});
});
...
...
projects/app/src/pages/chat/components/ToolMenu.tsx
View file @
98ce5103
...
@@ -8,7 +8,6 @@ import { useRouter } from 'next/router';
...
@@ -8,7 +8,6 @@ import { useRouter } from 'next/router';
const
ToolMenu
=
({
history
}:
{
history
:
ChatItemType
[]
})
=>
{
const
ToolMenu
=
({
history
}:
{
history
:
ChatItemType
[]
})
=>
{
const
{
onExportChat
}
=
useChatBox
();
const
{
onExportChat
}
=
useChatBox
();
const
router
=
useRouter
();
const
router
=
useRouter
();
const
{
appId
,
shareId
}
=
router
.
query
;
const
menuList
=
useMemo
(
const
menuList
=
useMemo
(
()
=>
[
()
=>
[
...
@@ -18,8 +17,8 @@ const ToolMenu = ({ history }: { history: ChatItemType[] }) => {
...
@@ -18,8 +17,8 @@ const ToolMenu = ({ history }: { history: ChatItemType[] }) => {
onClick
:
()
=>
{
onClick
:
()
=>
{
router
.
replace
({
router
.
replace
({
query
:
{
query
:
{
appId
,
...
router
.
query
,
shareId
chatId
:
''
}
}
});
});
}
}
...
@@ -36,7 +35,7 @@ const ToolMenu = ({ history }: { history: ChatItemType[] }) => {
...
@@ -36,7 +35,7 @@ const ToolMenu = ({ history }: { history: ChatItemType[] }) => {
},
},
{
icon
:
'pdf'
,
label
:
'PDF导出'
,
onClick
:
()
=>
onExportChat
({
type
:
'pdf'
,
history
})
}
{
icon
:
'pdf'
,
label
:
'PDF导出'
,
onClick
:
()
=>
onExportChat
({
type
:
'pdf'
,
history
})
}
],
],
[
appId
,
history
,
onExportChat
,
router
,
shareId
]
[
history
,
onExportChat
,
router
]
);
);
return
history
.
length
>
0
?
(
return
history
.
length
>
0
?
(
...
...
projects/app/src/pages/chat/index.tsx
View file @
98ce5103
...
@@ -358,7 +358,6 @@ const Chat = ({ appId, chatId }: { appId: string; chatId: string }) => {
...
@@ -358,7 +358,6 @@ const Chat = ({ appId, chatId }: { appId: string; chatId: string }) => {
<
ChatBox
<
ChatBox
ref=
{
ChatBoxRef
}
ref=
{
ChatBoxRef
}
showEmptyIntro
showEmptyIntro
chatId=
{
chatId
}
appAvatar=
{
chatData
.
app
.
avatar
}
appAvatar=
{
chatData
.
app
.
avatar
}
userAvatar=
{
userInfo
?.
avatar
}
userAvatar=
{
userInfo
?.
avatar
}
userGuideModule=
{
chatData
.
app
?.
userGuideModule
}
userGuideModule=
{
chatData
.
app
?.
userGuideModule
}
...
...
projects/app/src/pages/chat/share.tsx
View file @
98ce5103
...
@@ -24,10 +24,12 @@ import { serviceSideProps } from '@/utils/web/i18n';
...
@@ -24,10 +24,12 @@ import { serviceSideProps } from '@/utils/web/i18n';
const
OutLink
=
({
const
OutLink
=
({
shareId
,
shareId
,
chatId
,
chatId
,
showHistory
,
authToken
authToken
}:
{
}:
{
shareId
:
string
;
shareId
:
string
;
chatId
:
string
;
chatId
:
string
;
showHistory
:
'0'
|
'1'
;
authToken
?:
string
;
authToken
?:
string
;
})
=>
{
})
=>
{
const
router
=
useRouter
();
const
router
=
useRouter
();
...
@@ -89,9 +91,8 @@ const OutLink = ({
...
@@ -89,9 +91,8 @@ const OutLink = ({
forbidRefresh
.
current
=
true
;
forbidRefresh
.
current
=
true
;
router
.
replace
({
router
.
replace
({
query
:
{
query
:
{
shareId
,
...
router
.
query
,
chatId
:
completionChatId
,
chatId
:
completionChatId
authToken
}
}
});
});
}
}
...
@@ -174,59 +175,58 @@ const OutLink = ({
...
@@ -174,59 +175,58 @@ const OutLink = ({
<
title
>
{
shareChatData
.
app
.
name
}
</
title
>
<
title
>
{
shareChatData
.
app
.
name
}
</
title
>
</
Head
>
</
Head
>
<
Flex
h=
{
'100%'
}
flexDirection=
{
[
'column'
,
'row'
]
}
>
<
Flex
h=
{
'100%'
}
flexDirection=
{
[
'column'
,
'row'
]
}
>
{
((
children
:
React
.
ReactNode
)
=>
{
{
showHistory
===
'1'
return
isPc
?
(
?
((
children
:
React
.
ReactNode
)
=>
{
<
SideBar
>
{
children
}
</
SideBar
>
return
isPc
?
(
)
:
(
<
SideBar
>
{
children
}
</
SideBar
>
<
Drawer
)
:
(
isOpen=
{
isOpenSlider
}
<
Drawer
placement=
"left"
isOpen=
{
isOpenSlider
}
autoFocus=
{
false
}
placement=
"left"
size=
{
'xs'
}
autoFocus=
{
false
}
onClose=
{
onCloseSlider
}
size=
{
'xs'
}
>
onClose=
{
onCloseSlider
}
<
DrawerOverlay
backgroundColor=
{
'rgba(255,255,255,0.5)'
}
/>
>
<
DrawerContent
maxWidth=
{
'250px'
}
boxShadow=
{
'2px 0 10px rgba(0,0,0,0.15)'
}
>
<
DrawerOverlay
backgroundColor=
{
'rgba(255,255,255,0.5)'
}
/>
{
children
}
<
DrawerContent
maxWidth=
{
'250px'
}
boxShadow=
{
'2px 0 10px rgba(0,0,0,0.15)'
}
>
</
DrawerContent
>
{
children
}
</
Drawer
>
</
DrawerContent
>
);
</
Drawer
>
})(
);
<
ChatHistorySlider
})(
appName=
{
shareChatData
.
app
.
name
}
<
ChatHistorySlider
appAvatar=
{
shareChatData
.
app
.
avatar
}
appName=
{
shareChatData
.
app
.
name
}
activeChatId=
{
chatId
}
appAvatar=
{
shareChatData
.
app
.
avatar
}
history=
{
history
.
map
((
item
)
=>
({
activeChatId=
{
chatId
}
id
:
item
.
chatId
,
history=
{
history
.
map
((
item
)
=>
({
title
:
item
.
title
id
:
item
.
chatId
,
}))
}
title
:
item
.
title
onClose=
{
onCloseSlider
}
}))
}
onChangeChat=
{
(
chatId
)
=>
{
onClose=
{
onCloseSlider
}
console
.
log
(
chatId
);
onChangeChat=
{
(
chatId
)
=>
{
router
.
replace
({
router
.
replace
({
query
:
{
query
:
{
...
router
.
query
,
chatId
:
chatId
||
''
,
chatId
:
chatId
||
''
shareId
,
}
authToken
});
}
if
(
!
isPc
)
{
});
onCloseSlider
();
if
(
!
isPc
)
{
}
onCloseSlider
();
}
}
}
onDelHistory=
{
delOneShareHistoryByChatId
}
}
}
onClearHistory=
{
()
=>
{
onDelHistory=
{
delOneShareHistoryByChatId
}
delManyShareChatHistoryByShareId
(
shareId
);
onClearHistory=
{
()
=>
{
router
.
replace
({
delManyShareChatHistoryByShareId
(
shareId
);
query
:
{
router
.
replace
({
...
router
.
query
,
query
:
{
chatId
:
''
shareId
,
}
authToken
});
}
}
}
});
/>
}
}
)
/>
:
null
}
)
}
{
/* chat container */
}
{
/* chat container */
}
<
Flex
<
Flex
...
@@ -276,10 +276,11 @@ const OutLink = ({
...
@@ -276,10 +276,11 @@ const OutLink = ({
export
async
function
getServerSideProps
(
context
:
any
)
{
export
async
function
getServerSideProps
(
context
:
any
)
{
const
shareId
=
context
?.
query
?.
shareId
||
''
;
const
shareId
=
context
?.
query
?.
shareId
||
''
;
const
chatId
=
context
?.
query
?.
chatId
||
''
;
const
chatId
=
context
?.
query
?.
chatId
||
''
;
const
showHistory
=
context
?.
query
?.
showHistory
||
'1'
;
const
authToken
=
context
?.
query
?.
authToken
||
''
;
const
authToken
=
context
?.
query
?.
authToken
||
''
;
return
{
return
{
props
:
{
shareId
,
chatId
,
authToken
,
...(
await
serviceSideProps
(
context
))
}
props
:
{
shareId
,
chatId
,
showHistory
,
authToken
,
...(
await
serviceSideProps
(
context
))
}
};
};
}
}
...
...
projects/app/src/service/events/generateQA.ts
View file @
98ce5103
...
@@ -4,8 +4,8 @@ import { TrainingModeEnum } from '@/constants/plugin';
...
@@ -4,8 +4,8 @@ import { TrainingModeEnum } from '@/constants/plugin';
import
{
ERROR_ENUM
}
from
'../errorCode'
;
import
{
ERROR_ENUM
}
from
'../errorCode'
;
import
{
sendInform
}
from
'@/pages/api/user/inform/send'
;
import
{
sendInform
}
from
'@/pages/api/user/inform/send'
;
import
{
authBalanceByUid
}
from
'../utils/auth'
;
import
{
authBalanceByUid
}
from
'../utils/auth'
;
import
{
axiosConfig
,
getAIChatApi
}
from
'@fastgpt/core/ai
Api
/config'
;
import
{
axiosConfig
,
getAIChatApi
}
from
'@fastgpt/core/ai/config'
;
import
type
{
ChatCompletionRequestMessage
}
from
'@fastgpt/core/ai
Api
/type'
;
import
type
{
ChatCompletionRequestMessage
}
from
'@fastgpt/core/ai/type'
;
import
{
addLog
}
from
'../utils/tools'
;
import
{
addLog
}
from
'../utils/tools'
;
import
{
splitText2Chunks
}
from
'@/utils/file'
;
import
{
splitText2Chunks
}
from
'@/utils/file'
;
import
{
replaceVariable
}
from
'@/utils/common/tools/text'
;
import
{
replaceVariable
}
from
'@/utils/common/tools/text'
;
...
...
projects/app/src/service/moduleDispatch/agent/classifyQuestion.ts
View file @
98ce5103
...
@@ -2,7 +2,7 @@ import { adaptChat2GptMessages } from '@/utils/common/adapt/message';
...
@@ -2,7 +2,7 @@ import { adaptChat2GptMessages } from '@/utils/common/adapt/message';
import
{
ChatContextFilter
}
from
'@/service/common/tiktoken'
;
import
{
ChatContextFilter
}
from
'@/service/common/tiktoken'
;
import
type
{
ChatHistoryItemResType
,
ChatItemType
}
from
'@/types/chat'
;
import
type
{
ChatHistoryItemResType
,
ChatItemType
}
from
'@/types/chat'
;
import
{
ChatRoleEnum
,
TaskResponseKeyEnum
}
from
'@/constants/chat'
;
import
{
ChatRoleEnum
,
TaskResponseKeyEnum
}
from
'@/constants/chat'
;
import
{
getAIChatApi
,
axiosConfig
}
from
'@fastgpt/core/ai
Api
/config'
;
import
{
getAIChatApi
,
axiosConfig
}
from
'@fastgpt/core/ai/config'
;
import
type
{
ClassifyQuestionAgentItemType
}
from
'@/types/app'
;
import
type
{
ClassifyQuestionAgentItemType
}
from
'@/types/app'
;
import
{
SystemInputEnum
}
from
'@/constants/app'
;
import
{
SystemInputEnum
}
from
'@/constants/app'
;
import
{
SpecialInputKeyEnum
}
from
'@/constants/flow'
;
import
{
SpecialInputKeyEnum
}
from
'@/constants/flow'
;
...
@@ -29,7 +29,7 @@ const agentFunName = 'agent_user_question';
...
@@ -29,7 +29,7 @@ const agentFunName = 'agent_user_question';
export
const
dispatchClassifyQuestion
=
async
(
props
:
Props
):
Promise
<
CQResponse
>
=>
{
export
const
dispatchClassifyQuestion
=
async
(
props
:
Props
):
Promise
<
CQResponse
>
=>
{
const
{
const
{
moduleName
,
moduleName
,
user
OpenaiAccount
,
user
,
inputs
:
{
agents
,
userChatInput
}
inputs
:
{
agents
,
userChatInput
}
}
=
props
as
Props
;
}
=
props
as
Props
;
...
@@ -53,7 +53,7 @@ export const dispatchClassifyQuestion = async (props: Props): Promise<CQResponse
...
@@ -53,7 +53,7 @@ export const dispatchClassifyQuestion = async (props: Props): Promise<CQResponse
[
TaskResponseKeyEnum
.
responseData
]:
{
[
TaskResponseKeyEnum
.
responseData
]:
{
moduleType
:
FlowModuleTypeEnum
.
classifyQuestion
,
moduleType
:
FlowModuleTypeEnum
.
classifyQuestion
,
moduleName
,
moduleName
,
price
:
user
O
penaiAccount
?.
key
?
0
:
cqModel
.
price
*
tokens
,
price
:
user
.
o
penaiAccount
?.
key
?
0
:
cqModel
.
price
*
tokens
,
model
:
cqModel
.
name
||
''
,
model
:
cqModel
.
name
||
''
,
tokens
,
tokens
,
cqList
:
agents
,
cqList
:
agents
,
...
@@ -63,7 +63,7 @@ export const dispatchClassifyQuestion = async (props: Props): Promise<CQResponse
...
@@ -63,7 +63,7 @@ export const dispatchClassifyQuestion = async (props: Props): Promise<CQResponse
};
};
async
function
functionCall
({
async
function
functionCall
({
user
OpenaiAccount
,
user
,
inputs
:
{
agents
,
systemPrompt
,
history
=
[],
userChatInput
}
inputs
:
{
agents
,
systemPrompt
,
history
=
[],
userChatInput
}
}:
Props
)
{
}:
Props
)
{
const
cqModel
=
global
.
cqModel
;
const
cqModel
=
global
.
cqModel
;
...
@@ -105,7 +105,7 @@ async function functionCall({
...
@@ -105,7 +105,7 @@ async function functionCall({
required
:
[
'type'
]
required
:
[
'type'
]
}
}
};
};
const
chatAPI
=
getAIChatApi
(
user
O
penaiAccount
);
const
chatAPI
=
getAIChatApi
(
user
.
o
penaiAccount
);
const
response
=
await
chatAPI
.
createChatCompletion
(
const
response
=
await
chatAPI
.
createChatCompletion
(
{
{
...
@@ -116,7 +116,7 @@ async function functionCall({
...
@@ -116,7 +116,7 @@ async function functionCall({
functions
:
[
agentFunction
]
functions
:
[
agentFunction
]
},
},
{
{
...
axiosConfig
(
user
O
penaiAccount
)
...
axiosConfig
(
user
.
o
penaiAccount
)
}
}
);
);
...
@@ -138,7 +138,7 @@ async function functionCall({
...
@@ -138,7 +138,7 @@ async function functionCall({
}
}
async
function
completions
({
async
function
completions
({
user
OpenaiAccount
,
user
,
inputs
:
{
agents
,
systemPrompt
=
''
,
history
=
[],
userChatInput
}
inputs
:
{
agents
,
systemPrompt
=
''
,
history
=
[],
userChatInput
}
}:
Props
)
{
}:
Props
)
{
const
extractModel
=
global
.
extractModel
;
const
extractModel
=
global
.
extractModel
;
...
@@ -155,7 +155,7 @@ Human:${userChatInput}`
...
@@ -155,7 +155,7 @@ Human:${userChatInput}`
}
}
];
];
const
chatAPI
=
getAIChatApi
(
user
O
penaiAccount
);
const
chatAPI
=
getAIChatApi
(
user
.
o
penaiAccount
);
const
{
data
}
=
await
chatAPI
.
createChatCompletion
(
const
{
data
}
=
await
chatAPI
.
createChatCompletion
(
{
{
...
@@ -166,7 +166,7 @@ Human:${userChatInput}`
...
@@ -166,7 +166,7 @@ Human:${userChatInput}`
},
},
{
{
timeout
:
480000
,
timeout
:
480000
,
...
axiosConfig
(
user
O
penaiAccount
)
...
axiosConfig
(
user
.
o
penaiAccount
)
}
}
);
);
const
answer
=
data
.
choices
?.[
0
].
message
?.
content
||
''
;
const
answer
=
data
.
choices
?.[
0
].
message
?.
content
||
''
;
...
...
projects/app/src/service/moduleDispatch/agent/extract.ts
View file @
98ce5103
...
@@ -2,7 +2,7 @@ import { adaptChat2GptMessages } from '@/utils/common/adapt/message';
...
@@ -2,7 +2,7 @@ import { adaptChat2GptMessages } from '@/utils/common/adapt/message';
import
{
ChatContextFilter
}
from
'@/service/common/tiktoken'
;
import
{
ChatContextFilter
}
from
'@/service/common/tiktoken'
;
import
type
{
ChatHistoryItemResType
,
ChatItemType
}
from
'@/types/chat'
;
import
type
{
ChatHistoryItemResType
,
ChatItemType
}
from
'@/types/chat'
;
import
{
ChatRoleEnum
,
TaskResponseKeyEnum
}
from
'@/constants/chat'
;
import
{
ChatRoleEnum
,
TaskResponseKeyEnum
}
from
'@/constants/chat'
;
import
{
getAIChatApi
,
axiosConfig
}
from
'@fastgpt/core/ai
Api
/config'
;
import
{
getAIChatApi
,
axiosConfig
}
from
'@fastgpt/core/ai/config'
;
import
type
{
ContextExtractAgentItemType
}
from
'@/types/app'
;
import
type
{
ContextExtractAgentItemType
}
from
'@/types/app'
;
import
{
ContextExtractEnum
}
from
'@/constants/flow/flowField'
;
import
{
ContextExtractEnum
}
from
'@/constants/flow/flowField'
;
import
{
FlowModuleTypeEnum
}
from
'@/constants/flow'
;
import
{
FlowModuleTypeEnum
}
from
'@/constants/flow'
;
...
@@ -29,7 +29,7 @@ const agentFunName = 'agent_extract_data';
...
@@ -29,7 +29,7 @@ const agentFunName = 'agent_extract_data';
export
async
function
dispatchContentExtract
(
props
:
Props
):
Promise
<
Response
>
{
export
async
function
dispatchContentExtract
(
props
:
Props
):
Promise
<
Response
>
{
const
{
const
{
moduleName
,
moduleName
,
user
OpenaiAccount
,
user
,
inputs
:
{
content
,
description
,
extractKeys
}
inputs
:
{
content
,
description
,
extractKeys
}
}
=
props
;
}
=
props
;
...
@@ -73,7 +73,7 @@ export async function dispatchContentExtract(props: Props): Promise<Response> {
...
@@ -73,7 +73,7 @@ export async function dispatchContentExtract(props: Props): Promise<Response> {
[
TaskResponseKeyEnum
.
responseData
]:
{
[
TaskResponseKeyEnum
.
responseData
]:
{
moduleType
:
FlowModuleTypeEnum
.
contentExtract
,
moduleType
:
FlowModuleTypeEnum
.
contentExtract
,
moduleName
,
moduleName
,
price
:
user
O
penaiAccount
?.
key
?
0
:
extractModel
.
price
*
tokens
,
price
:
user
.
o
penaiAccount
?.
key
?
0
:
extractModel
.
price
*
tokens
,
model
:
extractModel
.
name
||
''
,
model
:
extractModel
.
name
||
''
,
tokens
,
tokens
,
extractDescription
:
description
,
extractDescription
:
description
,
...
@@ -83,7 +83,7 @@ export async function dispatchContentExtract(props: Props): Promise<Response> {
...
@@ -83,7 +83,7 @@ export async function dispatchContentExtract(props: Props): Promise<Response> {
}
}
async
function
functionCall
({
async
function
functionCall
({
user
OpenaiAccount
,
user
,
inputs
:
{
history
=
[],
content
,
extractKeys
,
description
}
inputs
:
{
history
=
[],
content
,
extractKeys
,
description
}
}:
Props
)
{
}:
Props
)
{
const
extractModel
=
global
.
extractModel
;
const
extractModel
=
global
.
extractModel
;
...
@@ -126,7 +126,7 @@ async function functionCall({
...
@@ -126,7 +126,7 @@ async function functionCall({
}
}
};
};
const
chatAPI
=
getAIChatApi
(
user
O
penaiAccount
);
const
chatAPI
=
getAIChatApi
(
user
.
o
penaiAccount
);
const
response
=
await
chatAPI
.
createChatCompletion
(
const
response
=
await
chatAPI
.
createChatCompletion
(
{
{
...
@@ -137,7 +137,7 @@ async function functionCall({
...
@@ -137,7 +137,7 @@ async function functionCall({
functions
:
[
agentFunction
]
functions
:
[
agentFunction
]
},
},
{
{
...
axiosConfig
(
user
O
penaiAccount
)
...
axiosConfig
(
user
.
o
penaiAccount
)
}
}
);
);
...
@@ -157,7 +157,7 @@ async function functionCall({
...
@@ -157,7 +157,7 @@ async function functionCall({
}
}
async
function
completions
({
async
function
completions
({
user
OpenaiAccount
,
user
,
inputs
:
{
history
=
[],
content
,
extractKeys
,
description
}
inputs
:
{
history
=
[],
content
,
extractKeys
,
description
}
}:
Props
)
{
}:
Props
)
{
const
extractModel
=
global
.
extractModel
;
const
extractModel
=
global
.
extractModel
;
...
@@ -181,7 +181,7 @@ Human: ${content}`
...
@@ -181,7 +181,7 @@ Human: ${content}`
}
}
];
];
const
chatAPI
=
getAIChatApi
(
user
O
penaiAccount
);
const
chatAPI
=
getAIChatApi
(
user
.
o
penaiAccount
);
const
{
data
}
=
await
chatAPI
.
createChatCompletion
(
const
{
data
}
=
await
chatAPI
.
createChatCompletion
(
{
{
...
@@ -192,7 +192,7 @@ Human: ${content}`
...
@@ -192,7 +192,7 @@ Human: ${content}`
},
},
{
{
timeout
:
480000
,
timeout
:
480000
,
...
axiosConfig
(
user
O
penaiAccount
)
...
axiosConfig
(
user
.
o
penaiAccount
)
}
}
);
);
const
answer
=
data
.
choices
?.[
0
].
message
?.
content
||
''
;
const
answer
=
data
.
choices
?.[
0
].
message
?.
content
||
''
;
...
...
projects/app/src/service/moduleDispatch/chat/oneapi.ts
View file @
98ce5103
...
@@ -5,13 +5,13 @@ import type { ChatHistoryItemResType } from '@/types/chat';
...
@@ -5,13 +5,13 @@ import type { ChatHistoryItemResType } from '@/types/chat';
import
{
ChatRoleEnum
,
sseResponseEventEnum
}
from
'@/constants/chat'
;
import
{
ChatRoleEnum
,
sseResponseEventEnum
}
from
'@/constants/chat'
;
import
{
SSEParseData
,
parseStreamChunk
}
from
'@/utils/sse'
;
import
{
SSEParseData
,
parseStreamChunk
}
from
'@/utils/sse'
;
import
{
textAdaptGptResponse
}
from
'@/utils/adapt'
;
import
{
textAdaptGptResponse
}
from
'@/utils/adapt'
;
import
{
getAIChatApi
,
axiosConfig
}
from
'@fastgpt/core/ai
Api
/config'
;
import
{
getAIChatApi
,
axiosConfig
}
from
'@fastgpt/core/ai/config'
;
import
{
TaskResponseKeyEnum
}
from
'@/constants/chat'
;
import
{
TaskResponseKeyEnum
}
from
'@/constants/chat'
;
import
{
getChatModel
}
from
'@/service/utils/data'
;
import
{
getChatModel
}
from
'@/service/utils/data'
;
import
{
countModelPrice
}
from
'@/service/common/bill/push'
;
import
{
countModelPrice
}
from
'@/service/common/bill/push'
;
import
{
ChatModelItemType
}
from
'@/types/model'
;
import
{
ChatModelItemType
}
from
'@/types/model'
;
import
{
textCensor
}
from
'@/api/service/plugins'
;
import
{
textCensor
}
from
'@/api/service/plugins'
;
import
{
ChatCompletionRequestMessageRoleEnum
}
from
'@fastgpt/core/ai
Api
/constant'
;
import
{
ChatCompletionRequestMessageRoleEnum
}
from
'@fastgpt/core/ai/constant'
;
import
{
AppModuleItemType
}
from
'@/types/app'
;
import
{
AppModuleItemType
}
from
'@/types/app'
;
import
{
countMessagesTokens
,
sliceMessagesTB
}
from
'@/utils/common/tiktoken'
;
import
{
countMessagesTokens
,
sliceMessagesTB
}
from
'@/utils/common/tiktoken'
;
import
{
adaptChat2GptMessages
}
from
'@/utils/common/adapt/message'
;
import
{
adaptChat2GptMessages
}
from
'@/utils/common/adapt/message'
;
...
@@ -35,6 +35,7 @@ export type ChatProps = ModuleDispatchProps<
...
@@ -35,6 +35,7 @@ export type ChatProps = ModuleDispatchProps<
export
type
ChatResponse
=
{
export
type
ChatResponse
=
{
[
TaskResponseKeyEnum
.
answerText
]:
string
;
[
TaskResponseKeyEnum
.
answerText
]:
string
;
[
TaskResponseKeyEnum
.
responseData
]:
ChatHistoryItemResType
;
[
TaskResponseKeyEnum
.
responseData
]:
ChatHistoryItemResType
;
[
TaskResponseKeyEnum
.
history
]:
ChatItemType
[];
finish
:
boolean
;
finish
:
boolean
;
};
};
...
@@ -45,7 +46,7 @@ export const dispatchChatCompletion = async (props: ChatProps): Promise<ChatResp
...
@@ -45,7 +46,7 @@ export const dispatchChatCompletion = async (props: ChatProps): Promise<ChatResp
moduleName
,
moduleName
,
stream
=
false
,
stream
=
false
,
detail
=
false
,
detail
=
false
,
user
OpenaiAccount
,
user
,
outputs
,
outputs
,
inputs
:
{
inputs
:
{
model
=
global
.
chatModels
[
0
]?.
model
,
model
=
global
.
chatModels
[
0
]?.
model
,
...
@@ -105,7 +106,7 @@ export const dispatchChatCompletion = async (props: ChatProps): Promise<ChatResp
...
@@ -105,7 +106,7 @@ export const dispatchChatCompletion = async (props: ChatProps): Promise<ChatResp
// FastGPT temperature range: 1~10
// FastGPT temperature range: 1~10
temperature
=
+
(
modelConstantsData
.
maxTemperature
*
(
temperature
/
10
)).
toFixed
(
2
);
temperature
=
+
(
modelConstantsData
.
maxTemperature
*
(
temperature
/
10
)).
toFixed
(
2
);
temperature
=
Math
.
max
(
temperature
,
0.01
);
temperature
=
Math
.
max
(
temperature
,
0.01
);
const
chatAPI
=
getAIChatApi
(
user
O
penaiAccount
);
const
chatAPI
=
getAIChatApi
(
user
.
o
penaiAccount
);
const
response
=
await
chatAPI
.
createChatCompletion
(
const
response
=
await
chatAPI
.
createChatCompletion
(
{
{
...
@@ -128,7 +129,7 @@ export const dispatchChatCompletion = async (props: ChatProps): Promise<ChatResp
...
@@ -128,7 +129,7 @@ export const dispatchChatCompletion = async (props: ChatProps): Promise<ChatResp
{
{
timeout
:
480000
,
timeout
:
480000
,
responseType
:
stream
?
'stream'
:
'json'
,
responseType
:
stream
?
'stream'
:
'json'
,
...
axiosConfig
(
user
O
penaiAccount
)
...
axiosConfig
(
user
.
o
penaiAccount
)
}
}
);
);
...
@@ -179,7 +180,7 @@ export const dispatchChatCompletion = async (props: ChatProps): Promise<ChatResp
...
@@ -179,7 +180,7 @@ export const dispatchChatCompletion = async (props: ChatProps): Promise<ChatResp
[
TaskResponseKeyEnum
.
responseData
]:
{
[
TaskResponseKeyEnum
.
responseData
]:
{
moduleType
:
FlowModuleTypeEnum
.
chatNode
,
moduleType
:
FlowModuleTypeEnum
.
chatNode
,
moduleName
,
moduleName
,
price
:
user
O
penaiAccount
?.
key
?
0
:
countModelPrice
({
model
,
tokens
:
totalTokens
}),
price
:
user
.
o
penaiAccount
?.
key
?
0
:
countModelPrice
({
model
,
tokens
:
totalTokens
}),
model
:
modelConstantsData
.
name
,
model
:
modelConstantsData
.
name
,
tokens
:
totalTokens
,
tokens
:
totalTokens
,
question
:
userChatInput
,
question
:
userChatInput
,
...
@@ -187,6 +188,7 @@ export const dispatchChatCompletion = async (props: ChatProps): Promise<ChatResp
...
@@ -187,6 +188,7 @@ export const dispatchChatCompletion = async (props: ChatProps): Promise<ChatResp
quoteList
:
filterQuoteQA
,
quoteList
:
filterQuoteQA
,
historyPreview
:
getHistoryPreview
(
completeMessages
)
historyPreview
:
getHistoryPreview
(
completeMessages
)
},
},
[
TaskResponseKeyEnum
.
history
]:
completeMessages
,
finish
:
true
finish
:
true
};
};
};
};
...
...
projects/app/src/service/moduleDispatch/index.ts
View file @
98ce5103
...
@@ -4,5 +4,6 @@ export * from './chat/oneapi';
...
@@ -4,5 +4,6 @@ export * from './chat/oneapi';
export
*
from
'./kb/search'
;
export
*
from
'./kb/search'
;
export
*
from
'./tools/answer'
;
export
*
from
'./tools/answer'
;
export
*
from
'./tools/http'
;
export
*
from
'./tools/http'
;
export
*
from
'./tools/runApp'
;
export
*
from
'./agent/classifyQuestion'
;
export
*
from
'./agent/classifyQuestion'
;
export
*
from
'./agent/extract'
;
export
*
from
'./agent/extract'
;
projects/app/src/service/moduleDispatch/tools/answer.ts
View file @
98ce5103
...
@@ -6,7 +6,6 @@ export type AnswerProps = ModuleDispatchProps<{
...
@@ -6,7 +6,6 @@ export type AnswerProps = ModuleDispatchProps<{
text
:
string
;
text
:
string
;
}
>
;
}
>
;
export
type
AnswerResponse
=
{
export
type
AnswerResponse
=
{
[
TaskResponseKeyEnum
.
answerText
]:
string
;
finish
:
boolean
;
finish
:
boolean
;
};
};
...
@@ -29,7 +28,6 @@ export const dispatchAnswer = (props: Record<string, any>): AnswerResponse => {
...
@@ -29,7 +28,6 @@ export const dispatchAnswer = (props: Record<string, any>): AnswerResponse => {
}
}
return
{
return
{
[
TaskResponseKeyEnum
.
answerText
]:
text
,
finish
:
true
finish
:
true
};
};
};
};
projects/app/src/service/moduleDispatch/tools/runApp.ts
0 → 100644
View file @
98ce5103
import
{
ChatHistoryItemResType
,
ChatItemType
}
from
'@/types/chat'
;
import
type
{
ModuleDispatchProps
}
from
'@/types/core/chat/type'
;
import
{
SelectAppItemType
}
from
'@/types/core/app/flow'
;
import
{
dispatchModules
}
from
'@/pages/api/v1/chat/completions'
;
import
{
App
}
from
'@/service/mongo'
;
import
{
responseWrite
}
from
'@/service/common/stream'
;
import
{
ChatRoleEnum
,
TaskResponseKeyEnum
,
sseResponseEventEnum
}
from
'@/constants/chat'
;
import
{
textAdaptGptResponse
}
from
'@/utils/adapt'
;
type
Props
=
ModuleDispatchProps
<
{
userChatInput
:
string
;
history
?:
ChatItemType
[];
app
:
SelectAppItemType
;
}
>
;
type
Response
=
{
finish
:
boolean
;
[
TaskResponseKeyEnum
.
responseData
]:
ChatHistoryItemResType
[];
[
TaskResponseKeyEnum
.
answerText
]:
string
;
[
TaskResponseKeyEnum
.
history
]:
ChatItemType
[];
};
export
const
dispatchAppRequest
=
async
(
props
:
Record
<
string
,
any
>
):
Promise
<
Response
>
=>
{
const
{
res
,
variables
,
user
,
stream
,
detail
,
inputs
:
{
userChatInput
,
history
=
[],
app
}
}
=
props
as
Props
;
if
(
!
userChatInput
)
{
return
Promise
.
reject
(
'Input is empty'
);
}
const
appData
=
await
App
.
findById
(
app
.
id
);
if
(
!
appData
)
{
return
Promise
.
reject
(
'App not found'
);
}
responseWrite
({
res
,
event
:
detail
?
sseResponseEventEnum
.
answer
:
undefined
,
data
:
textAdaptGptResponse
({
text
:
'\n'
})
});
const
{
responseData
,
answerText
}
=
await
dispatchModules
({
res
,
modules
:
appData
.
modules
,
user
,
variables
,
params
:
{
history
,
userChatInput
},
stream
,
detail
});
const
completeMessages
=
history
.
concat
([
{
obj
:
ChatRoleEnum
.
Human
,
value
:
userChatInput
},
{
obj
:
ChatRoleEnum
.
AI
,
value
:
answerText
}
]);
return
{
finish
:
true
,
responseData
,
[
TaskResponseKeyEnum
.
answerText
]:
answerText
,
[
TaskResponseKeyEnum
.
history
]:
completeMessages
};
};
projects/app/src/service/support/outLink/auth.ts
View file @
98ce5103
...
@@ -102,8 +102,23 @@ export async function authOutLinkLimit({
...
@@ -102,8 +102,23 @@ export async function authOutLinkLimit({
await
authShareStart
({
authToken
,
tokenUrl
:
outLink
.
limit
.
hookUrl
,
question
});
await
authShareStart
({
authToken
,
tokenUrl
:
outLink
.
limit
.
hookUrl
,
question
});
}
}
export
async
function
authOutLinkId
({
id
}:
{
id
:
string
})
{
const
outLink
=
await
OutLink
.
findOne
({
shareId
:
id
});
if
(
!
outLink
)
{
return
Promise
.
reject
(
'分享链接无效'
);
}
return
{
userId
:
String
(
outLink
.
userId
)
};
}
type
TokenAuthResponseType
=
{
type
TokenAuthResponseType
=
{
success
:
boolean
;
success
:
boolean
;
msg
?:
string
;
message
?:
string
;
message
?:
string
;
};
};
...
@@ -119,7 +134,7 @@ export const authShareChatInit = async (authToken?: string, tokenUrl?: string) =
...
@@ -119,7 +134,7 @@ export const authShareChatInit = async (authToken?: string, tokenUrl?: string) =
}
}
});
});
if
(
data
?.
success
!==
true
)
{
if
(
data
?.
success
!==
true
)
{
return
Promise
.
reject
(
data
?.
message
||
'身份校验失败'
);
return
Promise
.
reject
(
data
?.
message
||
data
?.
msg
||
'身份校验失败'
);
}
}
}
catch
(
error
)
{
}
catch
(
error
)
{
return
Promise
.
reject
(
'身份校验失败'
);
return
Promise
.
reject
(
'身份校验失败'
);
...
@@ -148,7 +163,7 @@ export const authShareStart = async ({
...
@@ -148,7 +163,7 @@ export const authShareStart = async ({
});
});
if
(
data
?.
success
!==
true
)
{
if
(
data
?.
success
!==
true
)
{
return
Promise
.
reject
(
data
?.
message
||
'身份校验失败'
);
return
Promise
.
reject
(
data
?.
message
||
data
?.
msg
||
'身份校验失败'
);
}
}
}
catch
(
error
)
{
}
catch
(
error
)
{
return
Promise
.
reject
(
'身份校验失败'
);
return
Promise
.
reject
(
'身份校验失败'
);
...
...
projects/app/src/service/utils/auth.ts
View file @
98ce5103
import
type
{
NextApiRequest
}
from
'next'
;
import
type
{
NextApiRequest
}
from
'next'
;
import
Cookie
from
'cookie'
;
import
Cookie
from
'cookie'
;
import
{
App
,
OpenApi
,
User
,
KB
}
from
'../mongo'
;
import
{
App
,
User
,
KB
}
from
'../mongo'
;
import
type
{
AppSchema
,
UserModelSchema
}
from
'@/types/mongoSchema'
;
import
type
{
AppSchema
,
UserModelSchema
}
from
'@/types/mongoSchema'
;
import
{
ERROR_ENUM
}
from
'../errorCode'
;
import
{
ERROR_ENUM
}
from
'../errorCode'
;
import
{
authJWT
}
from
'./tools'
;
import
{
authJWT
}
from
'./tools'
;
import
{
authOpenApiKey
}
from
'../support/openapi/auth'
;
import
{
authOpenApiKey
}
from
'../support/openapi/auth'
;
import
{
authOutLinkId
}
from
'../support/outLink/auth'
;
export
enum
AuthUserTypeEnum
{
export
enum
AuthUserTypeEnum
{
token
=
'token'
,
token
=
'token'
,
root
=
'root'
,
root
=
'root'
,
apikey
=
'apikey'
apikey
=
'apikey'
,
outLink
=
'outLink'
}
}
/* auth balance */
/* auth balance */
...
@@ -34,13 +36,15 @@ export const authUser = async ({
...
@@ -34,13 +36,15 @@ export const authUser = async ({
authToken
=
false
,
authToken
=
false
,
authRoot
=
false
,
authRoot
=
false
,
authApiKey
=
false
,
authApiKey
=
false
,
authBalance
=
false
authBalance
=
false
,
authOutLink
}:
{
}:
{
req
:
NextApiRequest
;
req
:
NextApiRequest
;
authToken
?:
boolean
;
authToken
?:
boolean
;
authRoot
?:
boolean
;
authRoot
?:
boolean
;
authApiKey
?:
boolean
;
authApiKey
?:
boolean
;
authBalance
?:
boolean
;
authBalance
?:
boolean
;
authOutLink
?:
boolean
;
})
=>
{
})
=>
{
const
authCookieToken
=
async
(
cookie
?:
string
,
token
?:
string
):
Promise
<
string
>
=>
{
const
authCookieToken
=
async
(
cookie
?:
string
,
token
?:
string
):
Promise
<
string
>
=>
{
// 获取 cookie
// 获取 cookie
...
@@ -107,13 +111,18 @@ export const authUser = async ({
...
@@ -107,13 +111,18 @@ export const authUser = async ({
userid
?:
string
;
userid
?:
string
;
authorization
?:
string
;
authorization
?:
string
;
};
};
const
{
shareId
}
=
(
req
?.
body
||
{})
as
{
shareId
?:
string
};
let
uid
=
''
;
let
uid
=
''
;
let
appId
=
''
;
let
appId
=
''
;
let
openApiKey
=
apikey
;
let
openApiKey
=
apikey
;
let
authType
:
`
${
AuthUserTypeEnum
}
`
=
AuthUserTypeEnum
.
token
;
let
authType
:
`
${
AuthUserTypeEnum
}
`
=
AuthUserTypeEnum
.
token
;
if
(
authToken
&&
(
cookie
||
token
))
{
if
(
authOutLink
&&
shareId
)
{
const
res
=
await
authOutLinkId
({
id
:
shareId
});
uid
=
res
.
userId
;
authType
=
AuthUserTypeEnum
.
outLink
;
}
else
if
(
authToken
&&
(
cookie
||
token
))
{
// user token(from fastgpt web)
// user token(from fastgpt web)
uid
=
await
authCookieToken
(
cookie
,
token
);
uid
=
await
authCookieToken
(
cookie
,
token
);
authType
=
AuthUserTypeEnum
.
token
;
authType
=
AuthUserTypeEnum
.
token
;
...
...
projects/app/src/types/core/app/flow.d.ts
View file @
98ce5103
...
@@ -60,3 +60,9 @@ export type FlowModuleTemplateType = {
...
@@ -60,3 +60,9 @@ export type FlowModuleTemplateType = {
export
type
FlowModuleItemType
=
FlowModuleTemplateType
&
{
export
type
FlowModuleItemType
=
FlowModuleTemplateType
&
{
moduleId
:
string
;
moduleId
:
string
;
};
};
export
type
SelectAppItemType
=
{
id
:
string
;
name
:
string
;
logo
:
string
;
};
projects/app/src/types/core/chat/type.d.ts
View file @
98ce5103
import
type
{
ChatCompletionRequestMessage
}
from
'@fastgpt/core/ai
Api
/type'
;
import
type
{
ChatCompletionRequestMessage
}
from
'@fastgpt/core/ai/type'
;
import
type
{
NextApiResponse
}
from
'next'
;
import
type
{
NextApiResponse
}
from
'next'
;
import
{
RunningModuleItemType
}
from
'@/types/app'
;
import
{
RunningModuleItemType
}
from
'@/types/app'
;
import
{
UserModelSchema
}
from
'@/types/mongoSchema'
;
import
{
UserModelSchema
}
from
'@/types/mongoSchema'
;
...
@@ -13,6 +13,6 @@ export type ModuleDispatchProps<T> = {
...
@@ -13,6 +13,6 @@ export type ModuleDispatchProps<T> = {
detail
:
boolean
;
detail
:
boolean
;
variables
:
Record
<
string
,
any
>
;
variables
:
Record
<
string
,
any
>
;
outputs
:
RunningModuleItemType
[
'outputs'
];
outputs
:
RunningModuleItemType
[
'outputs'
];
user
OpenaiAccount
?:
UserModelSchema
[
'openaiAccount'
]
;
user
:
UserModelSchema
;
inputs
:
T
;
inputs
:
T
;
};
};
projects/app/src/utils/adapt.ts
View file @
98ce5103
...
@@ -2,7 +2,7 @@ import { formatPrice } from '@fastgpt/common/bill/index';
...
@@ -2,7 +2,7 @@ import { formatPrice } from '@fastgpt/common/bill/index';
import
type
{
BillSchema
}
from
'@/types/common/bill'
;
import
type
{
BillSchema
}
from
'@/types/common/bill'
;
import
type
{
UserBillType
}
from
'@/types/user'
;
import
type
{
UserBillType
}
from
'@/types/user'
;
import
{
ChatItemType
}
from
'@/types/chat'
;
import
{
ChatItemType
}
from
'@/types/chat'
;
import
{
ChatCompletionRequestMessageRoleEnum
}
from
'@fastgpt/core/ai
Api
/constant'
;
import
{
ChatCompletionRequestMessageRoleEnum
}
from
'@fastgpt/core/ai/constant'
;
import
{
ChatRoleEnum
}
from
'@/constants/chat'
;
import
{
ChatRoleEnum
}
from
'@/constants/chat'
;
import
type
{
MessageItemType
}
from
'@/types/core/chat/type'
;
import
type
{
MessageItemType
}
from
'@/types/core/chat/type'
;
import
type
{
AppModuleItemType
}
from
'@/types/app'
;
import
type
{
AppModuleItemType
}
from
'@/types/app'
;
...
...
projects/app/src/utils/common/adapt/message.ts
View file @
98ce5103
import
type
{
ChatItemType
}
from
'@/types/chat'
;
import
type
{
ChatItemType
}
from
'@/types/chat'
;
import
{
ChatRoleEnum
}
from
'@/constants/chat'
;
import
{
ChatRoleEnum
}
from
'@/constants/chat'
;
import
{
ChatCompletionRequestMessageRoleEnum
}
from
'@fastgpt/core/ai
Api
/constant'
;
import
{
ChatCompletionRequestMessageRoleEnum
}
from
'@fastgpt/core/ai/constant'
;
import
type
{
MessageItemType
}
from
'@/types/core/chat/type'
;
import
type
{
MessageItemType
}
from
'@/types/core/chat/type'
;
const
chat2Message
=
{
const
chat2Message
=
{
...
...
projects/app/src/utils/common/tiktoken/index.ts
View file @
98ce5103
...
@@ -2,7 +2,7 @@
...
@@ -2,7 +2,7 @@
import
{
ChatItemType
}
from
'@/types/chat'
;
import
{
ChatItemType
}
from
'@/types/chat'
;
import
{
Tiktoken
}
from
'js-tiktoken/lite'
;
import
{
Tiktoken
}
from
'js-tiktoken/lite'
;
import
{
adaptChat2GptMessages
}
from
'../adapt/message'
;
import
{
adaptChat2GptMessages
}
from
'../adapt/message'
;
import
{
ChatCompletionRequestMessageRoleEnum
}
from
'@fastgpt/core/ai
Api
/constant'
;
import
{
ChatCompletionRequestMessageRoleEnum
}
from
'@fastgpt/core/ai/constant'
;
import
encodingJson
from
'./cl100k_base.json'
;
import
encodingJson
from
'./cl100k_base.json'
;
/* init tikToken obj */
/* init tikToken obj */
...
...
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