Skip to content

Commit

Permalink
v4.2 (#217)
Browse files Browse the repository at this point in the history
* fix: chat module link

* fix: url fetch check

* fix: import file ui

* feat: app logs

* perf: iframe icon

* imgs cdn

* perf: click range and pg
  • Loading branch information
c121914yu authored Aug 24, 2023
1 parent 2b50dac commit 9415e22
Show file tree
Hide file tree
Showing 30 changed files with 506 additions and 63 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ FastGPT 是一个基于 LLM 大语言模型的知识库问答系统,提供开
- [x] 支持直接分段导入
- [x] 支持 QA 拆分导入
- [x] 支持手动输入内容
- [ ] 支持 url 读取导入
- [x] 支持 url 读取导入
- [x] 支持 CSV 批量导入问答对
- [ ] 支持知识库单独设置向量模型
- [ ] 源文件存储
Expand Down
6 changes: 3 additions & 3 deletions client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
"@dqbd/tiktoken": "^1.0.7",
"@emotion/react": "^11.10.6",
"@emotion/styled": "^11.10.6",
"@mozilla/readability": "^0.4.4",
"@next/font": "13.1.6",
"@tanstack/react-query": "^4.24.10",
"@types/nprogress": "^0.2.0",
"@mozilla/readability": "^0.4.4",
"axios": "^1.3.3",
"cookie": "^0.5.0",
"crypto": "^1.0.1",
Expand All @@ -31,6 +31,7 @@
"i18next": "^22.5.1",
"immer": "^9.0.19",
"js-cookie": "^3.0.5",
"jsdom": "^22.1.0",
"jsonwebtoken": "^9.0.0",
"lodash": "^4.17.21",
"mammoth": "^1.5.1",
Expand Down Expand Up @@ -59,7 +60,6 @@
"request-ip": "^3.3.0",
"sass": "^1.58.3",
"tunnel": "^0.0.6",
"jsdom": "^22.1.0",
"winston": "^3.10.0",
"winston-mongodb": "^5.1.1",
"zustand": "^4.3.5"
Expand All @@ -69,6 +69,7 @@
"@types/cookie": "^0.5.1",
"@types/formidable": "^2.0.5",
"@types/js-cookie": "^3.0.3",
"@types/jsdom": "^21.1.1",
"@types/jsonwebtoken": "^9.0.1",
"@types/lodash": "^4.14.191",
"@types/node": "18.14.0",
Expand All @@ -79,7 +80,6 @@
"@types/react-syntax-highlighter": "^15.5.6",
"@types/request-ip": "^0.0.37",
"@types/tunnel": "^0.0.3",
"@types/jsdom": "^21.1.1",
"eslint": "8.34.0",
"eslint-config-next": "13.1.6",
"typescript": "4.9.5"
Expand Down
13 changes: 7 additions & 6 deletions client/public/docs/versionIntro.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
### Fast GPT V4.1
### Fast GPT V4.2

1. 新增 - 高级编排导入导出功能
2. 优化对话存储结构
3. 优化日志存储
4. [点击查看高级编排介绍文档](https://doc.fastgpt.run/docs/workflow)
5. 填写个人 OpenAI 账号后,分享和 API 功能也不会走平台余额扣费。
1. 新增 - 应用日志初版,可观测到所有对话记录
2. 新增 - 好友邀请链接,[点击查看](/account?currentTab=promotion)
3. 新增 - Iframe 嵌入页面图标可拖拽
4. 优化 - 知识库搜索提示词
5. 优化 - [使用文档](https://doc.fastgpt.run/docs/intro/)
6. [点击查看高级编排介绍文档](https://doc.fastgpt.run/docs/workflow)
37 changes: 34 additions & 3 deletions client/public/js/iframe.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,9 @@ async function embedChatbot() {
const ChatBtn = document.createElement('div');
ChatBtn.id = chatBtnId;
ChatBtn.style.cssText =
'position: fixed; bottom: 1rem; right: 1rem; width: 40px; height: 40px; cursor: pointer; z-index: 2147483647; ';
'position: fixed; bottom: 1rem; right: 1rem; width: 40px; height: 40px; cursor: pointer; z-index: 2147483647; transition: 0;';

const ChatBtnDiv = document.createElement('div');
ChatBtnDiv.style.cssText =
'transition: all 0.2s ease-in-out 0s; left: unset; transform: scale(1); :hover {transform: scale(1.1);} display: flex; align-items: center; justify-content: center; width: 100%; height: 100%; z-index: 9999;';
ChatBtnDiv.innerHTML = MessageIcon;

const iframe = document.createElement('iframe');
Expand All @@ -38,7 +36,15 @@ async function embedChatbot() {

document.body.appendChild(iframe);

let chatBtnDragged = false;
let chatBtnDown = false;
let chatBtnMouseX;
let chatBtnMouseY;
ChatBtn.addEventListener('click', function () {
if (chatBtnDragged) {
chatBtnDragged = false;
return;
}
const chatWindow = document.getElementById(chatWindowId);

if (!chatWindow) return;
Expand All @@ -52,6 +58,31 @@ async function embedChatbot() {
}
});

ChatBtn.addEventListener('mousedown', (e) => {
if (!chatBtnMouseX && !chatBtnMouseY) {
chatBtnMouseX = e.clientX;
chatBtnMouseY = e.clientY;
}

chatBtnDown = true;
});
ChatBtn.addEventListener('mousemove', (e) => {
if (!chatBtnDown) return;
chatBtnDragged = true;
const transformX = e.clientX - chatBtnMouseX;
const transformY = e.clientY - chatBtnMouseY;

ChatBtn.style.transform = `translate3d(${transformX}px, ${transformY}px, 0)`;

e.stopPropagation();
});
ChatBtn.addEventListener('mouseup', (e) => {
chatBtnDown = false;
});
ChatBtn.addEventListener('mouseleave', (e) => {
chatBtnDown = false;
});

ChatBtn.appendChild(ChatBtnDiv);
document.body.appendChild(ChatBtn);
}
Expand Down
22 changes: 20 additions & 2 deletions client/public/locales/en/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@
"Confirm": "Yes",
"Running": "Running",
"Warning": "Warning",
"UnKnow": "UnKnow",
"app": {
"Advance App TestTip": "The current application is advanced editing mode \n. If you need to switch to [simple mode], please click the save button on the left",
"App Detail": "App Detail",
"Chat Logs Tips": "Logs record the app's online, shared, and API conversations",
"Chat logs": "Chat Logs",
"Confirm Del App Tip": "Confirm to delete the app and all its chats",
"Confirm Save App Tip": "The application may be in advanced orchestration mode, and the advanced orchestration configuration will be overwritten after saving, please confirm!",
"Connection is invalid": "Connecting is invalid",
Expand All @@ -18,6 +21,11 @@
"Import Config Failed": "Failed to import the configuration, please ensure that the configuration is normal!",
"Import Configs": "Import Configs",
"Input Field Settings": "Input Field Settings",
"Logs Empty": "Logs is empty",
"Logs Message Total": "Message Count",
"Logs Source": "Source",
"Logs Time": "Time",
"Logs Title": "Title",
"My Apps": "My Apps",
"Output Field Settings": "Output Field Settings",
"Paste Config": "Paste Config"
Expand All @@ -28,7 +36,13 @@
"Exit Chat": "Exit",
"History": "History",
"New Chat": "New Chat",
"You need to a chat app": "You need to a chat app"
"You need to a chat app": "You need to a chat app",
"logs": {
"api": "API",
"online": "Online Chat",
"share": "Share",
"test": "Test Chat "
}
},
"commom": {
"Password inconsistency": "Password inconsistency"
Expand Down Expand Up @@ -149,6 +163,10 @@
"Update Password": "Update Password",
"Update password failed": "Update password failed",
"Update password succseful": "Update password succseful",
"Usage Record": "Usage"
"Usage Record": "Usage",
"promotion": {
"pay": "",
"register": ""
}
}
}
20 changes: 17 additions & 3 deletions client/public/locales/zh/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@
"Confirm": "确认",
"Running": "运行中",
"Warning": "提示",
"UnKnow": "未知",
"app": {
"Advance App TestTip": "当前应用为高级编排模式\n如需切换为【简易模式】请点击左侧保存按键",
"App Detail": "应用详情",
"Chat Logs Tips": "日志会记录该应用的在线、分享和 API 对话记录",
"Chat logs": "对话日志",
"Confirm Del App Tip": "确认删除该应用及其所有聊天记录?",
"Confirm Save App Tip": "该应用可能为高级编排模式,保存后将会覆盖高级编排配置,请确认!",
"Connection is invalid": "连接无效",
Expand All @@ -18,6 +21,11 @@
"Import Config Failed": "导入配置失败,请确保配置正常!",
"Import Configs": "导入配置",
"Input Field Settings": "输入字段编辑",
"Logs Empty": "还没有日志噢~",
"Logs Message Total": "消息总数",
"Logs Source": "来源",
"Logs Time": "时间",
"Logs Title": "标题",
"My Apps": "我的应用",
"Output Field Settings": "输出字段编辑",
"Paste Config": "粘贴配置"
Expand All @@ -28,7 +36,13 @@
"Exit Chat": "退出聊天",
"History": "记录",
"New Chat": "新对话",
"You need to a chat app": "你需要创建一个应用"
"You need to a chat app": "你需要创建一个应用",
"logs": {
"api": "API 调用",
"online": "在线使用",
"share": "外部链接调用",
"test": "测试"
}
},
"commom": {
"Password inconsistency": "两次密码不一致"
Expand Down Expand Up @@ -151,8 +165,8 @@
"Update password succseful": "修改密码成功",
"Usage Record": "使用记录",
"promotion": {
"register": "好友注册",
"pay": "好友充值"
"pay": "好友充值",
"register": "好友注册"
}
}
}
3 changes: 3 additions & 0 deletions client/src/api/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,6 @@ export const getAppTotalUsage = (data: { appId: string }) =>
start: addDays(new Date(), -13),
end: addDays(new Date(), 1)
}).then((res) => (res.length === 0 ? [{ date: new Date(), total: 0 }] : res));

export const getAppChatLogs = (data: RequestPaging & { appId: string }) =>
POST(`/chat/getChatLogs`, data);
1 change: 1 addition & 0 deletions client/src/components/ChatBox/QuoteModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ const QuoteModal = ({
_notLast={{ mb: 2 }}
position={'relative'}
_hover={{ '& .edit': { display: 'flex' } }}
overflow={'hidden'}
>
{item.source && <Box color={'myGray.600'}>({item.source})</Box>}
<Box>{item.q}</Box>
Expand Down
10 changes: 5 additions & 5 deletions client/src/components/ChatBox/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ const ChatBox = (
variableModules?: VariableItemType[];
welcomeText?: string;
onUpdateVariable?: (e: Record<string, any>) => void;
onStartChat: (e: StartChatFnProps) => Promise<{
onStartChat?: (e: StartChatFnProps) => Promise<{
responseText: string;
[TaskResponseKeyEnum.responseData]: ChatHistoryItemResType[];
}>;
Expand Down Expand Up @@ -239,8 +239,7 @@ const ChatBox = (
// 复制内容
const onclickCopy = useCallback(
(value: string) => {
const val = value.replace(/\n+/g, '\n');
copyData(val);
copyData(value);
},
[copyData]
);
Expand All @@ -264,6 +263,7 @@ const ChatBox = (
*/
const sendPrompt = useCallback(
async (variables: Record<string, any> = {}, inputVal = '') => {
if (!onStartChat) return;
if (isChatting) {
toast({
title: '正在聊天中...请等待结束',
Expand All @@ -272,7 +272,7 @@ const ChatBox = (
return;
}
// get input value
const val = inputVal.trim().replace(/\n\s*/g, '\n');
const val = inputVal.trim();

if (!val) {
toast({
Expand Down Expand Up @@ -698,7 +698,7 @@ const ChatBox = (
</Box>
</Box>
{/* input */}
{variableIsFinish ? (
{onStartChat && variableIsFinish ? (
<Box m={['0 auto', '10px auto']} w={'100%'} maxW={['auto', 'min(750px, 100%)']} px={[0, 5]}>
<Box
py={'18px'}
Expand Down
14 changes: 14 additions & 0 deletions client/src/components/Icon/icons/light/logs.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 2 additions & 1 deletion client/src/components/Icon/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ const map = {
addCircle: require('./icons/circle/add.svg').default,
playFill: require('./icons/fill/play.svg').default,
courseLight: require('./icons/light/course.svg').default,
promotionLight: require('./icons/light/promotion.svg').default
promotionLight: require('./icons/light/promotion.svg').default,
logsLight: require('./icons/light/logs.svg').default
};

export type IconName = keyof typeof map;
Expand Down
13 changes: 7 additions & 6 deletions client/src/constants/chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,32 +31,33 @@ export const ChatRoleMap = {
};

export enum ChatSourceEnum {
'test' = 'test',
test = 'test',
online = 'online',
share = 'share',
api = 'api'
}

export const ChatSourceMap = {
[ChatSourceEnum.test]: {
name: '调试测试'
name: 'chat.logs.test'
},
[ChatSourceEnum.online]: {
name: '在线使用'
name: 'chat.logs.online'
},
[ChatSourceEnum.share]: {
name: '链接分享'
name: 'chat.logs.share'
},
[ChatSourceEnum.api]: {
name: 'API调用'
name: 'chat.logs.api'
}
};

export enum ChatModuleEnum {
'AIChat' = 'AI Chat',
'KBSearch' = 'KB Search',
'CQ' = 'Classify Question',
'Extract' = 'Content Extract'
'Extract' = 'Content Extract',
'Http' = 'Http'
}

export enum OutLinkTypeEnum {
Expand Down
Loading

0 comments on commit 9415e22

Please sign in to comment.