Commit cd682d42 by Archer Committed by GitHub

4.6.5- CoreferenceResolution Module (#631)

parent 41115a96
...@@ -8,4 +8,5 @@ README.md ...@@ -8,4 +8,5 @@ README.md
.yalc/ .yalc/
yalc.lock yalc.lock
testApi/ testApi/
\ No newline at end of file *.local.*
\ No newline at end of file
...@@ -35,4 +35,5 @@ dist/ ...@@ -35,4 +35,5 @@ dist/
**/.hugo_build.lock **/.hugo_build.lock
docSite/public/ docSite/public/
docSite/resources/_gen/ docSite/resources/_gen/
docSite/.vercel docSite/.vercel
\ No newline at end of file *.local.*
\ No newline at end of file
...@@ -76,6 +76,11 @@ COPY --from=builder --chown=nextjs:nodejs /app/projects/$name/.next/static /app/ ...@@ -76,6 +76,11 @@ COPY --from=builder --chown=nextjs:nodejs /app/projects/$name/.next/static /app/
COPY --from=builder /app/projects/$name/package.json ./package.json COPY --from=builder /app/projects/$name/package.json ./package.json
# copy woker # copy woker
COPY --from=workerDeps /app/worker /app/worker COPY --from=workerDeps /app/worker /app/worker
# copy config
COPY ./projects/$name/data/config.json /app/data/config.json
COPY ./projects/$name/data/pluginTemplates /app/data/pluginTemplates
COPY ./projects/$name/data/simpleTemplates /app/data/simpleTemplates
ENV NODE_ENV production ENV NODE_ENV production
ENV NEXT_TELEMETRY_DISABLED 1 ENV NEXT_TELEMETRY_DISABLED 1
......

120 KB | W: | H:

353 KB | W: | H:

docSite/assets/imgs/demo-appointment5.png
docSite/assets/imgs/demo-appointment5.png
docSite/assets/imgs/demo-appointment5.png
docSite/assets/imgs/demo-appointment5.png
  • 2-up
  • Swipe
  • Onion skin

205 KB | W: | H:

138 KB | W: | H:

docSite/assets/imgs/demo-appointment6.png
docSite/assets/imgs/demo-appointment6.png
docSite/assets/imgs/demo-appointment6.png
docSite/assets/imgs/demo-appointment6.png
  • 2-up
  • Swipe
  • Onion skin

39 KB | W: | H:

178 KB | W: | H:

docSite/assets/imgs/demo-appointment7.png
docSite/assets/imgs/demo-appointment7.png
docSite/assets/imgs/demo-appointment7.png
docSite/assets/imgs/demo-appointment7.png
  • 2-up
  • Swipe
  • Onion skin
...@@ -92,7 +92,7 @@ weight: 708 ...@@ -92,7 +92,7 @@ weight: 708
"maxContext": 16000, "maxContext": 16000,
"maxResponse": 4000, "maxResponse": 4000,
"price": 0, "price": 0,
"functionCall": true, // 是否支持function call, 不支持的模型需要设置为 false,会走提示词生成 "toolChoice": true, // 是否支持openai的 toolChoice, 不支持的模型需要设置为 false,会走提示词生成
"functionPrompt": "" "functionPrompt": ""
}, },
{ {
...@@ -101,7 +101,7 @@ weight: 708 ...@@ -101,7 +101,7 @@ weight: 708
"maxContext": 8000, "maxContext": 8000,
"maxResponse": 8000, "maxResponse": 8000,
"price": 0, "price": 0,
"functionCall": true, "toolChoice": true,
"functionPrompt": "" "functionPrompt": ""
} }
], ],
...@@ -112,7 +112,7 @@ weight: 708 ...@@ -112,7 +112,7 @@ weight: 708
"maxContext": 16000, "maxContext": 16000,
"maxResponse": 4000, "maxResponse": 4000,
"price": 0, "price": 0,
"functionCall": true, "toolChoice": true,
"functionPrompt": "" "functionPrompt": ""
} }
], ],
......
---
title: 'V4.6.5(需要改配置文件)'
description: 'FastGPT V4.6.5'
icon: 'upgrade'
draft: false
toc: true
weight: 831
---
## 配置文件变更
由于 openai 已开始启用 function call,改为 toolChoice。FastGPT 同步的修改了对于的配置和调用方式,需要对配置文件做一些修改:
[点击查看最新的配置文件](/docs/development/configuration/)
主要是修改模型的`functionCall`字段,改成`toolChoice`即可。设置为`true`的模型,会默认走 openai 的 tools 模式;未设置或设置为`false`的,会走提示词生成模式。
问题补全模型与内容提取模型使用同一组配置。
## V4.6.5 功能介绍
1. 新增 - [问题补全模块](/docs/workflow/modules/coreferenceresolution/)
2. 新增 - [文本编辑模块](/docs/workflow/modules/text_editor/)
3. 新增 - [判断器模块](/docs/workflow/modules/tfswitch/)
4. 新增 - [自定义反馈模块](/docs/workflow/modules/custom_feedback/)
5. 新增 - 【内容提取】模块支持选择模型,以及字段枚举
6. 优化 - docx读取,兼容表格(表格转markdown)
7. 优化 - 高级编排连接线交互
8. 优化 - 由于 html2md 导致的 cpu密集计算,阻断线程问题
9. 修复 - 高级编排提示词提取描述
...@@ -5,4 +5,6 @@ description: "介绍 FastGPT 的常用模块" ...@@ -5,4 +5,6 @@ description: "介绍 FastGPT 的常用模块"
icon: "apps" icon: "apps"
draft: false draft: false
images: [] images: []
--- ---
\ No newline at end of file
<!-- 350 ~ 400 -->
\ No newline at end of file
---
title: "问题补全"
description: "问题补全模块介绍和使用"
icon: "input"
draft: false
toc: true
weight: 364
---
## 特点
- 可重复添加
- 有外部输入
- 触发执行
![](/imgs/coreferenceResolution1.png)
## 背景
在 RAG 中,我们需要根据输入的问题去数据库里执行 embedding 搜索,查找相关的内容,从而查找到相似的内容(简称知识库搜索)。
在搜索的过程中,尤其是连续对话的搜索,我们通常会发现后续的问题难以搜索到合适的内容,其中一个原因是知识库搜索只会使用“当前”的问题去执行。看下面的例子:
![](/imgs/coreferenceResolution2.png)
用户在提问“第二点是什么”的时候,只会去知识库里查找“第二点是什么”,压根查不到内容。实际上需要查询的是“QA结构是什么”。因此我们需要引入一个【问题补全】模块,来对用户当前的问题进行补全,从而使得知识库搜索能够搜索到合适的内容。使用补全后效果如下:
![](/imgs/coreferenceResolution3.png)
## 功能
调用 AI 去对用户当前的问题进行补全。目前主要是补全“指代”词,使得检索词更加的完善可靠,从而增强上下文连续对话的知识库搜索能力。
遇到最大的难题在于:模型对于【补全】的概念可能不清晰,且对于长上下文往往无法准确的知道应该如何补全。
## 示例
- [接入谷歌搜索](/docs/workflow/examples/google_search/)
\ No newline at end of file
...@@ -26,3 +26,7 @@ weight: 363 ...@@ -26,3 +26,7 @@ weight: 363
## 作用 ## 作用
给任意模块输入自定格式文本,或处理 AI 模块系统提示词。 给任意模块输入自定格式文本,或处理 AI 模块系统提示词。
## 示例
- [接入谷歌搜索](/docs/workflow/examples/google_search/)
\ No newline at end of file
...@@ -25,4 +25,5 @@ weight: 362 ...@@ -25,4 +25,5 @@ weight: 362
## 作用 ## 作用
适用场景有:让大模型做判断后输出固定内容,根据大模型回复内容判断是否触发后续模块。 适用场景有:让大模型做判断后输出固定内容,根据大模型回复内容判断是否触发后续模块。
\ No newline at end of file
...@@ -28,7 +28,7 @@ export const simpleMarkdownText = (rawText: string) => { ...@@ -28,7 +28,7 @@ export const simpleMarkdownText = (rawText: string) => {
['####', '###', '##', '#', '```', '~~~'].forEach((item, i) => { ['####', '###', '##', '#', '```', '~~~'].forEach((item, i) => {
const reg = new RegExp(`\\n\\s*${item}`, 'g'); const reg = new RegExp(`\\n\\s*${item}`, 'g');
if (reg.test(rawText)) { if (reg.test(rawText)) {
rawText = rawText.replace(new RegExp(`(\\n)\\s*(${item})`, 'g'), '$1$2'); rawText = rawText.replace(new RegExp(`(\\n)( *)(${item})`, 'g'), '$1$3');
} }
}); });
......
...@@ -14,7 +14,7 @@ export type ChatModelItemType = LLMModelItemType & { ...@@ -14,7 +14,7 @@ export type ChatModelItemType = LLMModelItemType & {
}; };
export type FunctionModelItemType = LLMModelItemType & { export type FunctionModelItemType = LLMModelItemType & {
functionCall: boolean; toolChoice: boolean;
functionPrompt: string; functionPrompt: string;
}; };
......
import type { import type { LLMModelItemType, VectorModelItemType } from './model.d';
LLMModelItemType,
ChatModelItemType,
FunctionModelItemType,
VectorModelItemType,
AudioSpeechModelType,
WhisperModelType,
ReRankModelItemType
} from './model.d';
export const defaultChatModels: ChatModelItemType[] = [
{
model: 'gpt-3.5-turbo-1106',
name: 'GPT35-1106',
price: 0,
maxContext: 16000,
maxResponse: 4000,
quoteMaxToken: 2000,
maxTemperature: 1.2,
censor: false,
vision: false,
defaultSystemChatPrompt: ''
},
{
model: 'gpt-3.5-turbo-16k',
name: 'GPT35-16k',
maxContext: 16000,
maxResponse: 16000,
price: 0,
quoteMaxToken: 8000,
maxTemperature: 1.2,
censor: false,
vision: false,
defaultSystemChatPrompt: ''
},
{
model: 'gpt-4',
name: 'GPT4-8k',
maxContext: 8000,
maxResponse: 8000,
price: 0,
quoteMaxToken: 4000,
maxTemperature: 1.2,
censor: false,
vision: false,
defaultSystemChatPrompt: ''
},
{
model: 'gpt-4-vision-preview',
name: 'GPT4-Vision',
maxContext: 128000,
maxResponse: 4000,
price: 0,
quoteMaxToken: 100000,
maxTemperature: 1.2,
censor: false,
vision: true,
defaultSystemChatPrompt: ''
}
];
export const defaultQAModels: LLMModelItemType[] = [ export const defaultQAModels: LLMModelItemType[] = [
{ {
model: 'gpt-3.5-turbo-16k', model: 'gpt-3.5-turbo-16k',
...@@ -67,46 +9,6 @@ export const defaultQAModels: LLMModelItemType[] = [ ...@@ -67,46 +9,6 @@ export const defaultQAModels: LLMModelItemType[] = [
price: 0 price: 0
} }
]; ];
export const defaultCQModels: FunctionModelItemType[] = [
{
model: 'gpt-3.5-turbo-1106',
name: 'GPT35-1106',
maxContext: 16000,
maxResponse: 4000,
price: 0,
functionCall: true,
functionPrompt: ''
},
{
model: 'gpt-4',
name: 'GPT4-8k',
maxContext: 8000,
maxResponse: 8000,
price: 0,
functionCall: true,
functionPrompt: ''
}
];
export const defaultExtractModels: FunctionModelItemType[] = [
{
model: 'gpt-3.5-turbo-1106',
name: 'GPT35-1106',
maxContext: 16000,
maxResponse: 4000,
price: 0,
functionCall: true,
functionPrompt: ''
}
];
export const defaultQGModels: LLMModelItemType[] = [
{
model: 'gpt-3.5-turbo-1106',
name: 'GPT35-1106',
maxContext: 1600,
maxResponse: 4000,
price: 0
}
];
export const defaultVectorModels: VectorModelItemType[] = [ export const defaultVectorModels: VectorModelItemType[] = [
{ {
...@@ -117,27 +19,3 @@ export const defaultVectorModels: VectorModelItemType[] = [ ...@@ -117,27 +19,3 @@ export const defaultVectorModels: VectorModelItemType[] = [
maxToken: 3000 maxToken: 3000
} }
]; ];
export const defaultReRankModels: ReRankModelItemType[] = [];
export const defaultAudioSpeechModels: AudioSpeechModelType[] = [
{
model: 'tts-1',
name: 'OpenAI TTS1',
price: 0,
voices: [
{ label: 'Alloy', value: 'Alloy', bufferId: 'openai-Alloy' },
{ label: 'Echo', value: 'Echo', bufferId: 'openai-Echo' },
{ label: 'Fable', value: 'Fable', bufferId: 'openai-Fable' },
{ label: 'Onyx', value: 'Onyx', bufferId: 'openai-Onyx' },
{ label: 'Nova', value: 'Nova', bufferId: 'openai-Nova' },
{ label: 'Shimmer', value: 'Shimmer', bufferId: 'openai-Shimmer' }
]
}
];
export const defaultWhisperModel: WhisperModelType = {
model: 'whisper-1',
name: 'Whisper1',
price: 0
};
...@@ -67,6 +67,9 @@ export type AppSimpleEditFormType = { ...@@ -67,6 +67,9 @@ export type AppSimpleEditFormType = {
searchMode: `${DatasetSearchModeEnum}`; searchMode: `${DatasetSearchModeEnum}`;
searchEmptyText: string; searchEmptyText: string;
}; };
cfr: {
background: string;
};
userGuide: { userGuide: {
welcomeText: string; welcomeText: string;
variables: { variables: {
...@@ -111,6 +114,9 @@ export type AppSimpleEditConfigTemplateType = { ...@@ -111,6 +114,9 @@ export type AppSimpleEditConfigTemplateType = {
searchMode: `${DatasetSearchModeEnum}`; searchMode: `${DatasetSearchModeEnum}`;
searchEmptyText?: boolean; searchEmptyText?: boolean;
}; };
cfr?: {
background?: boolean;
};
userGuide?: { userGuide?: {
welcomeText?: boolean; welcomeText?: boolean;
variables?: boolean; variables?: boolean;
......
...@@ -3,23 +3,23 @@ import { FlowNodeTypeEnum } from '../module/node/constant'; ...@@ -3,23 +3,23 @@ import { FlowNodeTypeEnum } from '../module/node/constant';
import { ModuleOutputKeyEnum, ModuleInputKeyEnum } from '../module/constants'; import { ModuleOutputKeyEnum, ModuleInputKeyEnum } from '../module/constants';
import type { FlowNodeInputItemType } from '../module/node/type.d'; import type { FlowNodeInputItemType } from '../module/node/type.d';
import { getGuideModule, splitGuideModule } from '../module/utils'; import { getGuideModule, splitGuideModule } from '../module/utils';
import { defaultChatModels } from '../ai/model';
import { ModuleItemType } from '../module/type.d'; import { ModuleItemType } from '../module/type.d';
import { DatasetSearchModeEnum } from '../dataset/constant'; import { DatasetSearchModeEnum } from '../dataset/constant';
export const getDefaultAppForm = (templateId = 'fastgpt-universal'): AppSimpleEditFormType => { export const getDefaultAppForm = (templateId = 'fastgpt-universal'): AppSimpleEditFormType => {
const defaultChatModel = defaultChatModels[0];
return { return {
templateId, templateId,
aiSettings: { aiSettings: {
model: defaultChatModel?.model, model: 'gpt-3.5-turbo',
systemPrompt: '', systemPrompt: '',
temperature: 0, temperature: 0,
isResponseAnswerText: true, isResponseAnswerText: true,
quotePrompt: '', quotePrompt: '',
quoteTemplate: '', quoteTemplate: '',
maxToken: defaultChatModel ? defaultChatModel.maxResponse / 2 : 4000 maxToken: 4000
},
cfr: {
background: ''
}, },
dataset: { dataset: {
datasets: [], datasets: [],
...@@ -116,6 +116,11 @@ export const appModules2Form = ({ ...@@ -116,6 +116,11 @@ export const appModules2Form = ({
questionGuide: questionGuide, questionGuide: questionGuide,
tts: ttsConfig tts: ttsConfig
}; };
} else if (module.flowType === FlowNodeTypeEnum.cfr) {
const value = module.inputs.find((item) => item.key === ModuleInputKeyEnum.aiSystemPrompt);
if (value) {
defaultAppForm.cfr.background = value.value;
}
} }
}); });
......
...@@ -93,6 +93,7 @@ export type moduleDispatchResType = { ...@@ -93,6 +93,7 @@ export type moduleDispatchResType = {
model?: string; model?: string;
query?: string; query?: string;
contextTotalLen?: number; contextTotalLen?: number;
textOutput?: string;
// chat // chat
temperature?: number; temperature?: number;
...@@ -119,9 +120,7 @@ export type moduleDispatchResType = { ...@@ -119,9 +120,7 @@ export type moduleDispatchResType = {
// plugin output // plugin output
pluginOutput?: Record<string, any>; pluginOutput?: Record<string, any>;
pluginDetail?: ChatHistoryItemResType[];
// text editor
textOutput?: string;
// tf switch // tf switch
tfSwitchResult?: boolean; tfSwitchResult?: boolean;
......
...@@ -38,7 +38,6 @@ export enum FlowNodeOutputTypeEnum { ...@@ -38,7 +38,6 @@ export enum FlowNodeOutputTypeEnum {
} }
export enum FlowNodeTypeEnum { export enum FlowNodeTypeEnum {
empty = 'empty',
userGuide = 'userGuide', userGuide = 'userGuide',
questionInput = 'questionInput', questionInput = 'questionInput',
historyNode = 'historyNode', historyNode = 'historyNode',
...@@ -52,10 +51,10 @@ export enum FlowNodeTypeEnum { ...@@ -52,10 +51,10 @@ export enum FlowNodeTypeEnum {
pluginModule = 'pluginModule', pluginModule = 'pluginModule',
pluginInput = 'pluginInput', pluginInput = 'pluginInput',
pluginOutput = 'pluginOutput', pluginOutput = 'pluginOutput',
textEditor = 'textEditor', cfr = 'cfr',
// abandon // abandon
variable = 'variable' variable = 'variable'
} }
export const EDGE_TYPE = 'smoothstep'; export const EDGE_TYPE = 'default';
...@@ -141,7 +141,7 @@ export const AiChatModule: FlowModuleTemplateType = { ...@@ -141,7 +141,7 @@ export const AiChatModule: FlowModuleTemplateType = {
}, },
{ {
key: ModuleOutputKeyEnum.answerText, key: ModuleOutputKeyEnum.answerText,
label: 'AI回复', label: 'AI回复内容',
description: '将在 stream 回复完毕后触发', description: '将在 stream 回复完毕后触发',
valueType: ModuleIOValueTypeEnum.string, valueType: ModuleIOValueTypeEnum.string,
type: FlowNodeOutputTypeEnum.source, type: FlowNodeOutputTypeEnum.source,
......
import {
FlowNodeInputTypeEnum,
FlowNodeOutputTypeEnum,
FlowNodeTypeEnum
} from '../../node/constant';
import { FlowModuleTemplateType } from '../../type.d';
import {
ModuleIOValueTypeEnum,
ModuleInputKeyEnum,
ModuleOutputKeyEnum,
ModuleTemplateTypeEnum
} from '../../constants';
import {
Input_Template_History,
Input_Template_Switch,
Input_Template_UserChatInput
} from '../input';
export const AiCFR: FlowModuleTemplateType = {
id: FlowNodeTypeEnum.chatNode,
templateType: ModuleTemplateTypeEnum.tools,
flowType: FlowNodeTypeEnum.cfr,
avatar: '/imgs/module/cfr.svg',
name: 'core.module.template.cfr',
intro: 'core.module.template.cfr intro',
showStatus: true,
inputs: [
Input_Template_Switch,
{
key: ModuleInputKeyEnum.aiModel,
type: FlowNodeInputTypeEnum.selectExtractModel,
label: 'core.module.input.label.aiModel',
required: true,
valueType: ModuleIOValueTypeEnum.string,
showTargetInApp: false,
showTargetInPlugin: false
},
{
key: ModuleInputKeyEnum.aiSystemPrompt,
type: FlowNodeInputTypeEnum.textarea,
label: 'core.module.input.label.cfr background',
max: 300,
valueType: ModuleIOValueTypeEnum.string,
description: 'core.module.input.description.cfr background',
placeholder: 'core.module.input.placeholder.cfr background',
showTargetInApp: true,
showTargetInPlugin: true
},
Input_Template_History,
Input_Template_UserChatInput
],
outputs: [
{
key: ModuleOutputKeyEnum.text,
label: 'core.module.output.label.cfr result',
valueType: ModuleIOValueTypeEnum.string,
type: FlowNodeOutputTypeEnum.source,
targets: []
}
]
};
import { ModuleTemplateTypeEnum } from '../../constants';
import { FlowNodeTypeEnum } from '../../node/constant';
import { FlowModuleTemplateType } from '../../type.d';
export const EmptyModule: FlowModuleTemplateType = {
id: FlowNodeTypeEnum.empty,
templateType: ModuleTemplateTypeEnum.other,
flowType: FlowNodeTypeEnum.empty,
avatar: '/imgs/module/cq.png',
name: '该模块已被移除',
intro: '',
inputs: [],
outputs: []
};
...@@ -38,7 +38,7 @@ export type ModuleItemType = { ...@@ -38,7 +38,7 @@ export type ModuleItemType = {
outputs: FlowNodeOutputItemType[]; outputs: FlowNodeOutputItemType[];
}; };
/* function type */ /* --------------- function type -------------------- */
// variable // variable
export type VariableItemType = { export type VariableItemType = {
id: string; id: string;
...@@ -74,3 +74,46 @@ export type ContextExtractAgentItemType = { ...@@ -74,3 +74,46 @@ export type ContextExtractAgentItemType = {
required: boolean; required: boolean;
enum?: string; enum?: string;
}; };
/* -------------- running module -------------- */
export type RunningModuleItemType = {
name: ModuleItemType['name'];
moduleId: ModuleItemType['moduleId'];
flowType: ModuleItemType['flowType'];
showStatus?: ModuleItemType['showStatus'];
} & {
inputs: {
key: string;
value?: any;
}[];
outputs: {
key: string;
answer?: boolean;
response?: boolean;
value?: any;
targets: {
moduleId: string;
key: string;
}[];
}[];
};
export type ChatDispatchProps = {
res: NextApiResponse;
mode: 'test' | 'chat';
teamId: string;
tmbId: string;
user: UserType;
appId: string;
chatId?: string;
responseChatItemId?: string;
histories: ChatItemType[];
variables: Record<string, any>;
stream: boolean;
detail: boolean; // response detail
};
export type ModuleDispatchProps<T> = ChatDispatchProps & {
outputs: RunningModuleItemType['outputs'];
inputs: T;
};
...@@ -15,14 +15,19 @@ export type PluginItemSchema = { ...@@ -15,14 +15,19 @@ export type PluginItemSchema = {
}; };
/* plugin template */ /* plugin template */
export type PluginTemplateType = { export type PluginTemplateType = PluginRuntimeType & {
author?: string; author?: string;
id: string; id: string;
source: `${PluginSourceEnum}`; source: `${PluginSourceEnum}`;
templateType: FlowModuleTemplateType['templateType']; templateType: FlowModuleTemplateType['templateType'];
intro: string;
modules: ModuleItemType[];
};
export type PluginRuntimeType = {
teamId?: string;
name: string; name: string;
avatar: string; avatar: string;
intro: string;
showStatus?: boolean; showStatus?: boolean;
modules: ModuleItemType[]; modules: ModuleItemType[];
}; };
...@@ -20,11 +20,12 @@ export async function connectMongo({ ...@@ -20,11 +20,12 @@ export async function connectMongo({
console.log('mongo start connect'); console.log('mongo start connect');
try { try {
mongoose.set('strictQuery', true); mongoose.set('strictQuery', true);
const maxConnecting = Math.max(20, Number(process.env.DB_MAX_LINK || 20));
await mongoose.connect(process.env.MONGODB_URI as string, { await mongoose.connect(process.env.MONGODB_URI as string, {
bufferCommands: true, bufferCommands: true,
maxConnecting: Number(process.env.DB_MAX_LINK || 5), maxConnecting: maxConnecting,
maxPoolSize: Number(process.env.DB_MAX_LINK || 5), maxPoolSize: maxConnecting,
minPoolSize: Math.min(10, Number(process.env.DB_MAX_LINK || 10)), minPoolSize: Math.max(5, Math.round(Number(process.env.DB_MAX_LINK || 5) * 0.1)),
connectTimeoutMS: 60000, connectTimeoutMS: 60000,
waitQueueTimeoutMS: 60000, waitQueueTimeoutMS: 60000,
socketTimeoutMS: 60000, socketTimeoutMS: 60000,
......
import type { NextApiResponse } from 'next'; import type { NextApiResponse } from 'next';
import { getAIApi } from '../config'; import { getAIApi } from '../config';
import { defaultAudioSpeechModels } from '../../../../global/core/ai/model';
import { UserModelSchema } from '@fastgpt/global/support/user/type';
export async function text2Speech({ export async function text2Speech({
res, res,
onSuccess, onSuccess,
onError, onError,
input, input,
model = defaultAudioSpeechModels[0].model, model,
voice, voice,
speed = 1 speed = 1
}: { }: {
......
import { replaceVariable } from '@fastgpt/global/common/string/tools';
import { getAIApi } from '../config';
const prompt = `
您的任务是生成根据用户问题,从不同角度,生成两个不同版本的问题,以便可以从矢量数据库检索相关文档。例如:
问题: FastGPT如何使用?
OUTPUT: ["FastGPT使用教程。","怎么使用FastGPT?"]
-------------------
问题: FastGPT如何收费?
OUTPUT: ["FastGPT收费标准。","FastGPT是如何计费的?"]
-------------------
问题: 怎么FastGPT部署?
OUTPUT: ["FastGPT的部署方式。","如何部署FastGPT?"]
-------------------
问题 question: {{q}}
OUTPUT:
`;
export const searchQueryExtension = async ({ query, model }: { query: string; model: string }) => {
const ai = getAIApi(undefined, 480000);
const result = await ai.chat.completions.create({
model,
temperature: 0,
messages: [
{
role: 'user',
content: replaceVariable(prompt, { q: query })
}
],
stream: false
});
const answer = result.choices?.[0]?.message?.content || '';
if (!answer) {
return {
queries: [query],
model,
inputTokens: 0,
responseTokens: 0
};
}
try {
return {
queries: JSON.parse(answer) as string[],
model,
inputTokens: result.usage?.prompt_tokens || 0,
responseTokens: result.usage?.completion_tokens || 0
};
} catch (error) {
return {
queries: [query],
model,
inputTokens: 0,
responseTokens: 0
};
}
};
...@@ -3,7 +3,7 @@ import { FlowModuleTemplateType } from '@fastgpt/global/core/module/type'; ...@@ -3,7 +3,7 @@ import { FlowModuleTemplateType } from '@fastgpt/global/core/module/type';
import { FlowNodeTypeEnum } from '@fastgpt/global/core/module/node/constant'; import { FlowNodeTypeEnum } from '@fastgpt/global/core/module/node/constant';
import { plugin2ModuleIO } from '@fastgpt/global/core/module/utils'; import { plugin2ModuleIO } from '@fastgpt/global/core/module/utils';
import { PluginSourceEnum } from '@fastgpt/global/core/plugin/constants'; import { PluginSourceEnum } from '@fastgpt/global/core/plugin/constants';
import type { PluginTemplateType } from '@fastgpt/global/core/plugin/type.d'; import type { PluginRuntimeType, PluginTemplateType } from '@fastgpt/global/core/plugin/type.d';
import { ModuleTemplateTypeEnum } from '@fastgpt/global/core/module/constants'; import { ModuleTemplateTypeEnum } from '@fastgpt/global/core/module/constants';
/* /*
...@@ -41,6 +41,7 @@ const getPluginTemplateById = async (id: string): Promise<PluginTemplateType> => ...@@ -41,6 +41,7 @@ const getPluginTemplateById = async (id: string): Promise<PluginTemplateType> =>
if (!item) return Promise.reject('plugin not found'); if (!item) return Promise.reject('plugin not found');
return { return {
id: String(item._id), id: String(item._id),
teamId: String(item.teamId),
name: item.name, name: item.name,
avatar: item.avatar, avatar: item.avatar,
intro: item.intro, intro: item.intro,
...@@ -74,16 +75,14 @@ export async function getPluginPreviewModule({ ...@@ -74,16 +75,14 @@ export async function getPluginPreviewModule({
} }
/* run plugin time */ /* run plugin time */
export async function getPluginRuntimeById(id: string): Promise<PluginTemplateType> { export async function getPluginRuntimeById(id: string): Promise<PluginRuntimeType> {
const plugin = await getPluginTemplateById(id); const plugin = await getPluginTemplateById(id);
return { return {
id: plugin.id, teamId: plugin.teamId,
source: plugin.source,
templateType: plugin.templateType,
name: plugin.name, name: plugin.name,
avatar: plugin.avatar, avatar: plugin.avatar,
intro: plugin.intro, showStatus: plugin.showStatus,
modules: plugin.modules modules: plugin.modules
}; };
} }
import TurndownService from 'turndown';
// @ts-ignore
import * as turndownPluginGfm from 'joplin-turndown-plugin-gfm';
const turndownService = new TurndownService({
headingStyle: 'atx',
bulletListMarker: '-',
codeBlockStyle: 'fenced',
fence: '```',
emDelimiter: '_',
strongDelimiter: '**',
linkStyle: 'inlined',
linkReferenceStyle: 'full'
});
export const htmlStr2Md = (html: string) => {
// 浏览器,html字符串转dom
const parser = new DOMParser();
const dom = parser.parseFromString(html, 'text/html');
turndownService.remove(['i', 'script', 'iframe']);
turndownService.addRule('codeBlock', {
filter: 'pre',
replacement(_, node) {
const content = node.textContent?.trim() || '';
// @ts-ignore
const codeName = node?._attrsByQName?.class?.data?.trim() || '';
return `\n\`\`\`${codeName}\n${content}\n\`\`\`\n`;
}
});
turndownService.use(turndownPluginGfm.gfm);
return turndownService.turndown(dom);
};
{ {
"name": "@fastgpt/web", "name": "@fastgpt/web",
"version": "1.0.0", "version": "1.0.0",
"dependencies": {}, "dependencies": {
"devDependencies": {} "joplin-turndown-plugin-gfm": "^1.0.12",
"turndown": "^7.1.2"
},
"devDependencies": {
"@types/turndown": "^5.0.4"
}
} }
...@@ -128,7 +128,18 @@ importers: ...@@ -128,7 +128,18 @@ importers:
specifier: ^0.0.4 specifier: ^0.0.4
version: registry.npmmirror.com/@types/tunnel@0.0.4 version: registry.npmmirror.com/@types/tunnel@0.0.4
packages/web: {} packages/web:
dependencies:
joplin-turndown-plugin-gfm:
specifier: ^1.0.12
version: registry.npmmirror.com/joplin-turndown-plugin-gfm@1.0.12
turndown:
specifier: ^7.1.2
version: registry.npmmirror.com/turndown@7.1.2
devDependencies:
'@types/turndown':
specifier: ^5.0.4
version: registry.npmmirror.com/@types/turndown@5.0.4
projects/app: projects/app:
dependencies: dependencies:
...@@ -4850,6 +4861,12 @@ packages: ...@@ -4850,6 +4861,12 @@ packages:
'@types/node': registry.npmmirror.com/@types/node@20.8.5 '@types/node': registry.npmmirror.com/@types/node@20.8.5
dev: true dev: true
registry.npmmirror.com/@types/turndown@5.0.4:
resolution: {integrity: sha512-28GI33lCCkU4SGH1GvjDhFgOVr+Tym4PXGBIU1buJUa6xQolniPArtUT+kv42RR2N9MsMLInkr904Aq+ESHBJg==, registry: https://registry.npm.taobao.org/, tarball: https://registry.npmmirror.com/@types/turndown/-/turndown-5.0.4.tgz}
name: '@types/turndown'
version: 5.0.4
dev: true
registry.npmmirror.com/@types/unist@2.0.10: registry.npmmirror.com/@types/unist@2.0.10:
resolution: {integrity: sha512-IfYcSBWE3hLpBg8+X2SEa8LVkJdJEkT2Ese2aaLs3ptGdVtABxndrMaxuFlQ1qdFf9Q5rDvDpxI3WwgvKFAsQA==, registry: https://registry.npm.taobao.org/, tarball: https://registry.npmmirror.com/@types/unist/-/unist-2.0.10.tgz} resolution: {integrity: sha512-IfYcSBWE3hLpBg8+X2SEa8LVkJdJEkT2Ese2aaLs3ptGdVtABxndrMaxuFlQ1qdFf9Q5rDvDpxI3WwgvKFAsQA==, registry: https://registry.npm.taobao.org/, tarball: https://registry.npmmirror.com/@types/unist/-/unist-2.0.10.tgz}
name: '@types/unist' name: '@types/unist'
...@@ -6756,6 +6773,12 @@ packages: ...@@ -6756,6 +6773,12 @@ packages:
domelementtype: registry.npmmirror.com/domelementtype@2.3.0 domelementtype: registry.npmmirror.com/domelementtype@2.3.0
dev: false dev: false
registry.npmmirror.com/domino@2.1.6:
resolution: {integrity: sha512-3VdM/SXBZX2omc9JF9nOPCtDaYQ67BGp5CoLpIQlO2KCAPETs8TcDHacF26jXadGbvUteZzRTeos2fhID5+ucQ==, registry: https://registry.npm.taobao.org/, tarball: https://registry.npmmirror.com/domino/-/domino-2.1.6.tgz}
name: domino
version: 2.1.6
dev: false
registry.npmmirror.com/dompurify@3.0.3: registry.npmmirror.com/dompurify@3.0.3:
resolution: {integrity: sha512-axQ9zieHLnAnHh0sfAamKYiqXMJAVwu+LM/alQ7WDagoWessyWvMSFyW65CqF3owufNu8HBcE4cM2Vflu7YWcQ==, registry: https://registry.npm.taobao.org/, tarball: https://registry.npmmirror.com/dompurify/-/dompurify-3.0.3.tgz} resolution: {integrity: sha512-axQ9zieHLnAnHh0sfAamKYiqXMJAVwu+LM/alQ7WDagoWessyWvMSFyW65CqF3owufNu8HBcE4cM2Vflu7YWcQ==, registry: https://registry.npm.taobao.org/, tarball: https://registry.npmmirror.com/dompurify/-/dompurify-3.0.3.tgz}
name: dompurify name: dompurify
...@@ -8772,6 +8795,12 @@ packages: ...@@ -8772,6 +8795,12 @@ packages:
set-function-name: registry.npmmirror.com/set-function-name@2.0.1 set-function-name: registry.npmmirror.com/set-function-name@2.0.1
dev: true dev: true
registry.npmmirror.com/joplin-turndown-plugin-gfm@1.0.12:
resolution: {integrity: sha512-qL4+1iycQjZ1fs8zk3jSRk7cg3ROBUHk7GKtiLAQLFzLPKErnILUvz5DLszSQvz3s1sTjPbywLDISVUtBY6HaA==, registry: https://registry.npm.taobao.org/, tarball: https://registry.npmmirror.com/joplin-turndown-plugin-gfm/-/joplin-turndown-plugin-gfm-1.0.12.tgz}
name: joplin-turndown-plugin-gfm
version: 1.0.12
dev: false
registry.npmmirror.com/js-sdsl@4.4.2: registry.npmmirror.com/js-sdsl@4.4.2:
resolution: {integrity: sha512-dwXFwByc/ajSV6m5bcKAPwe4yDDF6D614pxmIi5odytzxRlwqF6nwoiCek80Ixc7Cvma5awClxrzFtxCQvcM8w==, registry: https://registry.npm.taobao.org/, tarball: https://registry.npmmirror.com/js-sdsl/-/js-sdsl-4.4.2.tgz} resolution: {integrity: sha512-dwXFwByc/ajSV6m5bcKAPwe4yDDF6D614pxmIi5odytzxRlwqF6nwoiCek80Ixc7Cvma5awClxrzFtxCQvcM8w==, registry: https://registry.npm.taobao.org/, tarball: https://registry.npmmirror.com/js-sdsl/-/js-sdsl-4.4.2.tgz}
name: js-sdsl name: js-sdsl
...@@ -12166,6 +12195,14 @@ packages: ...@@ -12166,6 +12195,14 @@ packages:
engines: {node: '>=0.6.11 <=0.7.0 || >=0.7.3'} engines: {node: '>=0.6.11 <=0.7.0 || >=0.7.3'}
dev: false dev: false
registry.npmmirror.com/turndown@7.1.2:
resolution: {integrity: sha512-ntI9R7fcUKjqBP6QU8rBK2Ehyt8LAzt3UBT9JR9tgo6GtuKvyUzpayWmeMKJw1DPdXzktvtIT8m2mVXz+bL/Qg==, registry: https://registry.npm.taobao.org/, tarball: https://registry.npmmirror.com/turndown/-/turndown-7.1.2.tgz}
name: turndown
version: 7.1.2
dependencies:
domino: registry.npmmirror.com/domino@2.1.6
dev: false
registry.npmmirror.com/type-check@0.4.0: registry.npmmirror.com/type-check@0.4.0:
resolution: {integrity: sha512-XleUoc9uwGXqjWwXaUTZAmzMcFZ5858QA2vvx1Ur5xIcixXIP+8LnFDgRplU30us6teqdlskFfu+ae4K79Ooew==, registry: https://registry.npm.taobao.org/, tarball: https://registry.npmmirror.com/type-check/-/type-check-0.4.0.tgz} resolution: {integrity: sha512-XleUoc9uwGXqjWwXaUTZAmzMcFZ5858QA2vvx1Ur5xIcixXIP+8LnFDgRplU30us6teqdlskFfu+ae4K79Ooew==, registry: https://registry.npm.taobao.org/, tarball: https://registry.npmmirror.com/type-check/-/type-check-0.4.0.tgz}
name: type-check name: type-check
......
...@@ -7,10 +7,10 @@ ...@@ -7,10 +7,10 @@
}, },
"ChatModels": [ "ChatModels": [
{ {
"model": "gpt-3.5-turbo-1106", "model": "gpt-3.5-turbo",
"name": "GPT35-1106", "name": "GPT35",
"price": 0, "price": 0,
"maxContext": 16000, "maxContext": 4000,
"maxResponse": 4000, "maxResponse": 4000,
"quoteMaxToken": 2000, "quoteMaxToken": 2000,
"maxTemperature": 1.2, "maxTemperature": 1.2,
...@@ -71,7 +71,7 @@ ...@@ -71,7 +71,7 @@
"maxContext": 4000, "maxContext": 4000,
"maxResponse": 4000, "maxResponse": 4000,
"price": 0, "price": 0,
"functionCall": true, "toolChoice": true,
"functionPrompt": "" "functionPrompt": ""
}, },
{ {
...@@ -80,7 +80,7 @@ ...@@ -80,7 +80,7 @@
"maxContext": 8000, "maxContext": 8000,
"maxResponse": 8000, "maxResponse": 8000,
"price": 0, "price": 0,
"functionCall": true, "toolChoice": true,
"functionPrompt": "" "functionPrompt": ""
} }
], ],
...@@ -91,7 +91,7 @@ ...@@ -91,7 +91,7 @@
"maxContext": 16000, "maxContext": 16000,
"maxResponse": 4000, "maxResponse": 4000,
"price": 0, "price": 0,
"functionCall": true, "toolChoice": true,
"functionPrompt": "" "functionPrompt": ""
} }
], ],
......
...@@ -10,6 +10,9 @@ ...@@ -10,6 +10,9 @@
"quoteTemplate": false, "quoteTemplate": false,
"quotePrompt": false "quotePrompt": false
}, },
"cfr": {
"background": true
},
"dataset": { "dataset": {
"datasets": true, "datasets": true,
"similarity": false, "similarity": false,
......
### Fast GPT V4.6.4 ### Fast GPT V4.6.5
1. 重写 - 分享链接身份逻辑,采用 localID 记录用户的ID。 1. 新增 - [问题补全模块](https://doc.fastgpt.in/docs/workflow/modules/coreferenceresolution/)
2. 商业版新增 - 分享链接 SSO 方案,通过`身份鉴权`地址,仅需`3个接口`即可完全接入已有用户系统。具体参考[分享链接身份鉴权](https://doc.fastgpt.in/docs/development/openapi/share/) 2. 新增 - [文本编辑模块](https://doc.fastgpt.in/docs/workflow/modules/text_editor/)
3. 新增 - 分享链接更多嵌入方式提示,更多DIY方式。 3. 新增 - [判断器模块](https://doc.fastgpt.in/docs/workflow/modules/tfswitch/)
4. 优化 - 历史记录模块。弃用旧的历史记录模块,直接在对应地方填写数值即可。 4. 新增 - [自定义反馈模块](https://doc.fastgpt.in/docs/workflow/modules/custom_feedback/)
5. 调整 - 知识库搜索模块 topk 逻辑,采用 MaxToken 计算,兼容不同长度的文本块 5. 新增 - 【内容提取】模块支持选择模型,以及字段枚举
6. 链接读取支持多选择器。参考[Web 站点同步用法](https://doc.fastgpt.in/docs/course/websync) 6. 优化 - docx读取,兼容表格(表格转markdown)
7. [知识库结构详解](https://doc.fastgpt.in/docs/use-cases/datasetengine/) 7. 优化 - 高级编排连接线交互
8. [知识库提示词详解](https://doc.fastgpt.in/docs/use-cases/ai_settings/#引用模板--引用提示词) 8. 优化 - 由于 html2md 导致的 cpu密集计算,阻断线程问题
9. [使用文档](https://doc.fastgpt.in/docs/intro/) 9. 修复 - 高级编排提示词提取描述
10. [点击查看高级编排介绍文档](https://doc.fastgpt.in/docs/workflow) 10. [使用文档](https://doc.fastgpt.in/docs/intro/)
11. [点击查看商业版](https://doc.fastgpt.in/docs/commercial/) 11. [点击查看高级编排介绍文档](https://doc.fastgpt.in/docs/workflow)
12. [点击查看商业版](https://doc.fastgpt.in/docs/commercial/)
<?xml version="1.0" standalone="no"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg t="1703041511149" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="7024" xmlns:xlink="http://www.w3.org/1999/xlink" width="128" height="128"><path d="M512.512 128a384 384 0 1 1-384 384 384 384 0 0 1 384-384z m0 96a288 288 0 1 0 288 288 288 288 0 0 0-288-288z" fill="#3671FD" opacity=".2" p-id="7025"></path><path d="M512.512 64a448 448 0 1 1-302.56 117.6A32.032 32.032 0 1 1 253.312 228.8a384 384 0 1 0 298.016-98.88l-6.816-0.608v140.032a32 32 0 0 1-28.256 31.776l-3.744 0.224a32 32 0 0 1-31.776-28.288l-0.224-3.712V64z" fill="#3671FD" p-id="7026"></path><path d="M336.32 313.376l216.224 165.344a52.288 52.288 0 1 1-73.28 73.312l-165.376-216.224a16 16 0 0 1 22.4-22.4z" fill="#FE9C23" p-id="7027"></path></svg>
\ No newline at end of file
...@@ -245,7 +245,9 @@ ...@@ -245,7 +245,9 @@
"Out Ad Edit": "You are about to exit the Advanced orchestration page, please confirm", "Out Ad Edit": "You are about to exit the Advanced orchestration page, please confirm",
"Prompt Editor": "Prompt Editor", "Prompt Editor": "Prompt Editor",
"Save and out": "Save out", "Save and out": "Save out",
"UnSave": "UnSave" "UnSave": "UnSave",
"cfr background prompt": "Question completion - Chat background description",
"cfr background tip": "Describing the scope of the current conversation makes it easier for AI to complete first or vague questions, thereby enhancing the knowledge base's ability to continue conversations. \nIf is empty, the problem completion function is not used."
}, },
"feedback": { "feedback": {
"Custom feedback": "Custom feedback", "Custom feedback": "Custom feedback",
...@@ -295,7 +297,10 @@ ...@@ -295,7 +297,10 @@
"Stop Speak": "Stop Speak", "Stop Speak": "Stop Speak",
"Type a message": "Input problem", "Type a message": "Input problem",
"error": { "error": {
"Messages empty": "Interface content is empty, maybe the text is too long ~" "Messages empty": "Interface content is empty, maybe the text is too long ~",
"Select dataset empty": "You didn't choose any dataset.",
"user input empty": "User question is empty",
"Chat error": "Chat error"
}, },
"feedback": { "feedback": {
"Close User Good Feedback": "", "Close User Good Feedback": "",
...@@ -315,6 +320,7 @@ ...@@ -315,6 +320,7 @@
"Read Source": "Read Source" "Read Source": "Read Source"
}, },
"response": { "response": {
"Plugin Resonse Detail": "Plugin Detail",
"context total length": "Context Length", "context total length": "Context Length",
"module cq": "Question classification list", "module cq": "Question classification list",
"module cq result": "Classification Result", "module cq result": "Classification Result",
...@@ -541,6 +547,7 @@ ...@@ -541,6 +547,7 @@
"Http Request Url": "", "Http Request Url": "",
"TFSwitch textarea": "", "TFSwitch textarea": "",
"anyInput": "", "anyInput": "",
"cfr background": "The background knowledge of the current conversation makes it easy to complete the first question and the fuzzy question, and only needs to briefly describe the scope of the current conversation.",
"dynamic input": "", "dynamic input": "",
"textEditor textarea": "The passed variable can be referenced by {{key}}." "textEditor textarea": "The passed variable can be referenced by {{key}}."
}, },
...@@ -549,11 +556,16 @@ ...@@ -549,11 +556,16 @@
"Http Request Method": "", "Http Request Method": "",
"Http Request Url": "", "Http Request Url": "",
"TFSwitch textarea": "", "TFSwitch textarea": "",
"aiModel": "",
"anyInput": "", "anyInput": "",
"cfr background": "Background",
"chat history": "chat history", "chat history": "chat history",
"switch": "Switch", "switch": "Switch",
"textEditor textarea": "Text Edit", "textEditor textarea": "Text Edit",
"user question": "User question" "user question": "User question"
},
"placeholder": {
"cfr background": "Questions about the introduction and use of python. \nThe current dialogue is related to the game GTA5."
} }
}, },
"inputType": { "inputType": {
...@@ -574,6 +586,7 @@ ...@@ -574,6 +586,7 @@
"running done": "Triggered when the module call ends" "running done": "Triggered when the module call ends"
}, },
"label": { "label": {
"cfr result": "",
"result false": "", "result false": "",
"result true": "", "result true": "",
"running done": "End of module call ", "running done": "End of module call ",
...@@ -584,6 +597,8 @@ ...@@ -584,6 +597,8 @@
"TFSwitch": "", "TFSwitch": "",
"TFSwitch intro": "", "TFSwitch intro": "",
"UnKnow Module": "UnKnow Module", "UnKnow Module": "UnKnow Module",
"cfr": "",
"cfr intro": "Refine the current issue based on history, making it more conducive to knowledge base search, while improving continuous conversation capabilities.",
"textEditor": "Text Editor", "textEditor": "Text Editor",
"textEditor intro": "Output of fixed or incoming text after edit" "textEditor intro": "Output of fixed or incoming text after edit"
}, },
......
...@@ -239,13 +239,17 @@ ...@@ -239,13 +239,17 @@
"TTS": "语音播报", "TTS": "语音播报",
"TTS Tip": "开启后,每次对话后可使用语音播放功能。使用该功能可能产生额外费用。", "TTS Tip": "开启后,每次对话后可使用语音播放功能。使用该功能可能产生额外费用。",
"Welcome Text": "对话开场白", "Welcome Text": "对话开场白",
"Chat Variable": "对话框变量",
"Question Guide": "问题引导",
"create app": "创建属于你的 AI 应用", "create app": "创建属于你的 AI 应用",
"edit": { "edit": {
"Confirm Save App Tip": "该应用可能为高级编排模式,保存后将会覆盖高级编排配置,请确认!", "Confirm Save App Tip": "该应用可能为高级编排模式,保存后将会覆盖高级编排配置,请确认!",
"Out Ad Edit": "您即将退出高级编排页面,请确认", "Out Ad Edit": "您即将退出高级编排页面,请确认",
"Prompt Editor": "提示词编辑", "Prompt Editor": "提示词编辑",
"Save and out": "保存并退出", "Save and out": "保存并退出",
"UnSave": "不保存" "UnSave": "不保存",
"cfr background prompt": "问题补全 - 对话背景描述",
"cfr background tip": "描述当前对话的范围,便于AI补全首次问题或模糊的问题,从而增强知识库连续对话的能力。\n为空时,表示不使用问题补全功能。"
}, },
"feedback": { "feedback": {
"Custom feedback": "自定义反馈", "Custom feedback": "自定义反馈",
...@@ -295,7 +299,10 @@ ...@@ -295,7 +299,10 @@
"Stop Speak": "停止录音", "Stop Speak": "停止录音",
"Type a message": "输入问题", "Type a message": "输入问题",
"error": { "error": {
"Messages empty": "接口内容为空,可能文本超长了~" "Messages empty": "接口内容为空,可能文本超长了~",
"Select dataset empty": "你没有选择知识库",
"user input empty": "传入的用户问题为空",
"Chat error": "对话出现异常"
}, },
"feedback": { "feedback": {
"Close User Good Feedback": "", "Close User Good Feedback": "",
...@@ -315,6 +322,7 @@ ...@@ -315,6 +322,7 @@
"Read Source": "查看来源" "Read Source": "查看来源"
}, },
"response": { "response": {
"Plugin Resonse Detail": "插件详情",
"context total length": "上下文总长度", "context total length": "上下文总长度",
"module cq": "问题分类列表", "module cq": "问题分类列表",
"module cq result": "分类结果", "module cq result": "分类结果",
...@@ -479,7 +487,7 @@ ...@@ -479,7 +487,7 @@
"embeddingReRank": "增强语义检索", "embeddingReRank": "增强语义检索",
"embeddingReRank desc": "超额进行向量 topk 查询后再使用 Rerank 进行排序,相关度通常差异明显。" "embeddingReRank desc": "超额进行向量 topk 查询后再使用 Rerank 进行排序,相关度通常差异明显。"
}, },
"search mode": "检索模式" "search mode": "搜索模式"
}, },
"status": { "status": {
"active": "已就绪", "active": "已就绪",
...@@ -541,6 +549,7 @@ ...@@ -541,6 +549,7 @@
"Http Request Url": "新的HTTP请求地址。如果出现两个“请求地址”,可以删除该模块重新加入,会拉取最新的模块配置。", "Http Request Url": "新的HTTP请求地址。如果出现两个“请求地址”,可以删除该模块重新加入,会拉取最新的模块配置。",
"TFSwitch textarea": "允许定义一些字符串来实现 false 匹配,每行一个,支持正则表达式。", "TFSwitch textarea": "允许定义一些字符串来实现 false 匹配,每行一个,支持正则表达式。",
"anyInput": "可传入任意内容", "anyInput": "可传入任意内容",
"cfr background": "描述当前对话的范围,便于AI补全首次问题或模糊的问题,从而增强知识库连续对话的能力。\n为空时,表示【首次对话】不使用问题补全功能。",
"dynamic input": "接收用户动态添加的参数,会在运行时将这些参数平铺传入", "dynamic input": "接收用户动态添加的参数,会在运行时将这些参数平铺传入",
"textEditor textarea": "可以通过 {{key}} 的方式引用传入的变量。变量仅支持字符串或数字。" "textEditor textarea": "可以通过 {{key}} 的方式引用传入的变量。变量仅支持字符串或数字。"
}, },
...@@ -549,11 +558,16 @@ ...@@ -549,11 +558,16 @@
"Http Request Method": "请求方式", "Http Request Method": "请求方式",
"Http Request Url": "请求地址", "Http Request Url": "请求地址",
"TFSwitch textarea": "自定义 False 匹配规则", "TFSwitch textarea": "自定义 False 匹配规则",
"aiModel": "AI 模型",
"anyInput": "任意内容输入", "anyInput": "任意内容输入",
"cfr background": "背景知识",
"chat history": "聊天记录", "chat history": "聊天记录",
"switch": "触发器", "switch": "触发器",
"textEditor textarea": "文本编辑", "textEditor textarea": "文本编辑",
"user question": "用户问题" "user question": "用户问题"
},
"placeholder": {
"cfr background": "关于 python 的介绍和使用等问题。\n当前对话与游戏《GTA5》有关。"
} }
}, },
"inputType": { "inputType": {
...@@ -574,6 +588,7 @@ ...@@ -574,6 +588,7 @@
"running done": "模块调用结束时触发" "running done": "模块调用结束时触发"
}, },
"label": { "label": {
"cfr result": "补全结果",
"result false": "False", "result false": "False",
"result true": "True", "result true": "True",
"running done": "模块调用结束", "running done": "模块调用结束",
...@@ -584,6 +599,8 @@ ...@@ -584,6 +599,8 @@
"TFSwitch": "判断器", "TFSwitch": "判断器",
"TFSwitch intro": "根据传入的内容进行 True False 输出。默认情况下,当传入的内容为 false, undefined, null, 0, none 时,会输出 false。你也可以增加一些自定义的字符串来补充输出 false 的内容。", "TFSwitch intro": "根据传入的内容进行 True False 输出。默认情况下,当传入的内容为 false, undefined, null, 0, none 时,会输出 false。你也可以增加一些自定义的字符串来补充输出 false 的内容。",
"UnKnow Module": "未知模块", "UnKnow Module": "未知模块",
"cfr": "问题补全",
"cfr intro": "根据历史记录,完善当前问题,使其更利于知识库搜索,同时提高连续对话能力。",
"textEditor": "文本加工", "textEditor": "文本加工",
"textEditor intro": "可对固定或传入的文本进行加工后输出" "textEditor intro": "可对固定或传入的文本进行加工后输出"
}, },
......
...@@ -26,6 +26,43 @@ const QuoteModal = ({ ...@@ -26,6 +26,43 @@ const QuoteModal = ({
isShare: boolean; isShare: boolean;
}) => { }) => {
const { t } = useTranslation(); const { t } = useTranslation();
return (
<>
<MyModal
isOpen={true}
onClose={onClose}
h={['90vh', '80vh']}
isCentered
minW={['90vw', '600px']}
iconSrc="/imgs/modal/quote.svg"
title={
<Box>
{t('core.chat.Quote Amount', { amount: rawSearch.length })}
<Box fontSize={'sm'} color={'myGray.500'} fontWeight={'normal'}>
{t('core.chat.quote.Quote Tip')}
</Box>
</Box>
}
>
<ModalBody whiteSpace={'pre-wrap'} textAlign={'justify'} wordBreak={'break-all'}>
<QuoteList rawSearch={rawSearch} isShare={isShare} />
</ModalBody>
</MyModal>
</>
);
};
export default QuoteModal;
export const QuoteList = React.memo(function QuoteList({
rawSearch = [],
isShare
}: {
rawSearch: SearchDataResponseItemType[];
isShare: boolean;
}) {
const { t } = useTranslation();
const { isPc } = useSystemStore(); const { isPc } = useSystemStore();
const theme = useTheme(); const theme = useTheme();
const { toast } = useToast(); const { toast } = useToast();
...@@ -60,124 +97,104 @@ const QuoteModal = ({ ...@@ -60,124 +97,104 @@ const QuoteModal = ({
return ( return (
<> <>
<MyModal {rawSearch.map((item, i) => (
isOpen={true} <Box
onClose={onClose} key={i}
h={['90vh', '80vh']} flex={'1 0 0'}
isCentered p={2}
minW={['90vw', '600px']} borderRadius={'lg'}
iconSrc="/imgs/modal/quote.svg" border={theme.borders.base}
title={ _notLast={{ mb: 2 }}
<Box> position={'relative'}
{t('core.chat.Quote Amount', { amount: rawSearch.length })} overflow={'hidden'}
<Box fontSize={'sm'} color={'myGray.500'} fontWeight={'normal'}> _hover={{ '& .hover-data': { display: 'flex' } }}
{t('core.chat.quote.Quote Tip')} bg={i % 2 === 0 ? 'white' : 'myWhite.500'}
</Box> >
</Box> <Flex alignItems={'flex-end'} mb={3} fontSize={'sm'}>
} <RawSourceText
> fontWeight={'bold'}
<ModalBody whiteSpace={'pre-wrap'} textAlign={'justify'} wordBreak={'break-all'}> color={'black'}
{rawSearch.map((item, i) => ( sourceName={item.sourceName}
<Box sourceId={item.sourceId}
key={i} canView={!isShare}
flex={'1 0 0'} />
p={2} <Box flex={1} />
borderRadius={'lg'} {!isShare && (
border={theme.borders.base} <Link
_notLast={{ mb: 2 }} as={NextLink}
position={'relative'} className="hover-data"
overflow={'hidden'} display={'none'}
_hover={{ '& .hover-data': { display: 'flex' } }} alignItems={'center'}
bg={i % 2 === 0 ? 'white' : 'myWhite.500'} color={'blue.500'}
> href={`/dataset/detail?datasetId=${item.datasetId}&currentTab=dataCard&collectionId=${item.collectionId}`}
<Flex alignItems={'flex-end'} mb={3} fontSize={'sm'}> >
<RawSourceText {t('core.dataset.Go Dataset')}
fontWeight={'bold'} <MyIcon name={'common/rightArrowLight'} w={'10px'} />
color={'black'} </Link>
sourceName={item.sourceName} )}
sourceId={item.sourceId} </Flex>
canView={!isShare}
/>
<Box flex={1} />
{!isShare && (
<Link
as={NextLink}
className="hover-data"
display={'none'}
alignItems={'center'}
color={'blue.500'}
href={`/dataset/detail?datasetId=${item.datasetId}&currentTab=dataCard&collectionId=${item.collectionId}`}
>
{t('core.dataset.Go Dataset')}
<MyIcon name={'common/rightArrowLight'} w={'10px'} />
</Link>
)}
</Flex>
<Box color={'black'}>{item.q}</Box> <Box color={'black'}>{item.q}</Box>
<Box color={'myGray.600'}>{item.a}</Box> <Box color={'myGray.600'}>{item.a}</Box>
{!isShare && ( {!isShare && (
<Flex alignItems={'center'} fontSize={'sm'} mt={3} gap={4} color={'myGray.500'}> <Flex alignItems={'center'} fontSize={'sm'} mt={3} gap={4} color={'myGray.500'}>
{isPc && ( {isPc && (
<MyTooltip label={t('core.dataset.data.id')}> <MyTooltip label={t('core.dataset.data.id')}>
<Flex border={theme.borders.base} py={'1px'} px={3} borderRadius={'3px'}> <Flex border={theme.borders.base} py={'1px'} px={3} borderRadius={'3px'}>
# {item.id} # {item.id}
</Flex> </Flex>
</MyTooltip> </MyTooltip>
)} )}
<MyTooltip label={t('core.dataset.Quote Length')}> <MyTooltip label={t('core.dataset.Quote Length')}>
<Flex alignItems={'center'}> <Flex alignItems={'center'}>
<MyIcon name="common/text/t" w={'14px'} mr={1} color={'myGray.500'} /> <MyIcon name="common/text/t" w={'14px'} mr={1} color={'myGray.500'} />
{item.q.length + (item.a?.length || 0)} {item.q.length + (item.a?.length || 0)}
</Flex>
</MyTooltip>
{!isShare && item.score && (
<MyTooltip label={t('core.dataset.Similarity')}>
<Flex alignItems={'center'}>
<MyIcon name={'kbTest'} w={'12px'} />
<Progress
mx={2}
w={['60px', '90px']}
value={item.score * 100}
size="sm"
borderRadius={'20px'}
colorScheme="myGray"
border={theme.borders.base}
/>
<Box>{item.score.toFixed(4)}</Box>
</Flex>
</MyTooltip>
)}
<Box flex={1} />
{item.id && (
<MyTooltip label={t('core.dataset.data.Edit')}>
<Box
bg={'rgba(255,255,255,0.9)'}
alignItems={'center'}
justifyContent={'center'}
boxShadow={'-10px 0 10px rgba(255,255,255,1)'}
>
<MyIcon
name={'edit'}
w={['16px', '18px']}
h={['16px', '18px']}
cursor={'pointer'}
color={'myGray.600'}
_hover={{
color: 'blue.600'
}}
onClick={() => onclickEdit(item)}
/>
</Box>
</MyTooltip>
)}
</Flex> </Flex>
</MyTooltip>
{!isShare && item.score && (
<MyTooltip label={t('core.dataset.Similarity')}>
<Flex alignItems={'center'}>
<MyIcon name={'kbTest'} w={'12px'} />
<Progress
mx={2}
w={['60px', '90px']}
value={item.score * 100}
size="sm"
borderRadius={'20px'}
colorScheme="myGray"
border={theme.borders.base}
/>
<Box>{item.score.toFixed(4)}</Box>
</Flex>
</MyTooltip>
)} )}
</Box> <Box flex={1} />
))} {item.id && (
</ModalBody> <MyTooltip label={t('core.dataset.data.Edit')}>
<Loading fixed={false} /> <Box
</MyModal> bg={'rgba(255,255,255,0.9)'}
alignItems={'center'}
justifyContent={'center'}
boxShadow={'-10px 0 10px rgba(255,255,255,1)'}
>
<MyIcon
name={'edit'}
w={['16px', '18px']}
h={['16px', '18px']}
cursor={'pointer'}
color={'myGray.600'}
_hover={{
color: 'blue.600'
}}
onClick={() => onclickEdit(item)}
/>
</Box>
</MyTooltip>
)}
</Flex>
)}
</Box>
))}
{editInputData && editInputData.id && ( {editInputData && editInputData.id && (
<InputDataModal <InputDataModal
onClose={() => setEditInputData(undefined)} onClose={() => setEditInputData(undefined)}
...@@ -191,8 +208,7 @@ const QuoteModal = ({ ...@@ -191,8 +208,7 @@ const QuoteModal = ({
collectionId={editInputData.collectionId} collectionId={editInputData.collectionId}
/> />
)} )}
<Loading fixed={false} />
</> </>
); );
}; });
export default QuoteModal;
...@@ -222,7 +222,11 @@ const ResponseTags = ({ ...@@ -222,7 +222,11 @@ const ResponseTags = ({
<ContextModal context={contextModalData} onClose={() => setContextModalData(undefined)} /> <ContextModal context={contextModalData} onClose={() => setContextModalData(undefined)} />
)} )}
{isOpenWholeModal && ( {isOpenWholeModal && (
<WholeResponseModal response={responseData} onClose={onCloseWholeModal} /> <WholeResponseModal
response={responseData}
isShare={isShare}
onClose={onCloseWholeModal}
/>
)} )}
</Flex> </Flex>
</> </>
......
...@@ -349,7 +349,13 @@ const ChatBox = ( ...@@ -349,7 +349,13 @@ const ChatBox = (
responseText, responseText,
isNewChat = false isNewChat = false
} = await onStartChat({ } = await onStartChat({
chatList: newChatList, chatList: newChatList.map((item) => ({
dataId: item.dataId,
obj: item.obj,
value: item.value,
status: item.status,
moduleName: item.moduleName
})),
messages, messages,
controller: abortSignal, controller: abortSignal,
generatingMessage, generatingMessage,
...@@ -386,7 +392,7 @@ const ChatBox = ( ...@@ -386,7 +392,7 @@ const ChatBox = (
}, 100); }, 100);
} catch (err: any) { } catch (err: any) {
toast({ toast({
title: getErrText(err, '聊天出错了~'), title: t(getErrText(err, 'core.chat.error.Chat error')),
status: 'error', status: 'error',
duration: 5000, duration: 5000,
isClosable: true isClosable: true
...@@ -419,7 +425,8 @@ const ChatBox = ( ...@@ -419,7 +425,8 @@ const ChatBox = (
generatingMessage, generatingMessage,
createQuestionGuide, createQuestionGuide,
generatingScroll, generatingScroll,
isPc isPc,
t
] ]
); );
......
...@@ -39,7 +39,7 @@ const Layout = ({ children }: { children: JSX.Element }) => { ...@@ -39,7 +39,7 @@ const Layout = ({ children }: { children: JSX.Element }) => {
const router = useRouter(); const router = useRouter();
const { colorMode, setColorMode } = useColorMode(); const { colorMode, setColorMode } = useColorMode();
const { Loading } = useLoading(); const { Loading } = useLoading();
const { loading, setScreenWidth, isPc, loadGitStar } = useSystemStore(); const { loading, setScreenWidth, isPc } = useSystemStore();
const { userInfo } = useUserStore(); const { userInfo } = useUserStore();
const isChatPage = useMemo( const isChatPage = useMemo(
...@@ -61,12 +61,11 @@ const Layout = ({ children }: { children: JSX.Element }) => { ...@@ -61,12 +61,11 @@ const Layout = ({ children }: { children: JSX.Element }) => {
window.addEventListener('resize', resize); window.addEventListener('resize', resize);
resize(); resize();
loadGitStar();
return () => { return () => {
window.removeEventListener('resize', resize); window.removeEventListener('resize', resize);
}; };
}, [loadGitStar, setScreenWidth]); }, [setScreenWidth]);
const { data: unread = 0 } = useQuery(['getUnreadCount'], getUnreadCount, { const { data: unread = 0 } = useQuery(['getUnreadCount'], getUnreadCount, {
enabled: !!userInfo && !!feConfigs.isPlus, enabled: !!userInfo && !!feConfigs.isPlus,
......
...@@ -346,7 +346,7 @@ ...@@ -346,7 +346,7 @@
width: 100%; width: 100%;
* { * {
word-break: break-all; word-break: break-word;
} }
pre { pre {
......
...@@ -19,49 +19,51 @@ type Props = TextareaProps & { ...@@ -19,49 +19,51 @@ type Props = TextareaProps & {
// variables: string[]; // variables: string[];
}; };
const PromptTextarea = (props: Props) => { const PromptTextarea = React.forwardRef<HTMLTextAreaElement, Props>(
const ModalTextareaRef = useRef<HTMLTextAreaElement>(null); function PromptTextarea(props, ref) {
const TextareaRef = useRef<HTMLTextAreaElement>(null); const ModalTextareaRef = useRef<HTMLTextAreaElement>(null);
const TextareaRef = useRef<HTMLTextAreaElement>(null);
const { t } = useTranslation(); const { t } = useTranslation();
const { title = t('core.app.edit.Prompt Editor'), value, ...childProps } = props; const { title = t('core.app.edit.Prompt Editor'), ...childProps } = props;
const { isOpen, onOpen, onClose } = useDisclosure(); const { isOpen, onOpen, onClose } = useDisclosure();
return ( return (
<> <>
<Editor textareaRef={TextareaRef} {...childProps} onOpenModal={onOpen} /> <Editor textareaRef={TextareaRef} {...childProps} onOpenModal={onOpen} />
{isOpen && ( {isOpen && (
<MyModal iconSrc="/imgs/modal/edit.svg" title={title} isOpen onClose={onClose}> <MyModal iconSrc="/imgs/modal/edit.svg" title={title} isOpen onClose={onClose}>
<ModalBody> <ModalBody>
<Editor <Editor
textareaRef={ModalTextareaRef} textareaRef={ModalTextareaRef}
{...childProps} {...childProps}
minH={'300px'} minH={'300px'}
maxH={'auto'} maxH={'auto'}
minW={['100%', '512px']} minW={['100%', '512px']}
/> />
</ModalBody> </ModalBody>
<ModalFooter> <ModalFooter>
<Button <Button
onClick={() => { onClick={() => {
if (ModalTextareaRef.current && TextareaRef.current) { if (ModalTextareaRef.current && TextareaRef.current) {
TextareaRef.current.value = ModalTextareaRef.current.value; TextareaRef.current.value = ModalTextareaRef.current.value;
} }
onClose(); onClose();
}} }}
> >
{t('common.Confirm')} {t('common.Confirm')}
</Button> </Button>
</ModalFooter> </ModalFooter>
</MyModal> </MyModal>
)} )}
</> </>
); );
}; }
);
export default PromptTextarea; export default React.memo(PromptTextarea);
const Editor = React.memo(function Editor({ const Editor = React.memo(function Editor({
onOpenModal, onOpenModal,
...@@ -75,7 +77,7 @@ const Editor = React.memo(function Editor({ ...@@ -75,7 +77,7 @@ const Editor = React.memo(function Editor({
return ( return (
<Box h={'100%'} w={'100%'} position={'relative'}> <Box h={'100%'} w={'100%'} position={'relative'}>
<Textarea ref={textareaRef} wordBreak={'break-all'} maxW={'100%'} {...props} /> <Textarea ref={textareaRef} textAlign={'justify'} maxW={'100%'} {...props} />
{onOpenModal && ( {onOpenModal && (
<Box <Box
zIndex={1} zIndex={1}
......
import React from 'react'; import React from 'react';
import { SmoothStepEdge, EdgeLabelRenderer, EdgeProps, getSmoothStepPath } from 'reactflow'; import {
BezierEdge,
getBezierPath,
EdgeLabelRenderer,
EdgeProps,
getSmoothStepPath
} from 'reactflow';
import { Flex } from '@chakra-ui/react'; import { Flex } from '@chakra-ui/react';
import MyIcon from '@/components/Icon'; import MyIcon from '@/components/Icon';
...@@ -21,7 +27,7 @@ const ButtonEdge = ( ...@@ -21,7 +27,7 @@ const ButtonEdge = (
style = {} style = {}
} = props; } = props;
const [edgePath, labelX, labelY] = getSmoothStepPath({ const [edgePath, labelX, labelY] = getBezierPath({
sourceX, sourceX,
sourceY, sourceY,
sourcePosition, sourcePosition,
...@@ -42,7 +48,7 @@ const ButtonEdge = ( ...@@ -42,7 +48,7 @@ const ButtonEdge = (
return ( return (
<> <>
<SmoothStepEdge {...props} style={edgeStyle} /> <BezierEdge {...props} style={edgeStyle} />
<EdgeLabelRenderer> <EdgeLabelRenderer>
<Flex <Flex
alignItems={'center'} alignItems={'center'}
......
...@@ -14,7 +14,7 @@ import 'reactflow/dist/style.css'; ...@@ -14,7 +14,7 @@ import 'reactflow/dist/style.css';
import type { ModuleItemType } from '@fastgpt/global/core/module/type.d'; import type { ModuleItemType } from '@fastgpt/global/core/module/type.d';
const NodeSimple = dynamic(() => import('./components/nodes/NodeSimple')); const NodeSimple = dynamic(() => import('./components/nodes/NodeSimple'));
const nodeTypes = { const nodeTypes: Record<`${FlowNodeTypeEnum}`, any> = {
[FlowNodeTypeEnum.userGuide]: dynamic(() => import('./components/nodes/NodeUserGuide')), [FlowNodeTypeEnum.userGuide]: dynamic(() => import('./components/nodes/NodeUserGuide')),
[FlowNodeTypeEnum.variable]: dynamic(() => import('./components/nodes/abandon/NodeVariable')), [FlowNodeTypeEnum.variable]: dynamic(() => import('./components/nodes/abandon/NodeVariable')),
[FlowNodeTypeEnum.questionInput]: dynamic(() => import('./components/nodes/NodeQuestionInput')), [FlowNodeTypeEnum.questionInput]: dynamic(() => import('./components/nodes/NodeQuestionInput')),
...@@ -28,7 +28,8 @@ const nodeTypes = { ...@@ -28,7 +28,8 @@ const nodeTypes = {
[FlowNodeTypeEnum.runApp]: NodeSimple, [FlowNodeTypeEnum.runApp]: NodeSimple,
[FlowNodeTypeEnum.pluginInput]: dynamic(() => import('./components/nodes/NodePluginInput')), [FlowNodeTypeEnum.pluginInput]: dynamic(() => import('./components/nodes/NodePluginInput')),
[FlowNodeTypeEnum.pluginOutput]: dynamic(() => import('./components/nodes/NodePluginOutput')), [FlowNodeTypeEnum.pluginOutput]: dynamic(() => import('./components/nodes/NodePluginOutput')),
[FlowNodeTypeEnum.pluginModule]: NodeSimple [FlowNodeTypeEnum.pluginModule]: NodeSimple,
[FlowNodeTypeEnum.cfr]: NodeSimple
}; };
const edgeTypes = { const edgeTypes = {
[EDGE_TYPE]: ButtonEdge [EDGE_TYPE]: ButtonEdge
......
import { ModuleInputKeyEnum } from '@fastgpt/global/core/module/constants';
import { FlowNodeTypeEnum } from '@fastgpt/global/core/module/node/constant';
import { FlowNodeOutputTargetItemType } from '@fastgpt/global/core/module/node/type'; import { FlowNodeOutputTargetItemType } from '@fastgpt/global/core/module/node/type';
import { FlowModuleItemType, ModuleItemType } from '@fastgpt/global/core/module/type'; import { FlowModuleItemType, ModuleItemType } from '@fastgpt/global/core/module/type';
import { type Node, type Edge } from 'reactflow'; import { type Node, type Edge } from 'reactflow';
export function flowNode2Modules({ export const flowNode2Modules = ({
nodes, nodes,
edges edges
}: { }: {
nodes: Node<FlowModuleItemType, string | undefined>[]; nodes: Node<FlowModuleItemType, string | undefined>[];
edges: Edge<any>[]; edges: Edge<any>[];
}) { }) => {
const modules: ModuleItemType[] = nodes.map((item) => ({ const modules: ModuleItemType[] = nodes.map((item) => ({
moduleId: item.data.moduleId, moduleId: item.data.moduleId,
name: item.data.name, name: item.data.name,
...@@ -48,4 +50,19 @@ export function flowNode2Modules({ ...@@ -48,4 +50,19 @@ export function flowNode2Modules({
}); });
return modules; return modules;
} };
export const filterExportModules = (modules: ModuleItemType[]) => {
modules.forEach((module) => {
// dataset - remove select dataset value
if (module.flowType === FlowNodeTypeEnum.datasetSearchNode) {
module.inputs.forEach((item) => {
if (item.key === ModuleInputKeyEnum.datasetSelectList) {
item.value = [];
}
});
}
});
return JSON.stringify(modules, null, 2);
};
...@@ -14,6 +14,9 @@ export const SimpleModeTemplate_FastGPT_Universal: AppSimpleEditConfigTemplateTy ...@@ -14,6 +14,9 @@ export const SimpleModeTemplate_FastGPT_Universal: AppSimpleEditConfigTemplateTy
quoteTemplate: true, quoteTemplate: true,
quotePrompt: true quotePrompt: true
}, },
cfr: {
background: true
},
dataset: { dataset: {
datasets: true, datasets: true,
similarity: true, similarity: true,
......
...@@ -39,6 +39,7 @@ function App({ Component, pageProps }: AppProps) { ...@@ -39,6 +39,7 @@ function App({ Component, pageProps }: AppProps) {
const router = useRouter(); const router = useRouter();
const { hiId } = router.query as { hiId?: string }; const { hiId } = router.query as { hiId?: string };
const { i18n } = useTranslation(); const { i18n } = useTranslation();
const { loadGitStar } = useSystemStore();
const [scripts, setScripts] = useState<FeConfigsType['scripts']>([]); const [scripts, setScripts] = useState<FeConfigsType['scripts']>([]);
const [title, setTitle] = useState(process.env.SYSTEM_NAME || 'AI'); const [title, setTitle] = useState(process.env.SYSTEM_NAME || 'AI');
...@@ -46,18 +47,23 @@ function App({ Component, pageProps }: AppProps) { ...@@ -46,18 +47,23 @@ function App({ Component, pageProps }: AppProps) {
// get init data // get init data
(async () => { (async () => {
const { const {
feConfigs: { scripts, isPlus, systemTitle } feConfigs: { scripts, isPlus, show_git, systemTitle }
} = await clientInitData(); } = await clientInitData();
setTitle(systemTitle || 'FastGPT'); setTitle(systemTitle || 'FastGPT');
// log fastgpt // log fastgpt
!isPlus && if (!isPlus) {
console.log( console.log(
'%cWelcome to FastGPT', '%cWelcome to FastGPT',
'font-family:Arial; color:#3370ff ; font-size:18px; font-weight:bold;', 'font-family:Arial; color:#3370ff ; font-size:18px; font-weight:bold;',
`GitHub:https://github.com/labring/FastGPT` `GitHub:https://github.com/labring/FastGPT`
); );
}
if (show_git) {
loadGitStar();
}
setScripts(scripts || []); setScripts(scripts || []);
})(); })();
......
...@@ -58,6 +58,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse) ...@@ -58,6 +58,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
/* start process */ /* start process */
const { responseData } = await dispatchModules({ const { responseData } = await dispatchModules({
res, res,
mode: 'test',
teamId, teamId,
tmbId, tmbId,
user, user,
...@@ -101,6 +102,9 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse) ...@@ -101,6 +102,9 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
export const config = { export const config = {
api: { api: {
bodyParser: {
sizeLimit: '10mb'
},
responseLimit: '20mb' responseLimit: '20mb'
} }
}; };
...@@ -9,6 +9,7 @@ import { pushGenerateVectorBill } from '@/service/support/wallet/bill/push'; ...@@ -9,6 +9,7 @@ import { pushGenerateVectorBill } from '@/service/support/wallet/bill/push';
import { searchDatasetData } from '@/service/core/dataset/data/pg'; import { searchDatasetData } from '@/service/core/dataset/data/pg';
import { updateApiKeyUsage } from '@fastgpt/service/support/openapi/tools'; import { updateApiKeyUsage } from '@fastgpt/service/support/openapi/tools';
import { BillSourceEnum } from '@fastgpt/global/support/wallet/bill/constants'; import { BillSourceEnum } from '@fastgpt/global/support/wallet/bill/constants';
import { searchQueryExtension } from '@fastgpt/service/core/ai/functions/queryExtension';
export default withNextCors(async function handler(req: NextApiRequest, res: NextApiResponse<any>) { export default withNextCors(async function handler(req: NextApiRequest, res: NextApiResponse<any>) {
try { try {
...@@ -33,8 +34,15 @@ export default withNextCors(async function handler(req: NextApiRequest, res: Nex ...@@ -33,8 +34,15 @@ export default withNextCors(async function handler(req: NextApiRequest, res: Nex
// auth balance // auth balance
await authTeamBalance(teamId); await authTeamBalance(teamId);
// query extension
// const { queries } = await searchQueryExtension({
// query: text,
// model: global.chatModels[0].model
// });
const { searchRes, tokenLen } = await searchDatasetData({ const { searchRes, tokenLen } = await searchDatasetData({
text, rawQuery: text,
queries: [text],
model: dataset.vectorModel, model: dataset.vectorModel,
limit: Math.min(limit * 800, 30000), limit: Math.min(limit * 800, 30000),
datasetIds: [datasetId], datasetIds: [datasetId],
......
...@@ -19,6 +19,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse< ...@@ -19,6 +19,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse<
const result = (() => { const result = (() => {
if (typeof input === 'string') { if (typeof input === 'string') {
const defaultReg: any[] = [ const defaultReg: any[] = [
'',
undefined, undefined,
'undefined', 'undefined',
null, null,
......
...@@ -2,12 +2,14 @@ import type { NextApiRequest, NextApiResponse } from 'next'; ...@@ -2,12 +2,14 @@ import type { NextApiRequest, NextApiResponse } from 'next';
import { jsonRes } from '@fastgpt/service/common/response'; import { jsonRes } from '@fastgpt/service/common/response';
import { request } from '@fastgpt/service/common/api/plusRequest'; import { request } from '@fastgpt/service/common/api/plusRequest';
import type { Method } from 'axios'; import type { Method } from 'axios';
import { connectToDatabase } from '@/service/mongo';
import { setCookie } from '@fastgpt/service/support/permission/controller'; import { setCookie } from '@fastgpt/service/support/permission/controller';
import { getInitConfig } from '../system/getInitData';
export default async function handler(req: NextApiRequest, res: NextApiResponse) { export default async function handler(req: NextApiRequest, res: NextApiResponse) {
try { try {
await connectToDatabase(); if (!global.systemEnv?.pluginBaseUrl) {
await getInitConfig();
}
const method = (req.method || 'POST') as Method; const method = (req.method || 'POST') as Method;
const { path = [], ...query } = req.query as any; const { path = [], ...query } = req.query as any;
......
import type { FeConfigsType, SystemEnvType } from '@fastgpt/global/common/system/types/index.d'; import type { FeConfigsType } from '@fastgpt/global/common/system/types/index.d';
import type { NextApiRequest, NextApiResponse } from 'next'; import type { NextApiRequest, NextApiResponse } from 'next';
import { jsonRes } from '@fastgpt/service/common/response'; import { jsonRes } from '@fastgpt/service/common/response';
import { readFileSync, readdirSync } from 'fs'; import { readFileSync, readdirSync } from 'fs';
...@@ -6,23 +6,14 @@ import type { ConfigFileType, InitDateResponse } from '@/global/common/api/syste ...@@ -6,23 +6,14 @@ import type { ConfigFileType, InitDateResponse } from '@/global/common/api/syste
import { formatPrice } from '@fastgpt/global/support/wallet/bill/tools'; import { formatPrice } from '@fastgpt/global/support/wallet/bill/tools';
import { getTikTokenEnc } from '@fastgpt/global/common/string/tiktoken'; import { getTikTokenEnc } from '@fastgpt/global/common/string/tiktoken';
import { initHttpAgent } from '@fastgpt/service/common/middle/httpAgent'; import { initHttpAgent } from '@fastgpt/service/common/middle/httpAgent';
import {
defaultChatModels,
defaultQAModels,
defaultCQModels,
defaultExtractModels,
defaultQGModels,
defaultVectorModels,
defaultAudioSpeechModels,
defaultWhisperModel,
defaultReRankModels
} from '@fastgpt/global/core/ai/model';
import { SimpleModeTemplate_FastGPT_Universal } from '@/global/core/app/constants'; import { SimpleModeTemplate_FastGPT_Universal } from '@/global/core/app/constants';
import { getSimpleTemplatesFromPlus } from '@/service/core/app/utils'; import { getSimpleTemplatesFromPlus } from '@/service/core/app/utils';
import { PluginSourceEnum } from '@fastgpt/global/core/plugin/constants'; import { PluginSourceEnum } from '@fastgpt/global/core/plugin/constants';
import { getFastGPTFeConfig } from '@fastgpt/service/common/system/config/controller'; import { getFastGPTFeConfig } from '@fastgpt/service/common/system/config/controller';
import { connectToDatabase } from '@/service/mongo'; import { connectToDatabase } from '@/service/mongo';
import { PluginTemplateType } from '@fastgpt/global/core/plugin/type'; import { PluginTemplateType } from '@fastgpt/global/core/plugin/type';
import { readConfigData } from '@/service/common/system';
import { exit } from 'process';
export default async function handler(req: NextApiRequest, res: NextApiResponse) { export default async function handler(req: NextApiRequest, res: NextApiResponse) {
await getInitConfig(); await getInitConfig();
...@@ -48,18 +39,14 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse) ...@@ -48,18 +39,14 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
}); });
} }
const defaultSystemEnv: SystemEnvType = {
vectorMaxProcess: 15,
qaMaxProcess: 15,
pgHNSWEfSearch: 100
};
const defaultFeConfigs: FeConfigsType = { const defaultFeConfigs: FeConfigsType = {
show_emptyChat: true, show_emptyChat: true,
show_git: true, show_git: true,
show_register: false,
docUrl: 'https://doc.fastgpt.in', docUrl: 'https://doc.fastgpt.in',
openAPIDocUrl: 'https://doc.fastgpt.in/docs/development/openapi', openAPIDocUrl: 'https://doc.fastgpt.in/docs/development/openapi',
systemTitle: 'FastGPT', systemTitle: 'FastGPT',
concatMd:
'* 项目开源地址: [FastGPT GitHub](https://github.com/labring/FastGPT)\n* 交流群: ![](https://doc.fastgpt.in/wechat-fastgpt.webp)',
limit: { limit: {
exportLimitMinutes: 0 exportLimitMinutes: 0
}, },
...@@ -73,24 +60,45 @@ export async function getInitConfig() { ...@@ -73,24 +60,45 @@ export async function getInitConfig() {
await connectToDatabase(); await connectToDatabase();
initGlobal(); initGlobal();
const filename = // load config
process.env.NODE_ENV === 'development' ? 'data/config.local.json' : '/app/data/config.json'; const [dbConfig, fileConfig] = await Promise.all([
const res = JSON.parse(readFileSync(filename, 'utf-8')) as ConfigFileType; getFastGPTFeConfig(),
readConfigData('config.json')
]);
const fileRes = JSON.parse(fileConfig) as ConfigFileType;
// get config from database // get config from database
const dbFeConfig = await getFastGPTFeConfig(); const config: ConfigFileType = {
const concatConfig: ConfigFileType = { ...fileRes,
...res,
FeConfig: { FeConfig: {
...res.FeConfig, ...defaultFeConfigs,
...dbFeConfig ...fileRes.FeConfig,
...dbConfig
} }
}; };
setDefaultData(concatConfig); // set config
global.feConfigs = {
isPlus: !!config.SystemParams.pluginBaseUrl,
concatMd: config.FeConfig.show_git ? config.FeConfig.concatMd : '',
...config.FeConfig
};
global.systemEnv = config.SystemParams;
global.chatModels = config.ChatModels;
global.qaModels = config.QAModels;
global.cqModels = config.CQModels;
global.extractModels = config.ExtractModels;
global.qgModels = config.QGModels;
global.vectorModels = config.VectorModels;
global.reRankModels = config.ReRankModels;
global.audioSpeechModels = config.AudioSpeechModels;
global.whisperModel = config.WhisperModel;
global.priceMd = '';
} catch (error) { } catch (error) {
setDefaultData(); console.error('Load init config error', error);
console.log('get init config error, set default', error); exit(1);
} }
await getSimpleModeTemplates(); await getSimpleModeTemplates();
...@@ -117,45 +125,13 @@ export async function getInitConfig() { ...@@ -117,45 +125,13 @@ export async function getInitConfig() {
} }
export function initGlobal() { export function initGlobal() {
// init tikToken
getTikTokenEnc();
initHttpAgent();
global.communityPlugins = []; global.communityPlugins = [];
global.simpleModeTemplates = []; global.simpleModeTemplates = [];
global.qaQueueLen = global.qaQueueLen ?? 0; global.qaQueueLen = global.qaQueueLen ?? 0;
global.vectorQueueLen = global.vectorQueueLen ?? 0; global.vectorQueueLen = global.vectorQueueLen ?? 0;
} // init tikToken
getTikTokenEnc();
export function setDefaultData(res?: ConfigFileType) { initHttpAgent();
global.systemEnv = res?.SystemParams
? { ...defaultSystemEnv, ...res.SystemParams }
: defaultSystemEnv;
global.feConfigs = res?.FeConfig
? {
concatMd: res?.FeConfig?.show_git
? '* 项目开源地址: [FastGPT GitHub](https://github.com/labring/FastGPT)\n* 交流群: ![](https://doc.fastgpt.in/wechat-fastgpt.webp)'
: '',
...defaultFeConfigs,
...res.FeConfig,
isPlus: !!res.SystemParams?.pluginBaseUrl
}
: defaultFeConfigs;
global.chatModels = res?.ChatModels || defaultChatModels;
global.qaModels = res?.QAModels || defaultQAModels;
global.cqModels = res?.CQModels || defaultCQModels;
global.extractModels = res?.ExtractModels || defaultExtractModels;
global.qgModels = res?.QGModels || defaultQGModels;
global.vectorModels = res?.VectorModels || defaultVectorModels;
global.reRankModels = res?.ReRankModels || defaultReRankModels;
global.audioSpeechModels = res?.AudioSpeechModels || defaultAudioSpeechModels;
global.whisperModel = res?.WhisperModel || defaultWhisperModel;
global.priceMd = '';
} }
export function getSystemVersion() { export function getSystemVersion() {
...@@ -209,9 +185,7 @@ async function getSimpleModeTemplates() { ...@@ -209,9 +185,7 @@ async function getSimpleModeTemplates() {
try { try {
const basePath = const basePath =
process.env.NODE_ENV === 'development' process.env.NODE_ENV === 'development' ? 'data/simpleTemplates' : '/app/data/simpleTemplates';
? 'public/simpleTemplates'
: '/app/projects/app/public/simpleTemplates';
// read data/simpleTemplates directory, get all json file // read data/simpleTemplates directory, get all json file
const files = readdirSync(basePath); const files = readdirSync(basePath);
// filter json file // filter json file
...@@ -243,9 +217,7 @@ function getSystemPlugin() { ...@@ -243,9 +217,7 @@ function getSystemPlugin() {
if (global.communityPlugins && global.communityPlugins.length > 0) return; if (global.communityPlugins && global.communityPlugins.length > 0) return;
const basePath = const basePath =
process.env.NODE_ENV === 'development' process.env.NODE_ENV === 'development' ? 'data/pluginTemplates' : '/app/data/pluginTemplates';
? 'public/pluginTemplates'
: '/app/projects/app/public/pluginTemplates';
// read data/pluginTemplates directory, get all json file // read data/pluginTemplates directory, get all json file
const files = readdirSync(basePath); const files = readdirSync(basePath);
// filter json file // filter json file
......
...@@ -200,13 +200,14 @@ export default withNextCors(async function handler(req: NextApiRequest, res: Nex ...@@ -200,13 +200,14 @@ export default withNextCors(async function handler(req: NextApiRequest, res: Nex
/* start flow controller */ /* start flow controller */
const { responseData, answerText } = await dispatchModules({ const { responseData, answerText } = await dispatchModules({
res, res,
mode: 'chat',
user,
teamId: String(user.team.teamId),
tmbId: String(user.team.tmbId),
appId: String(app._id), appId: String(app._id),
chatId, chatId,
responseChatItemId, responseChatItemId,
modules: app.modules, modules: app.modules,
user,
teamId: user.team.teamId,
tmbId: user.team.tmbId,
variables, variables,
histories: concatHistories, histories: concatHistories,
startParams: { startParams: {
......
...@@ -13,7 +13,7 @@ import MyIcon from '@/components/Icon'; ...@@ -13,7 +13,7 @@ import MyIcon from '@/components/Icon';
import MyTooltip from '@/components/MyTooltip'; import MyTooltip from '@/components/MyTooltip';
import ChatTest, { type ChatTestComponentRef } from '@/components/core/module/Flow/ChatTest'; import ChatTest, { type ChatTestComponentRef } from '@/components/core/module/Flow/ChatTest';
import { useFlowProviderStore } from '@/components/core/module/Flow/FlowProvider'; import { useFlowProviderStore } from '@/components/core/module/Flow/FlowProvider';
import { flowNode2Modules } from '@/components/core/module/utils'; import { flowNode2Modules, filterExportModules } from '@/components/core/module/utils';
import { useAppStore } from '@/web/core/app/store/useAppStore'; import { useAppStore } from '@/web/core/app/store/useAppStore';
import { useToast } from '@/web/common/hooks/useToast'; import { useToast } from '@/web/common/hooks/useToast';
import { useConfirm } from '@/web/common/hooks/useConfirm'; import { useConfirm } from '@/web/common/hooks/useConfirm';
...@@ -136,12 +136,12 @@ const RenderHeaderContainer = React.memo(function RenderHeaderContainer({ ...@@ -136,12 +136,12 @@ const RenderHeaderContainer = React.memo(function RenderHeaderContainer({
borderRadius={'lg'} borderRadius={'lg'}
variant={'base'} variant={'base'}
aria-label={'save'} aria-label={'save'}
onClick={() => onClick={() => {
copyData( const modules = flow2ModulesAndCheck();
JSON.stringify(flowNode2Modules({ nodes, edges }), null, 2), if (modules) {
t('app.Export Config Successful') copyData(filterExportModules(modules), t('app.Export Config Successful'));
) }
} }}
/> />
</MyTooltip> </MyTooltip>
......
...@@ -24,7 +24,6 @@ import { chatNodeSystemPromptTip, welcomeTextTip } from '@fastgpt/global/core/mo ...@@ -24,7 +24,6 @@ import { chatNodeSystemPromptTip, welcomeTextTip } from '@fastgpt/global/core/mo
import type { ModuleItemType } from '@fastgpt/global/core/module/type'; import type { ModuleItemType } from '@fastgpt/global/core/module/type';
import { useRequest } from '@/web/common/hooks/useRequest'; import { useRequest } from '@/web/common/hooks/useRequest';
import { useConfirm } from '@/web/common/hooks/useConfirm'; import { useConfirm } from '@/web/common/hooks/useConfirm';
import { FlowNodeTypeEnum } from '@fastgpt/global/core/module/node/constant';
import { streamFetch } from '@/web/common/api/fetch'; import { streamFetch } from '@/web/common/api/fetch';
import { useRouter } from 'next/router'; import { useRouter } from 'next/router';
import { useToast } from '@/web/common/hooks/useToast'; import { useToast } from '@/web/common/hooks/useToast';
...@@ -51,6 +50,7 @@ import { SimpleModeTemplate_FastGPT_Universal } from '@/global/core/app/constant ...@@ -51,6 +50,7 @@ import { SimpleModeTemplate_FastGPT_Universal } from '@/global/core/app/constant
import VariableEdit from '@/components/core/module/Flow/components/modules/VariableEdit'; import VariableEdit from '@/components/core/module/Flow/components/modules/VariableEdit';
import { ModuleInputKeyEnum } from '@fastgpt/global/core/module/constants'; import { ModuleInputKeyEnum } from '@fastgpt/global/core/module/constants';
import PromptTextarea from '@/components/common/Textarea/PromptTextarea/index'; import PromptTextarea from '@/components/common/Textarea/PromptTextarea/index';
import { DatasetSearchModeMap } from '@fastgpt/global/core/dataset/constant';
const InfoModal = dynamic(() => import('../InfoModal')); const InfoModal = dynamic(() => import('../InfoModal'));
const DatasetSelectModal = dynamic(() => import('@/components/core/module/DatasetSelectModal')); const DatasetSelectModal = dynamic(() => import('@/components/core/module/DatasetSelectModal'));
...@@ -132,6 +132,12 @@ function ConfigForm({ ...@@ -132,6 +132,12 @@ function ConfigForm({
); );
}, [getValues, refresh]); }, [getValues, refresh]);
const datasetSearchMode = useMemo(() => {
const mode = getValues('dataset.searchMode');
if (!mode) return '';
return t(DatasetSearchModeMap[mode]?.title);
}, [getValues, t, refresh]);
const { mutate: onSubmitSave, isLoading: isSaving } = useRequest({ const { mutate: onSubmitSave, isLoading: isSaving } = useRequest({
mutationFn: async (data: AppSimpleEditFormType) => { mutationFn: async (data: AppSimpleEditFormType) => {
const modules = await postForm2Modules(data, data.templateId); const modules = await postForm2Modules(data, data.templateId);
...@@ -251,39 +257,6 @@ function ConfigForm({ ...@@ -251,39 +257,6 @@ function ConfigForm({
/> />
</Flex> </Flex>
{/* welcome */}
{selectSimpleTemplate?.systemForm?.userGuide?.welcomeText && (
<Box {...BoxStyles} mt={2}>
<Flex alignItems={'center'}>
<Image alt={''} src={'/imgs/module/userGuide.png'} w={'18px'} />
<Box mx={2}>{t('core.app.Welcome Text')}</Box>
<MyTooltip label={welcomeTextTip} forceShow>
<QuestionOutlineIcon />
</MyTooltip>
</Flex>
<Textarea
mt={2}
rows={5}
placeholder={welcomeTextTip}
borderColor={'myGray.100'}
{...register('userGuide.welcomeText')}
/>
</Box>
)}
{/* variable */}
{selectSimpleTemplate?.systemForm?.userGuide?.variables && (
<Box mt={2} {...BoxStyles}>
<VariableEdit
variables={getValues('userGuide.variables')}
onChange={(e) => {
setValue('userGuide.variables', e);
setRefresh(!refresh);
}}
/>
</Box>
)}
{/* ai */} {/* ai */}
{selectSimpleTemplate?.systemForm?.aiSettings && ( {selectSimpleTemplate?.systemForm?.aiSettings && (
<Box mt={5} {...BoxStyles}> <Box mt={5} {...BoxStyles}>
...@@ -340,7 +313,6 @@ function ConfigForm({ ...@@ -340,7 +313,6 @@ function ConfigForm({
defaultValue={getValues('aiSettings.systemPrompt')} defaultValue={getValues('aiSettings.systemPrompt')}
onBlur={(e) => { onBlur={(e) => {
setValue('aiSettings.systemPrompt', e.target.value || ''); setValue('aiSettings.systemPrompt', e.target.value || '');
setRefresh(!refresh);
}} }}
/> />
</Flex> </Flex>
...@@ -372,16 +344,20 @@ function ConfigForm({ ...@@ -372,16 +344,20 @@ function ConfigForm({
</Flex> </Flex>
)} )}
</Flex> </Flex>
<Flex mt={1} color={'myGray.600'} fontSize={['sm', 'md']}> {getValues('dataset.datasets').length > 0 && (
{t('core.dataset.search.Min Similarity')}: {getValues('dataset.similarity')},{' '} <Flex mt={1} color={'myGray.600'} fontSize={'sm'} mb={2}>
{t('core.dataset.search.Max Tokens')}: {getValues('dataset.limit')} {t('core.dataset.search.search mode')}: {datasetSearchMode}
{getValues('dataset.searchEmptyText') === '' {', '}
? '' {t('core.dataset.search.Min Similarity')}: {getValues('dataset.similarity')}
: t('core.dataset.Set Empty Result Tip')} {', '}
</Flex> {t('core.dataset.search.Max Tokens')}: {getValues('dataset.limit')}
{getValues('dataset.searchEmptyText') === ''
? ''
: t('core.dataset.Set Empty Result Tip')}
</Flex>
)}
<Grid <Grid
gridTemplateColumns={['repeat(2, minmax(0, 1fr))', 'repeat(3, minmax(0, 1fr))']} gridTemplateColumns={['repeat(2, minmax(0, 1fr))', 'repeat(3, minmax(0, 1fr))']}
my={2}
gridGap={[2, 4]} gridGap={[2, 4]}
> >
{selectDatasets.map((item) => ( {selectDatasets.map((item) => (
...@@ -412,6 +388,64 @@ function ConfigForm({ ...@@ -412,6 +388,64 @@ function ConfigForm({
</MyTooltip> </MyTooltip>
))} ))}
</Grid> </Grid>
{selectSimpleTemplate?.systemForm?.cfr && getValues('dataset.datasets').length > 0 && (
<Box mt={10}>
<Box {...LabelStyles} w={'auto'}>
{t('core.app.edit.cfr background prompt')}
<MyTooltip label={t('core.app.edit.cfr background tip')} forceShow>
<QuestionOutlineIcon display={['none', 'inline']} ml={1} />
</MyTooltip>
</Box>
<PromptTextarea
mt={1}
flex={1}
bg={'myWhite.400'}
rows={5}
placeholder={t('core.module.input.placeholder.cfr background')}
defaultValue={getValues('cfr.background')}
onBlur={(e) => {
setValue('cfr.background', e.target.value || '');
}}
/>
</Box>
)}
</Box>
)}
{/* variable */}
{selectSimpleTemplate?.systemForm?.userGuide?.variables && (
<Box mt={2} {...BoxStyles}>
<VariableEdit
variables={getValues('userGuide.variables')}
onChange={(e) => {
setValue('userGuide.variables', e);
setRefresh(!refresh);
}}
/>
</Box>
)}
{/* welcome */}
{selectSimpleTemplate?.systemForm?.userGuide?.welcomeText && (
<Box {...BoxStyles} mt={2}>
<Flex alignItems={'center'}>
<Image alt={''} src={'/imgs/module/userGuide.png'} w={'18px'} />
<Box mx={2}>{t('core.app.Welcome Text')}</Box>
<MyTooltip label={welcomeTextTip} forceShow>
<QuestionOutlineIcon />
</MyTooltip>
</Flex>
<PromptTextarea
mt={2}
bg={'myWhite.400'}
rows={5}
placeholder={welcomeTextTip}
defaultValue={getValues('userGuide.welcomeText')}
onBlur={(e) => {
setValue('userGuide.welcomeText', e.target.value || '');
}}
/>
</Box> </Box>
)} )}
......
...@@ -609,7 +609,6 @@ const CollectionCard = () => { ...@@ -609,7 +609,6 @@ const CollectionCard = () => {
), ),
onClick: () => onClick: () =>
openSyncConfirm(() => { openSyncConfirm(() => {
console.log(collection._id);
onclickStartSync(collection._id); onclickStartSync(collection._id);
})() })()
} }
......
...@@ -8,7 +8,7 @@ import dynamic from 'next/dynamic'; ...@@ -8,7 +8,7 @@ import dynamic from 'next/dynamic';
import MyIcon from '@/components/Icon'; import MyIcon from '@/components/Icon';
import MyTooltip from '@/components/MyTooltip'; import MyTooltip from '@/components/MyTooltip';
import { useFlowProviderStore } from '@/components/core/module/Flow/FlowProvider'; import { useFlowProviderStore } from '@/components/core/module/Flow/FlowProvider';
import { flowNode2Modules } from '@/components/core/module/utils'; import { filterExportModules, flowNode2Modules } from '@/components/core/module/utils';
import { putUpdatePlugin } from '@/web/core/plugin/api'; import { putUpdatePlugin } from '@/web/core/plugin/api';
import { FlowNodeTypeEnum } from '@fastgpt/global/core/module/node/constant'; import { FlowNodeTypeEnum } from '@fastgpt/global/core/module/node/constant';
import { ModuleItemType } from '@fastgpt/global/core/module/type'; import { ModuleItemType } from '@fastgpt/global/core/module/type';
...@@ -62,7 +62,9 @@ const Header = ({ plugin, onClose }: Props) => { ...@@ -62,7 +62,9 @@ const Header = ({ plugin, onClose }: Props) => {
if ( if (
item.inputs.find((input) => { item.inputs.find((input) => {
if (!input.required || input.connected) return false; if (!input.required || input.connected) return false;
if (!input.value || input.value === '' || input.value?.length === 0) return true; if (input.value === undefined || input.value === '' || input.value?.length === 0) {
return true;
}
return false; return false;
}) })
) { ) {
...@@ -155,7 +157,7 @@ const Header = ({ plugin, onClose }: Props) => { ...@@ -155,7 +157,7 @@ const Header = ({ plugin, onClose }: Props) => {
onClick={() => { onClick={() => {
const modules = flow2ModulesAndCheck(); const modules = flow2ModulesAndCheck();
if (modules) { if (modules) {
copyData(JSON.stringify(modules, null, 2), t('app.Export Config Successful')); copyData(filterExportModules(modules), t('app.Export Config Successful'));
} }
}} }}
/> />
......
import { existsSync, readFileSync } from 'fs';
export const readConfigData = (name: string) => {
const isDev = process.env.NODE_ENV === 'development';
const splitName = name.split('.');
const devName = `${splitName[0]}.local.${splitName[1]}`;
const filename = (() => {
if (isDev) {
// check local file exists
const hasLocalFile = existsSync(`data/${devName}`);
if (hasLocalFile) {
return `data/${devName}`;
}
return `data/${name}`;
}
// production path
return `/app/data/${name}`;
})();
const content = readFileSync(filename, 'utf-8');
return content;
};
import {
defaultAudioSpeechModels,
defaultChatModels,
defaultCQModels,
defaultExtractModels,
defaultQAModels,
defaultQGModels,
defaultVectorModels
} from '@fastgpt/global/core/ai/model';
export const getChatModel = (model?: string) => { export const getChatModel = (model?: string) => {
return ( return global.chatModels.find((item) => item.model === model) ?? global.chatModels[0];
(global.chatModels || defaultChatModels).find((item) => item.model === model) ||
global.chatModels?.[0] ||
defaultChatModels[0]
);
}; };
export const getQAModel = (model?: string) => { export const getQAModel = (model?: string) => {
return ( return global.qaModels.find((item) => item.model === model) || global.qaModels[0];
(global.qaModels || defaultQAModels).find((item) => item.model === model) ||
global.qaModels?.[0] ||
defaultQAModels[0]
);
}; };
export const getCQModel = (model?: string) => { export const getCQModel = (model?: string) => {
return ( return global.cqModels.find((item) => item.model === model) || global.cqModels[0];
(global.cqModels || defaultCQModels).find((item) => item.model === model) ||
global.cqModels?.[0] ||
defaultCQModels[0]
);
}; };
export const getExtractModel = (model?: string) => { export const getExtractModel = (model?: string) => {
return ( return global.extractModels.find((item) => item.model === model) || global.extractModels[0];
(global.extractModels || defaultExtractModels).find((item) => item.model === model) ||
global.extractModels?.[0] ||
defaultExtractModels[0]
);
}; };
export const getQGModel = (model?: string) => { export const getQGModel = (model?: string) => {
return ( return global.qgModels.find((item) => item.model === model) || global.qgModels[0];
(global.qgModels || defaultQGModels).find((item) => item.model === model) ||
global.qgModels?.[0] ||
defaultQGModels[0]
);
}; };
export const getVectorModel = (model?: string) => { export const getVectorModel = (model?: string) => {
return ( return global.vectorModels.find((item) => item.model === model) || global.vectorModels[0];
global.vectorModels.find((item) => item.model === model) ||
global.vectorModels?.[0] ||
defaultVectorModels[0]
);
}; };
export function getAudioSpeechModel(model?: string) { export function getAudioSpeechModel(model?: string) {
return ( return (
global.audioSpeechModels.find((item) => item.model === model) || global.audioSpeechModels.find((item) => item.model === model) || global.audioSpeechModels[0]
global.audioSpeechModels?.[0] ||
defaultAudioSpeechModels[0]
); );
} }
......
...@@ -170,9 +170,11 @@ export async function generateVector(): Promise<any> { ...@@ -170,9 +170,11 @@ export async function generateVector(): Promise<any> {
err.response?.data?.error?.type === 'invalid_request_error' || err.response?.data?.error?.type === 'invalid_request_error' ||
err?.code === 500 err?.code === 500
) { ) {
addLog.info('invalid message format', { addLog.info('Lock training data');
dataItem console.log(err?.code);
}); console.log(err.response?.data?.error?.type);
console.log(err?.message);
try { try {
await MongoDatasetTraining.findByIdAndUpdate(data._id, { await MongoDatasetTraining.findByIdAndUpdate(data._id, {
lockTime: new Date('2998/5/5') lockTime: new Date('2998/5/5')
......
...@@ -5,7 +5,7 @@ import { ChatRoleEnum } from '@fastgpt/global/core/chat/constants'; ...@@ -5,7 +5,7 @@ import { ChatRoleEnum } from '@fastgpt/global/core/chat/constants';
import { getAIApi } from '@fastgpt/service/core/ai/config'; import { getAIApi } from '@fastgpt/service/core/ai/config';
import type { ClassifyQuestionAgentItemType } from '@fastgpt/global/core/module/type.d'; import type { ClassifyQuestionAgentItemType } from '@fastgpt/global/core/module/type.d';
import { ModuleInputKeyEnum, ModuleOutputKeyEnum } from '@fastgpt/global/core/module/constants'; import { ModuleInputKeyEnum, ModuleOutputKeyEnum } from '@fastgpt/global/core/module/constants';
import type { ModuleDispatchProps } from '@/types/core/chat/type'; import type { ModuleDispatchProps } from '@fastgpt/global/core/module/type.d';
import { replaceVariable } from '@fastgpt/global/common/string/tools'; import { replaceVariable } from '@fastgpt/global/common/string/tools';
import { Prompt_CQJson } from '@/global/core/prompt/agent'; import { Prompt_CQJson } from '@/global/core/prompt/agent';
import { FunctionModelItemType } from '@fastgpt/global/core/ai/model.d'; import { FunctionModelItemType } from '@fastgpt/global/core/ai/model.d';
...@@ -43,8 +43,8 @@ export const dispatchClassifyQuestion = async (props: Props): Promise<CQResponse ...@@ -43,8 +43,8 @@ export const dispatchClassifyQuestion = async (props: Props): Promise<CQResponse
const chatHistories = getHistories(history, histories); const chatHistories = getHistories(history, histories);
const { arg, tokens } = await (async () => { const { arg, tokens } = await (async () => {
if (cqModel.functionCall) { if (cqModel.toolChoice) {
return functionCall({ return toolChoice({
...props, ...props,
histories: chatHistories, histories: chatHistories,
cqModel cqModel
...@@ -73,7 +73,7 @@ export const dispatchClassifyQuestion = async (props: Props): Promise<CQResponse ...@@ -73,7 +73,7 @@ export const dispatchClassifyQuestion = async (props: Props): Promise<CQResponse
}; };
}; };
async function functionCall({ async function toolChoice({
user, user,
cqModel, cqModel,
histories, histories,
......
...@@ -5,17 +5,19 @@ import { ChatRoleEnum } from '@fastgpt/global/core/chat/constants'; ...@@ -5,17 +5,19 @@ import { ChatRoleEnum } from '@fastgpt/global/core/chat/constants';
import { getAIApi } from '@fastgpt/service/core/ai/config'; import { getAIApi } from '@fastgpt/service/core/ai/config';
import type { ContextExtractAgentItemType } from '@fastgpt/global/core/module/type'; import type { ContextExtractAgentItemType } from '@fastgpt/global/core/module/type';
import { ModuleInputKeyEnum, ModuleOutputKeyEnum } from '@fastgpt/global/core/module/constants'; import { ModuleInputKeyEnum, ModuleOutputKeyEnum } from '@fastgpt/global/core/module/constants';
import type { ModuleDispatchProps } from '@/types/core/chat/type'; import type { ModuleDispatchProps } from '@fastgpt/global/core/module/type.d';
import { Prompt_ExtractJson } from '@/global/core/prompt/agent'; import { Prompt_ExtractJson } from '@/global/core/prompt/agent';
import { replaceVariable } from '@fastgpt/global/common/string/tools'; import { replaceVariable } from '@fastgpt/global/common/string/tools';
import { FunctionModelItemType } from '@fastgpt/global/core/ai/model.d'; import { FunctionModelItemType } from '@fastgpt/global/core/ai/model.d';
import { getHistories } from '../utils'; import { getHistories } from '../utils';
import { getExtractModel } from '@/service/core/ai/model';
type Props = ModuleDispatchProps<{ type Props = ModuleDispatchProps<{
[ModuleInputKeyEnum.history]?: ChatItemType[]; [ModuleInputKeyEnum.history]?: ChatItemType[];
[ModuleInputKeyEnum.contextExtractInput]: string; [ModuleInputKeyEnum.contextExtractInput]: string;
[ModuleInputKeyEnum.extractKeys]: ContextExtractAgentItemType[]; [ModuleInputKeyEnum.extractKeys]: ContextExtractAgentItemType[];
[ModuleInputKeyEnum.description]: string; [ModuleInputKeyEnum.description]: string;
[ModuleInputKeyEnum.aiModel]: string;
}>; }>;
type Response = { type Response = {
[ModuleOutputKeyEnum.success]?: boolean; [ModuleOutputKeyEnum.success]?: boolean;
...@@ -30,19 +32,19 @@ export async function dispatchContentExtract(props: Props): Promise<Response> { ...@@ -30,19 +32,19 @@ export async function dispatchContentExtract(props: Props): Promise<Response> {
const { const {
user, user,
histories, histories,
inputs: { content, history = 6, description, extractKeys } inputs: { content, history = 6, model, description, extractKeys }
} = props; } = props;
if (!content) { if (!content) {
return Promise.reject('Input is empty'); return Promise.reject('Input is empty');
} }
const extractModel = global.extractModels[0]; const extractModel = getExtractModel(model);
const chatHistories = getHistories(history, histories); const chatHistories = getHistories(history, histories);
const { arg, tokens, rawResponse } = await (async () => { const { arg, tokens } = await (async () => {
if (extractModel.functionCall) { if (extractModel.toolChoice) {
return functionCall({ return toolChoice({
...props, ...props,
histories: chatHistories, histories: chatHistories,
extractModel extractModel
...@@ -60,6 +62,9 @@ export async function dispatchContentExtract(props: Props): Promise<Response> { ...@@ -60,6 +62,9 @@ export async function dispatchContentExtract(props: Props): Promise<Response> {
if (!extractKeys.find((item) => item.key === key)) { if (!extractKeys.find((item) => item.key === key)) {
delete arg[key]; delete arg[key];
} }
if (arg[key] === '') {
delete arg[key];
}
} }
// auth fields // auth fields
...@@ -91,7 +96,7 @@ export async function dispatchContentExtract(props: Props): Promise<Response> { ...@@ -91,7 +96,7 @@ export async function dispatchContentExtract(props: Props): Promise<Response> {
}; };
} }
async function functionCall({ async function toolChoice({
extractModel, extractModel,
user, user,
histories, histories,
...@@ -101,17 +106,19 @@ async function functionCall({ ...@@ -101,17 +106,19 @@ async function functionCall({
...histories, ...histories,
{ {
obj: ChatRoleEnum.Human, obj: ChatRoleEnum.Human,
value: `<任务描述> value: `你的任务:
"""
${description || '根据用户要求获取适当的 JSON 字符串。'} ${description || '根据用户要求获取适当的 JSON 字符串。'}
"""
要求:
"""
- 如果字段为空,你返回空字符串。 - 如果字段为空,你返回空字符串。
- 不要换行。 - 字符串不要换行。
- 结合历史记录和文本进行获取。 - 结合上下文和当前问题进行获取。
</任务描述> """
<文本> 当前问题: "${content}"`
${content}
</文本>`
} }
]; ];
const filterMessages = ChatContextFilter({ const filterMessages = ChatContextFilter({
......
...@@ -16,7 +16,7 @@ import { adaptChat2GptMessages } from '@fastgpt/global/core/chat/adapt'; ...@@ -16,7 +16,7 @@ import { adaptChat2GptMessages } from '@fastgpt/global/core/chat/adapt';
import { Prompt_QuotePromptList, Prompt_QuoteTemplateList } from '@/global/core/prompt/AIChat'; import { Prompt_QuotePromptList, Prompt_QuoteTemplateList } from '@/global/core/prompt/AIChat';
import type { AIChatModuleProps } from '@fastgpt/global/core/module/node/type.d'; import type { AIChatModuleProps } from '@fastgpt/global/core/module/node/type.d';
import { replaceVariable } from '@fastgpt/global/common/string/tools'; import { replaceVariable } from '@fastgpt/global/common/string/tools';
import type { ModuleDispatchProps } from '@/types/core/chat/type'; import type { ModuleDispatchProps } from '@fastgpt/global/core/module/type.d';
import { responseWrite, responseWriteController } from '@fastgpt/service/common/response'; import { responseWrite, responseWriteController } from '@fastgpt/service/common/response';
import { getChatModel, ModelTypeEnum } from '@/service/core/ai/model'; import { getChatModel, ModelTypeEnum } from '@/service/core/ai/model';
import type { SearchDataResponseItemType } from '@fastgpt/global/core/dataset/type'; import type { SearchDataResponseItemType } from '@fastgpt/global/core/dataset/type';
......
...@@ -2,11 +2,12 @@ import type { moduleDispatchResType } from '@fastgpt/global/core/chat/type.d'; ...@@ -2,11 +2,12 @@ import type { moduleDispatchResType } from '@fastgpt/global/core/chat/type.d';
import { countModelPrice } from '@/service/support/wallet/bill/utils'; import { countModelPrice } from '@/service/support/wallet/bill/utils';
import type { SelectedDatasetType } from '@fastgpt/global/core/module/api.d'; import type { SelectedDatasetType } from '@fastgpt/global/core/module/api.d';
import type { SearchDataResponseItemType } from '@fastgpt/global/core/dataset/type'; import type { SearchDataResponseItemType } from '@fastgpt/global/core/dataset/type';
import type { ModuleDispatchProps } from '@/types/core/chat/type'; import type { ModuleDispatchProps } from '@fastgpt/global/core/module/type.d';
import { ModelTypeEnum } from '@/service/core/ai/model'; import { ModelTypeEnum } from '@/service/core/ai/model';
import { searchDatasetData } from '@/service/core/dataset/data/pg'; import { searchDatasetData } from '@/service/core/dataset/data/pg';
import { ModuleInputKeyEnum, ModuleOutputKeyEnum } from '@fastgpt/global/core/module/constants'; import { ModuleInputKeyEnum, ModuleOutputKeyEnum } from '@fastgpt/global/core/module/constants';
import { DatasetSearchModeEnum } from '@fastgpt/global/core/dataset/constant'; import { DatasetSearchModeEnum } from '@fastgpt/global/core/dataset/constant';
import { searchQueryExtension } from '@fastgpt/service/core/ai/functions/queryExtension';
type DatasetSearchProps = ModuleDispatchProps<{ type DatasetSearchProps = ModuleDispatchProps<{
[ModuleInputKeyEnum.datasetSelectList]: SelectedDatasetType; [ModuleInputKeyEnum.datasetSelectList]: SelectedDatasetType;
...@@ -26,24 +27,34 @@ export async function dispatchDatasetSearch( ...@@ -26,24 +27,34 @@ export async function dispatchDatasetSearch(
props: DatasetSearchProps props: DatasetSearchProps
): Promise<DatasetSearchResponse> { ): Promise<DatasetSearchResponse> {
const { const {
teamId,
tmbId,
inputs: { datasets = [], similarity = 0.4, limit = 5, searchMode, userChatInput } inputs: { datasets = [], similarity = 0.4, limit = 5, searchMode, userChatInput }
} = props as DatasetSearchProps; } = props as DatasetSearchProps;
if (!Array.isArray(datasets)) {
return Promise.reject('Quote type error');
}
if (datasets.length === 0) { if (datasets.length === 0) {
return Promise.reject("You didn't choose the knowledge base"); return Promise.reject('core.chat.error.Select dataset empty');
} }
if (!userChatInput) { if (!userChatInput) {
return Promise.reject('Your input is empty'); return Promise.reject('core.chat.error.User question empty');
} }
// get vector // get vector
const vectorModel = datasets[0]?.vectorModel || global.vectorModels[0]; const vectorModel = datasets[0]?.vectorModel || global.vectorModels[0];
// const { queries: extensionQueries } = await searchQueryExtension({
// query: userChatInput,
// model: global.chatModels[0].model
// });
const concatQueries = [userChatInput];
// start search
const { searchRes, tokenLen } = await searchDatasetData({ const { searchRes, tokenLen } = await searchDatasetData({
text: userChatInput, rawQuery: userChatInput,
queries: concatQueries,
model: vectorModel.model, model: vectorModel.model,
similarity, similarity,
limit, limit,
...@@ -61,7 +72,7 @@ export async function dispatchDatasetSearch( ...@@ -61,7 +72,7 @@ export async function dispatchDatasetSearch(
tokens: tokenLen, tokens: tokenLen,
type: ModelTypeEnum.vector type: ModelTypeEnum.vector
}), }),
query: userChatInput, query: concatQueries.join('\n'),
model: vectorModel.name, model: vectorModel.name,
tokens: tokenLen, tokens: tokenLen,
similarity, similarity,
......
import { NextApiResponse } from 'next'; import { NextApiResponse } from 'next';
import { ModuleInputKeyEnum } from '@fastgpt/global/core/module/constants'; import { ModuleInputKeyEnum } from '@fastgpt/global/core/module/constants';
import { ModuleOutputKeyEnum } from '@fastgpt/global/core/module/constants'; import { ModuleOutputKeyEnum } from '@fastgpt/global/core/module/constants';
import { RunningModuleItemType } from '@/types/app'; import type { ChatDispatchProps, RunningModuleItemType } from '@fastgpt/global/core/module/type.d';
import { ModuleDispatchProps } from '@/types/core/chat/type'; import { ModuleDispatchProps } from '@fastgpt/global/core/module/type.d';
import type { ChatHistoryItemResType, ChatItemType } from '@fastgpt/global/core/chat/type.d'; import type { ChatHistoryItemResType } from '@fastgpt/global/core/chat/type.d';
import { FlowNodeInputTypeEnum, FlowNodeTypeEnum } from '@fastgpt/global/core/module/node/constant'; import { FlowNodeInputTypeEnum, FlowNodeTypeEnum } from '@fastgpt/global/core/module/node/constant';
import { ModuleItemType } from '@fastgpt/global/core/module/type'; import { ModuleItemType } from '@fastgpt/global/core/module/type';
import { UserType } from '@fastgpt/global/support/user/type';
import { replaceVariable } from '@fastgpt/global/common/string/tools'; import { replaceVariable } from '@fastgpt/global/common/string/tools';
import { responseWrite } from '@fastgpt/service/common/response'; import { responseWrite } from '@fastgpt/service/common/response';
import { sseResponseEventEnum } from '@fastgpt/service/common/response/constant'; import { sseResponseEventEnum } from '@fastgpt/service/common/response/constant';
...@@ -22,11 +21,12 @@ import { dispatchClassifyQuestion } from './agent/classifyQuestion'; ...@@ -22,11 +21,12 @@ import { dispatchClassifyQuestion } from './agent/classifyQuestion';
import { dispatchContentExtract } from './agent/extract'; import { dispatchContentExtract } from './agent/extract';
import { dispatchHttpRequest } from './tools/http'; import { dispatchHttpRequest } from './tools/http';
import { dispatchAppRequest } from './tools/runApp'; import { dispatchAppRequest } from './tools/runApp';
import { dispatchCFR } from './tools/cfr';
import { dispatchRunPlugin } from './plugin/run'; import { dispatchRunPlugin } from './plugin/run';
import { dispatchPluginInput } from './plugin/runInput'; import { dispatchPluginInput } from './plugin/runInput';
import { dispatchPluginOutput } from './plugin/runOutput'; import { dispatchPluginOutput } from './plugin/runOutput';
const callbackMap: Record<string, Function> = { const callbackMap: Record<`${FlowNodeTypeEnum}`, Function> = {
[FlowNodeTypeEnum.historyNode]: dispatchHistory, [FlowNodeTypeEnum.historyNode]: dispatchHistory,
[FlowNodeTypeEnum.questionInput]: dispatchChatInput, [FlowNodeTypeEnum.questionInput]: dispatchChatInput,
[FlowNodeTypeEnum.answerNode]: dispatchAnswer, [FlowNodeTypeEnum.answerNode]: dispatchAnswer,
...@@ -38,38 +38,28 @@ const callbackMap: Record<string, Function> = { ...@@ -38,38 +38,28 @@ const callbackMap: Record<string, Function> = {
[FlowNodeTypeEnum.runApp]: dispatchAppRequest, [FlowNodeTypeEnum.runApp]: dispatchAppRequest,
[FlowNodeTypeEnum.pluginModule]: dispatchRunPlugin, [FlowNodeTypeEnum.pluginModule]: dispatchRunPlugin,
[FlowNodeTypeEnum.pluginInput]: dispatchPluginInput, [FlowNodeTypeEnum.pluginInput]: dispatchPluginInput,
[FlowNodeTypeEnum.pluginOutput]: dispatchPluginOutput [FlowNodeTypeEnum.pluginOutput]: dispatchPluginOutput,
[FlowNodeTypeEnum.cfr]: dispatchCFR,
// none
[FlowNodeTypeEnum.userGuide]: () => Promise.resolve(),
[FlowNodeTypeEnum.variable]: () => Promise.resolve()
}; };
/* running */ /* running */
export async function dispatchModules({ export async function dispatchModules({
res, res,
teamId,
tmbId,
user,
appId,
modules, modules,
chatId,
responseChatItemId,
histories = [], histories = [],
startParams = {}, startParams = {},
variables = {}, variables = {},
user,
stream = false, stream = false,
detail = false detail = false,
}: { ...props
res: NextApiResponse; }: ChatDispatchProps & {
teamId: string;
tmbId: string;
user: UserType;
appId: string;
modules: ModuleItemType[]; modules: ModuleItemType[];
chatId?: string;
responseChatItemId?: string;
histories: ChatItemType[];
startParams?: Record<string, any>; startParams?: Record<string, any>;
variables?: Record<string, any>;
stream?: boolean;
detail?: boolean;
}) { }) {
// set sse response headers // set sse response headers
if (stream) { if (stream) {
...@@ -196,25 +186,21 @@ export async function dispatchModules({ ...@@ -196,25 +186,21 @@ export async function dispatchModules({
module.inputs.forEach((item: any) => { module.inputs.forEach((item: any) => {
params[item.key] = item.value; params[item.key] = item.value;
}); });
const props: ModuleDispatchProps<Record<string, any>> = { const dispatchData: ModuleDispatchProps<Record<string, any>> = {
...props,
res, res,
teamId, variables,
tmbId, histories,
user, user,
appId,
chatId,
responseChatItemId,
stream, stream,
detail, detail,
variables,
histories,
outputs: module.outputs, outputs: module.outputs,
inputs: params inputs: params
}; };
const dispatchRes: Record<string, any> = await (async () => { const dispatchRes: Record<string, any> = await (async () => {
if (callbackMap[module.flowType]) { if (callbackMap[module.flowType]) {
return callbackMap[module.flowType](props); return callbackMap[module.flowType](dispatchData);
} }
return {}; return {};
})(); })();
......
import { ModuleInputKeyEnum } from '@fastgpt/global/core/module/constants'; import { ModuleInputKeyEnum } from '@fastgpt/global/core/module/constants';
import type { ChatItemType } from '@fastgpt/global/core/chat/type.d'; import type { ChatItemType } from '@fastgpt/global/core/chat/type.d';
import type { ModuleDispatchProps } from '@/types/core/chat/type'; import type { ModuleDispatchProps } from '@fastgpt/global/core/module/type.d';
import { getHistories } from '../utils'; import { getHistories } from '../utils';
export type HistoryProps = ModuleDispatchProps<{ export type HistoryProps = ModuleDispatchProps<{
maxContext?: number; maxContext?: number;
......
import { ModuleInputKeyEnum } from '@fastgpt/global/core/module/constants'; import { ModuleInputKeyEnum } from '@fastgpt/global/core/module/constants';
import type { ModuleDispatchProps } from '@/types/core/chat/type'; import type { ModuleDispatchProps } from '@fastgpt/global/core/module/type.d';
export type UserChatInputProps = ModuleDispatchProps<{ export type UserChatInputProps = ModuleDispatchProps<{
[ModuleInputKeyEnum.userChatInput]: string; [ModuleInputKeyEnum.userChatInput]: string;
}>; }>;
......
import type { ModuleDispatchProps } from '@/types/core/chat/type'; import type { ModuleDispatchProps } from '@fastgpt/global/core/module/type.d';
import { dispatchModules } from '../index'; import { dispatchModules } from '../index';
import { FlowNodeTypeEnum } from '@fastgpt/global/core/module/node/constant'; import { FlowNodeTypeEnum } from '@fastgpt/global/core/module/node/constant';
import { import {
...@@ -21,6 +21,7 @@ type RunPluginResponse = { ...@@ -21,6 +21,7 @@ type RunPluginResponse = {
export const dispatchRunPlugin = async (props: RunPluginProps): Promise<RunPluginResponse> => { export const dispatchRunPlugin = async (props: RunPluginProps): Promise<RunPluginResponse> => {
const { const {
mode,
teamId, teamId,
tmbId, tmbId,
inputs: { pluginId, ...data } inputs: { pluginId, ...data }
...@@ -71,6 +72,7 @@ export const dispatchRunPlugin = async (props: RunPluginProps): Promise<RunPlugi ...@@ -71,6 +72,7 @@ export const dispatchRunPlugin = async (props: RunPluginProps): Promise<RunPlugi
if (output) { if (output) {
output.moduleLogo = plugin.avatar; output.moduleLogo = plugin.avatar;
} }
console.log(responseData.length);
return { return {
answerText, answerText,
...@@ -79,7 +81,14 @@ export const dispatchRunPlugin = async (props: RunPluginProps): Promise<RunPlugi ...@@ -79,7 +81,14 @@ export const dispatchRunPlugin = async (props: RunPluginProps): Promise<RunPlugi
moduleLogo: plugin.avatar, moduleLogo: plugin.avatar,
price: responseData.reduce((sum, item) => sum + (item.price || 0), 0), price: responseData.reduce((sum, item) => sum + (item.price || 0), 0),
runningTime: responseData.reduce((sum, item) => sum + (item.runningTime || 0), 0), runningTime: responseData.reduce((sum, item) => sum + (item.runningTime || 0), 0),
pluginOutput: output?.pluginOutput pluginOutput: output?.pluginOutput,
pluginDetail:
mode === 'test' && plugin.teamId === teamId
? responseData.filter((item) => {
const filterArr = [FlowNodeTypeEnum.pluginOutput];
return !filterArr.includes(item.moduleType as any);
})
: undefined
}, },
...(output ? output.pluginOutput : {}) ...(output ? output.pluginOutput : {})
}; };
......
import type { ModuleDispatchProps } from '@/types/core/chat/type'; import type { ModuleDispatchProps } from '@fastgpt/global/core/module/type.d';
export type PluginInputProps = ModuleDispatchProps<{ export type PluginInputProps = ModuleDispatchProps<{
[key: string]: any; [key: string]: any;
......
import type { moduleDispatchResType } from '@fastgpt/global/core/chat/type.d'; import type { moduleDispatchResType } from '@fastgpt/global/core/chat/type.d';
import type { ModuleDispatchProps } from '@/types/core/chat/type'; import type { ModuleDispatchProps } from '@fastgpt/global/core/module/type.d';
import { ModuleOutputKeyEnum } from '@fastgpt/global/core/module/constants'; import { ModuleOutputKeyEnum } from '@fastgpt/global/core/module/constants';
export type PluginOutputProps = ModuleDispatchProps<{ export type PluginOutputProps = ModuleDispatchProps<{
......
import { sseResponseEventEnum } from '@fastgpt/service/common/response/constant'; import { sseResponseEventEnum } from '@fastgpt/service/common/response/constant';
import { responseWrite } from '@fastgpt/service/common/response'; import { responseWrite } from '@fastgpt/service/common/response';
import { textAdaptGptResponse } from '@/utils/adapt'; import { textAdaptGptResponse } from '@/utils/adapt';
import type { ModuleDispatchProps } from '@/types/core/chat/type'; import type { ModuleDispatchProps } from '@fastgpt/global/core/module/type.d';
import { ModuleOutputKeyEnum } from '@fastgpt/global/core/module/constants'; import { ModuleOutputKeyEnum } from '@fastgpt/global/core/module/constants';
export type AnswerProps = ModuleDispatchProps<{ export type AnswerProps = ModuleDispatchProps<{
text: string; text: string;
......
import type { ChatItemType, moduleDispatchResType } from '@fastgpt/global/core/chat/type.d';
import type { ModuleDispatchProps } from '@fastgpt/global/core/module/type.d';
import { ModuleInputKeyEnum, ModuleOutputKeyEnum } from '@fastgpt/global/core/module/constants';
import { getHistories } from '../utils';
import { getAIApi } from '@fastgpt/service/core/ai/config';
import { replaceVariable } from '@fastgpt/global/common/string/tools';
import { getExtractModel } from '@/service/core/ai/model';
type Props = ModuleDispatchProps<{
[ModuleInputKeyEnum.aiModel]: string;
[ModuleInputKeyEnum.aiSystemPrompt]?: string;
[ModuleInputKeyEnum.history]?: ChatItemType[] | number;
[ModuleInputKeyEnum.userChatInput]: string;
}>;
type Response = {
[ModuleOutputKeyEnum.text]: string;
[ModuleOutputKeyEnum.responseData]?: moduleDispatchResType;
};
export const dispatchCFR = async ({
histories,
inputs: { model, systemPrompt, history, userChatInput }
}: Props): Promise<Response> => {
if (!userChatInput) {
return Promise.reject('Question is empty');
}
if (histories.length === 0 && !systemPrompt) {
return {
[ModuleOutputKeyEnum.text]: userChatInput
};
}
const extractModel = getExtractModel(model);
const chatHistories = getHistories(history, histories);
const systemFewShot = systemPrompt
? `Q: 对话背景。
A: ${systemPrompt}
`
: '';
const historyFewShot = chatHistories
.map((item) => {
const role = item.obj === 'Human' ? 'Q' : 'A';
return `${role}: ${item.value}`;
})
.join('\n');
const concatFewShot = `${systemFewShot}${historyFewShot}`.trim();
const ai = getAIApi(undefined, 480000);
const result = await ai.chat.completions.create({
model: extractModel.model,
temperature: 0,
max_tokens: 150,
messages: [
{
role: 'user',
content: replaceVariable(defaultPrompt, {
query: userChatInput,
histories: concatFewShot
})
}
],
stream: false
});
let answer = result.choices?.[0]?.message?.content || '';
// console.log(
// replaceVariable(defaultPrompt, {
// query: userChatInput,
// histories: concatFewShot
// })
// );
// console.log(answer);
const tokens = result.usage?.total_tokens || 0;
return {
[ModuleOutputKeyEnum.responseData]: {
price: extractModel.price * tokens,
model: extractModel.name || '',
tokens,
query: userChatInput,
textOutput: answer
},
[ModuleOutputKeyEnum.text]: answer
};
};
const defaultPrompt = `请不要回答任何问题。
你的任务是结合上下文,为当前问题,实现代词替换,确保问题描述的对象清晰明确。例如:
历史记录:
"""
Q: 对话背景。
A: 关于 FatGPT 的介绍和使用等问题。
"""
当前问题: 怎么下载
输出: FastGPT 怎么下载?
----------------
历史记录:
"""
Q: 报错 "no connection"
A: FastGPT 报错"no connection"可能是因为……
"""
当前问题: 怎么解决
输出: FastGPT 报错"no connection"如何解决?
----------------
历史记录:
"""
Q: 作者是谁?
A: FastGPT 的作者是 labring。
"""
当前问题: 介绍下他
输出: 介绍下 FastGPT 的作者 labring。
----------------
历史记录:
"""
Q: 作者是谁?
A: FastGPT 的作者是 labring。
"""
当前问题: 我想购买商业版。
输出: FastGPT 商业版如何购买?
----------------
历史记录:
"""
Q: 对话背景。
A: 关于 FatGPT 的介绍和使用等问题。
"""
当前问题: nh
输出: nh
----------------
历史记录:
"""
Q: FastGPT 如何收费?
A: FastGPT 收费可以参考……
"""
当前问题: 你知道 laf 么?
输出: 你知道 laf 么?
----------------
历史记录:
"""
Q: FastGPT 的优势
A: 1. 开源
2. 简便
3. 扩展性强
"""
当前问题: 介绍下第2点。
输出: 介绍下 FastGPT 简便的优势。
----------------
历史记录:
"""
Q: 什么是 FastGPT?
A: FastGPT 是一个 RAG 平台。
Q: 什么是 Sealos?
A: Sealos 是一个云操作系统。
"""
当前问题: 它们有什么关系?
输出: FastGPT 和 Sealos 有什么关系?
----------------
历史记录:
"""
{{histories}}
"""
当前问题: {{query}}
输出: `;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment