Skip to content

Commit

Permalink
v4.4.5-3 (#357)
Browse files Browse the repository at this point in the history
  • Loading branch information
c121914yu authored Sep 26, 2023
1 parent a11e0bd commit 11848b8
Show file tree
Hide file tree
Showing 34 changed files with 395 additions and 62 deletions.
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ ARG name

# copy common node_modules and one project node_modules
COPY --from=deps /app/node_modules ./node_modules
COPY --from=deps /app/packages ./packages
COPY ./projects/$name ./projects/$name
COPY --from=deps /app/projects/$name/node_modules ./projects/$name/node_modules
COPY pnpm-lock.yaml pnpm-workspace.yaml ./
Expand Down
12 changes: 10 additions & 2 deletions docSite/content/docs/installation/upgrading/445.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: '升级到 V4.4.5'
description: 'FastGPT 从旧版本升级到 V4.4.5 操作指南'
title: 'V4.4.5'
description: 'FastGPT V4.4.5 更新(需执行升级脚本)'
icon: 'upgrade'
draft: false
toc: true
Expand All @@ -21,3 +21,11 @@ curl --location --request POST 'https://{{host}}/api/admin/initv445' \

初始化了 variable 模块,将其合并到用户引导模块中。

## 功能介绍

### Fast GPT V4.4.5

1. 新增 - 下一步指引选项,可以通过模型生成 3 个预测问题。
2. 新增 - 分享链接 hook 身份校验。
3. 新增 - Api Key 使用。增加别名、额度限制和过期时间。自带 appId,无需额外连接。
4. 优化 - 全局变量与开场白合并成同一模块。
4 changes: 2 additions & 2 deletions docSite/content/docs/installation/upgrading/_index.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
weight: 760
title: "版本升级"
description: "FastGPT 升级指南"
title: "版本更新/升级操作"
description: "FastGPT 版本更新介绍及升级操作"
icon: upgrade
draft: false
images: []
Expand Down
8 changes: 8 additions & 0 deletions projects/app/data/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,5 +75,13 @@
"maxToken": 16000,
"price": 0,
"prompt": ""
},
"QGModel": {
"model": "gpt-3.5-turbo",
"name": "GPT35-4k",
"maxToken": 4000,
"price": 0,
"prompt": "",
"functionCall": false
}
}
14 changes: 8 additions & 6 deletions projects/app/public/docs/versionIntro.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
### Fast GPT V4.4.5

1. 优化 - Api Key 使用。增加别名、额度限制和过期时间。自带 appId,无需额外连接。
2. 去除 - 限定词。目前旧应用仍生效,9/25 后全面去除,请及时替换。
3. 新增 - 引用模板/引用提示词设置,可以 DIY 引用内容的格式,从而更好的适配场景。[参考文档](https://doc.fastgpt.run/docs/use-cases/prompt/)
4. [使用文档](https://doc.fastgpt.run/docs/intro/)
5. [点击查看高级编排介绍文档](https://doc.fastgpt.run/docs/workflow)
6. [点击查看商业版](https://doc.fastgpt.run/docs/commercial/)
1. 新增 - 下一步指引选项,可以通过模型生成 3 个预测问题。
2. 新增 - 分享链接 hook 身份校验。
3. 新增 - Api Key 使用。增加别名、额度限制和过期时间。自带 appId,无需额外连接。
4. 去除 - 限定词。目前旧应用仍生效,9/25 后全面去除,请及时替换。
5. 新增 - 引用模板/引用提示词设置,可以 DIY 引用内容的格式,从而更好的适配场景。[参考文档](https://doc.fastgpt.run/docs/use-cases/prompt/)
6. [使用文档](https://doc.fastgpt.run/docs/intro/)
7. [点击查看高级编排介绍文档](https://doc.fastgpt.run/docs/workflow)
8. [点击查看商业版](https://doc.fastgpt.run/docs/commercial/)
1 change: 1 addition & 0 deletions projects/app/public/locales/en/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
"Mark Description": "The annotation feature is currently in beta. \n\n After clicking Add annotation, you need to select a knowledge base in order to store annotation data. You can use this feature to quickly annotate questions and expected answers to guide the model to the next answer. At present, the annotation function, like other data in the knowledge base, is affected by the model, which does not mean that the annotation meets 100% expectations. The \n\n annotation data is only unidirectional synchronization with the knowledge base. If the knowledge base modifies the annotation data, the annotation data displayed in the log cannot be synchronized",
"Mark Description Title": "Mark Description",
"New Chat": "New Chat",
"Question Guide Tips": "I guess what you're asking is",
"Read Mark Description": "Read mark description",
"Read User Feedback": "Read user feedback",
"Select Mark Kb": "Select Dataset",
Expand Down
1 change: 1 addition & 0 deletions projects/app/public/locales/zh/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
"Mark Description": "当前标注功能为测试版。\n\n点击添加标注后,需要选择一个知识库,以便存储标注数据。你可以通过该功能快速的标注问题和预期回答,以便引导模型下次的回答。\n\n目前,标注功能同知识库其他数据一样,受模型的影响,不代表标注后 100% 符合预期。\n\n标注数据仅单向与知识库同步,如果知识库修改了该标注数据,日志展示的标注数据无法同步",
"Mark Description Title": "标注功能介绍",
"New Chat": "新对话",
"Question Guide Tips": "猜你想问",
"Read Mark Description": "查看标注功能介绍",
"Read User Feedback": "查看用户反馈",
"Select Mark Kb": "选择知识库",
Expand Down
5 changes: 5 additions & 0 deletions projects/app/src/api/core/ai/agent/api.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { GET, POST, PUT, DELETE } from '@/api/request';
import { CreateQuestionGuideProps } from './type';

export const postQuestionGuide = (data: CreateQuestionGuideProps, cancelToken: AbortController) =>
POST<string[]>('/core/ai/agent/createQuestionGuide', data, { cancelToken });
5 changes: 5 additions & 0 deletions projects/app/src/api/core/ai/agent/type.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { ChatCompletionRequestMessage } from '@fastgpt/core/aiApi/type';

export type CreateQuestionGuideProps = {
messages: ChatCompletionRequestMessage[];
};
9 changes: 8 additions & 1 deletion projects/app/src/api/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ interface ConfigType {
hold?: boolean;
timeout?: number;
onUploadProgress?: (progressEvent: AxiosProgressEvent) => void;
cancelToken?: AbortController;
}
interface ResponseDataType {
code: number;
Expand Down Expand Up @@ -88,7 +89,12 @@ instance.interceptors.request.use(requestStart, (err) => Promise.reject(err));
/* 响应拦截 */
instance.interceptors.response.use(responseSuccess, (err) => Promise.reject(err));

function request(url: string, data: any, config: ConfigType, method: Method): any {
function request(
url: string,
data: any,
{ cancelToken, ...config }: ConfigType,
method: Method
): any {
/* 去空 */
for (const key in data) {
if (data[key] === null || data[key] === undefined) {
Expand All @@ -103,6 +109,7 @@ function request(url: string, data: any, config: ConfigType, method: Method): an
method,
data: ['POST', 'PUT'].includes(method) ? data : null,
params: !['POST', 'PUT'].includes(method) ? data : null,
signal: cancelToken?.signal,
...config // 用户自定义配置,可以覆盖前面的配置
})
.then((res) => checkRes(res.data))
Expand Down
5 changes: 2 additions & 3 deletions projects/app/src/api/response/chat.d.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import type { AppSchema } from '@/types/mongoSchema';
import type { ChatItemType } from '@/types/chat';
import { VariableItemType } from '@/types/app';
import { AppModuleItemType, VariableItemType } from '@/types/app';

export interface InitChatResponse {
chatId: string;
appId: string;
app: {
variableModules?: VariableItemType[];
welcomeText?: string;
userGuideModule?: AppModuleItemType;
chatModels?: string[];
name: string;
avatar: string;
Expand Down
114 changes: 101 additions & 13 deletions projects/app/src/components/ChatBox/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { feConfigs } from '@/store/static';
import { event } from '@/utils/plugin/eventbus';
import { adaptChat2GptMessages } from '@/utils/common/adapt/message';
import { useMarkdown } from '@/hooks/useMarkdown';
import { VariableItemType } from '@/types/app';
import { AppModuleItemType, VariableItemType } from '@/types/app';
import { VariableInputEnum } from '@/constants/app';
import { useForm } from 'react-hook-form';
import { MessageItemType } from '@/pages/api/openapi/v1/chat/completions';
Expand All @@ -51,6 +51,8 @@ const InputDataModal = dynamic(() => import('@/pages/kb/detail/components/InputD

import styles from './index.module.scss';
import Script from 'next/script';
import { postQuestionGuide } from '@/api/core/ai/agent/api';
import { splitGuideModule } from './utils';

const nanoid = customAlphabet('abcdefghijklmnopqrstuvwxyz1234567890', 24);

Expand Down Expand Up @@ -137,8 +139,7 @@ const ChatBox = (
chatId,
appAvatar,
userAvatar,
variableModules,
welcomeText,
userGuideModule,
active = true,
onUpdateVariable,
onStartChat,
Expand All @@ -151,8 +152,7 @@ const ChatBox = (
chatId?: string;
appAvatar?: string;
userAvatar?: string;
variableModules?: VariableItemType[];
welcomeText?: string;
userGuideModule?: AppModuleItemType;
active?: boolean;
onUpdateVariable?: (e: Record<string, any>) => void;
onStartChat?: (e: StartChatFnProps) => Promise<{
Expand All @@ -171,31 +171,41 @@ const ChatBox = (
const { toast } = useToast();
const { isPc } = useGlobalStore();
const TextareaDom = useRef<HTMLTextAreaElement>(null);
const controller = useRef(new AbortController());
const chatController = useRef(new AbortController());
const questionGuideController = useRef(new AbortController());

const [refresh, setRefresh] = useState(false);
const [variables, setVariables] = useState<Record<string, any>>({});
const [variables, setVariables] = useState<Record<string, any>>({}); // settings variable
const [chatHistory, setChatHistory] = useState<ChatSiteItemType[]>([]);
const [feedbackId, setFeedbackId] = useState<string>();
const [readFeedbackData, setReadFeedbackData] = useState<{
// read feedback modal data
chatItemId: string;
content: string;
isMarked: boolean;
}>();
const [adminMarkData, setAdminMarkData] = useState<{
// mark modal data
kbId?: string;
chatItemId: string;
dataId?: string;
q: string;
a: string;
}>();
const [questionGuides, setQuestionGuide] = useState<string[]>([]);

const isChatting = useMemo(
() =>
chatHistory[chatHistory.length - 1] &&
chatHistory[chatHistory.length - 1]?.status !== 'finish',
[chatHistory]
);

const { welcomeText, variableModules, questionGuide } = useMemo(
() => splitGuideModule(userGuideModule),
[userGuideModule]
);

// compute variable input is finish.
const [variableInputFinish, setVariableInputFinish] = useState(false);
const variableIsFinish = useMemo(() => {
Expand Down Expand Up @@ -287,6 +297,32 @@ const ChatBox = (
}, 100);
}, []);

// create question guide
const createQuestionGuide = useCallback(
async ({ history }: { history: ChatSiteItemType[] }) => {
if (!questionGuide || chatController.current?.signal?.aborted) return;

try {
const abortSignal = new AbortController();
questionGuideController.current = abortSignal;

const result = await postQuestionGuide(
{
messages: adaptChat2GptMessages({ messages: history, reserveId: false }).slice(-6)
},
abortSignal
);
if (Array.isArray(result)) {
setQuestionGuide(result);
setTimeout(() => {
scrollToBottom();
}, 100);
}
} catch (error) {}
},
[questionGuide, scrollToBottom]
);

/**
* user confirm send prompt
*/
Expand All @@ -300,6 +336,7 @@ const ChatBox = (
});
return;
}
questionGuideController.current?.abort('stop');
// get input value
const val = inputVal.trim();

Expand Down Expand Up @@ -332,18 +369,19 @@ const ChatBox = (

// 清空输入内容
resetInputVal('');
setQuestionGuide([]);
setTimeout(() => {
scrollToBottom();
}, 100);

try {
// create abort obj
const abortSignal = new AbortController();
controller.current = abortSignal;
chatController.current = abortSignal;

const messages = adaptChat2GptMessages({ messages: newChatList, reserveId: true });

const { responseData } = await onStartChat({
const { responseData, responseText } = await onStartChat({
chatList: newChatList,
messages,
controller: abortSignal,
Expand All @@ -364,6 +402,16 @@ const ChatBox = (
);

setTimeout(() => {
createQuestionGuide({
history: newChatList.map((item, i) =>
i === newChatList.length - 1
? {
...item,
value: responseText
}
: item
)
});
generatingScroll();
isPc && TextareaDom.current?.focus();
}, 100);
Expand Down Expand Up @@ -393,13 +441,14 @@ const ChatBox = (
}
},
[
isChatting,
chatHistory,
onStartChat,
isChatting,
resetInputVal,
toast,
scrollToBottom,
onStartChat,
generatingMessage,
createQuestionGuide,
generatingScroll,
isPc
]
Expand Down Expand Up @@ -494,7 +543,8 @@ const ChatBox = (
// page change and abort request
useEffect(() => {
return () => {
controller.current?.abort('leave');
chatController.current?.abort('leave');
questionGuideController.current?.abort('leave');
// close voice
cancelBroadcast();
};
Expand Down Expand Up @@ -528,6 +578,7 @@ const ChatBox = (
<Flex flexDirection={'column'} h={'100%'}>
<Script src="/js/html2pdf.bundle.min.js" strategy="lazyOnload"></Script>

{/* chat box container */}
<Box ref={ChatBoxRef} flex={'1 0 0'} h={0} w={'100%'} overflow={'overlay'} px={[4, 0]} pb={3}>
<Box id="chat-container" maxW={['100%', '92%']} h={'100%'} mx={'auto'}>
{showEmpty && <Empty />}
Expand Down Expand Up @@ -839,6 +890,43 @@ const ChatBox = (
contentId={item.dataId}
responseData={item.responseData}
/>
{/* question guide */}
{index === chatHistory.length - 1 &&
!isChatting &&
questionGuides.length > 0 && (
<Flex
mt={2}
borderTop={theme.borders.sm}
alignItems={'center'}
flexWrap={'wrap'}
>
<Box
color={'myGray.500'}
mt={2}
mr={2}
fontSize={'sm'}
fontStyle={'italic'}
>
{t('chat.Question Guide Tips')}
</Box>
{questionGuides.map((item) => (
<Button
mt={2}
key={item}
mr="2"
borderRadius={'md'}
variant={'outline'}
colorScheme={'gray'}
size={'xs'}
onClick={() => {
resetInputVal(item);
}}
>
{item}
</Button>
))}
</Flex>
)}
{/* admin mark content */}
{showMarkIcon && item.adminFeedback && (
<Box>
Expand Down Expand Up @@ -928,7 +1016,7 @@ const ChatBox = (
cursor={'pointer'}
name={'stop'}
color={'gray.500'}
onClick={() => controller.current?.abort('stop')}
onClick={() => chatController.current?.abort('stop')}
/>
) : (
<MyIcon
Expand Down
Loading

0 comments on commit 11848b8

Please sign in to comment.