Skip to content

Commit

Permalink
perf: outlink detail ux
Browse files Browse the repository at this point in the history
  • Loading branch information
c121914yu committed Mar 24, 2024
1 parent 536b51f commit 5561ae7
Show file tree
Hide file tree
Showing 13 changed files with 168 additions and 121 deletions.
21 changes: 9 additions & 12 deletions docSite/content/docs/development/docker.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,7 @@ curl -O https://raw.githubusercontent.com/labring/FastGPT/main/projects/app/data
在 docker-compose.yml 同级目录下执行

```bash
# 进入项目目录
cd 项目目录
# 启动容器
docker-compose pull
docker-compose up -d
```

Expand All @@ -122,19 +119,20 @@ docker-compose up -d

## FAQ

### Mongo 启动失败
### Mongo 副本集自动初始化失败

最新的 docker-compose 示例优化 Mongo 副本集初始化,实现了全自动。目前在 unbuntu20,22 centos7, wsl2, mac, window 均通过测试。如果你的环境特殊,可以手动初始化副本集:

1. 终端中执行
1. 终端中执行下面命令,创建mongo密钥

```bash
openssl rand -base64 756 > ./mongodb.key
chmod 600 ./mongodb.key
# 修改密钥权限,部分系统是admin,部分是root
chown 999:root ./mongodb.key
```

2. 修改 docker-compose.yml
2. 修改 docker-compose.yml,挂载密钥

```yml
mongo:
Expand Down Expand Up @@ -164,7 +162,6 @@ docker-compose up -d

4. 进入容器执行副本集合初始化


```bash
# 查看 mongo 容器是否正常运行
docker ps
Expand All @@ -174,7 +171,7 @@ docker exec -it mongo bash
# 连接数据库(这里要填Mongo的用户名和密码)
mongo -u myusername -p mypassword --authenticationDatabase admin

# 初始化副本集。如果需要外网访问,mongo:27017 可以改成 ip:27017。但是需要同时修改 FastGPT 连接的参数(MONGODB_URI=mongodb://myname:mypassword@mongo:27017/fastgpt?authSource=admin => MONGODB_URI=mongodb://myname:mypassword@ip:27017/fastgpt?authSource=admin)
# 初始化副本集。如果需要外网访问,mongo:27017 。如果需要外网访问,需要增加Mongo连接参数:directConnection=true
rs.initiate({
_id: "rs0",
members: [
Expand Down Expand Up @@ -262,10 +259,10 @@ mongo连接失败,查看mongo的运行状态对应日志。
可能原因:
1. mongo 服务有没有起来(有些 cpu 不支持 AVX,无法用 mongo5,需要换成 mongo4.x,可以dockerhub找个最新的4.x,修改镜像版本,重新运行)
2. 环境变量(账号密码,注意host和port)
3. 副本集启动失败。
1. mongo 服务有没有起来(有些 cpu 不支持 AVX,无法用 mongo5,需要换成 mongo4.x,可以docker hub找个最新的4.x,修改镜像版本,重新运行)
2. 连接数据库的环境变量填写错误(账号密码,注意host和port,非容器网络连接,需要用公网ip并加上 directConnection=true
3. 副本集启动失败。导致容器一直重启。
### 首次部署,root用户提示未注册
没有启动 Mongo 副本集模式。
日志会有错误提示。大概率是没有启动 Mongo 副本集模式。
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { Output_Template_Finish, Output_Template_UserChatInput } from '../output
import { DatasetSearchModeEnum } from '../../../dataset/constants';

export const Dataset_SEARCH_DESC =
'调用“语义检索”和“全文检索”能力,从数据库中查找“可能”与问题相关的内容';
'调用“语义检索”和“全文检索”能力,从“知识库”中查找可能与问题相关的参考内容';

export const DatasetSearchModule: FlowNodeTemplateType = {
id: FlowNodeTypeEnum.datasetSearchNode,
Expand Down
8 changes: 5 additions & 3 deletions projects/app/public/locales/en/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -837,8 +837,6 @@
"Add props": "Add props",
"AppId": "appId",
"ChatId": "chatId",
"curl import": "curl Import",
"curl import placeholder": "Please enter the curl format content, and the request information for the first interface will be extracted.",
"Current time": "Current time",
"Histories": "histories",
"Key already exists": "Key already exists",
Expand All @@ -849,6 +847,8 @@
"ResponseChatItemId": "Ai response id",
"Url and params have been split": "Path parameters are automatically added to Params",
"Variables": "Global variables",
"curl import": "curl Import",
"curl import placeholder": "Please enter the curl format content, and the request information for the first interface will be extracted.",
"params": ""
},
"input": {
Expand Down Expand Up @@ -1005,6 +1005,7 @@
"Custom headers": "Custom Headers",
"Delete http plugin": "Are you sure to delete this group of HTTP plug-ins? All plug-ins in the directory are deleted.",
"Get Plugin Module Detail Failed": "Load plugin failed",
"Http plugin intro placeholder": "Only for demonstration, no practical effect",
"Intro placeholder": "If the plug-in is called as a tool, the introduction is used as the prompt word."
},
"shareChat": {
Expand Down Expand Up @@ -1223,7 +1224,7 @@
"Get Plugin Module Detail Failed": "Get plugin detail failed",
"HTTP Plugin": "HTTP plugin",
"Import Plugin": "Import HTTP plugin",
"Import from URL": "Import from URL",
"Import from URL": "Import from URL. https://xxxx",
"Intro": "Plugin Intro",
"Invalid Schema": "Invalid Schema",
"Invalid URL": "Invalid URL",
Expand Down Expand Up @@ -1259,6 +1260,7 @@
"Usage": "Usage"
},
"outlink": {
"Delete link tip": "Are you sure to delete this no-sign link? After deletion, the link will be invalid immediately and the session log will still be retained. Please confirm!",
"Max usage points": "Max usage",
"Max usage points tip": "The maximum number of credits allowed for this link will not be used. -1 indicates no limit.",
"Usage points": "Usage points",
Expand Down
11 changes: 7 additions & 4 deletions projects/app/public/locales/zh/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -582,7 +582,8 @@
"success": "开始同步"
}
},
"training": {}
"training": {
}
},
"data": {
"Auxiliary Data": "辅助数据",
Expand Down Expand Up @@ -838,8 +839,6 @@
"Add props": "添加参数",
"AppId": "应用的ID",
"ChatId": "当前对话ID",
"curl import": "curl 导入",
"curl import placeholder": "请输入 curl 格式内容,将会提取第一个接口的请求信息。",
"Current time": "当前时间",
"Histories": "历史纪录,最多取10条",
"Key already exists": "Key 已经存在",
Expand All @@ -850,6 +849,8 @@
"ResponseChatItemId": "AI回复的ID",
"Url and params have been split": "路径参数已被自动加入 Params 中",
"Variables": "全局变量",
"curl import": "curl 导入",
"curl import placeholder": "请输入 curl 格式内容,将会提取第一个接口的请求信息。",
"params": "Params"
},
"input": {
Expand Down Expand Up @@ -1006,6 +1007,7 @@
"Custom headers": "自定义请求头",
"Delete http plugin": "确认删除该组HTTP插件?会删除该目录下所有插件。",
"Get Plugin Module Detail Failed": "加载插件异常",
"Http plugin intro placeholder": "仅做展示,无实际效果",
"Intro placeholder": "如果该插件作为工具被调用,则会使用该介绍作为提示词。"
},
"shareChat": {
Expand Down Expand Up @@ -1224,7 +1226,7 @@
"Get Plugin Module Detail Failed": "获取插件信息异常",
"HTTP Plugin": "HTTP 插件",
"Import Plugin": "导入 HTTP 插件",
"Import from URL": "URL 导入",
"Import from URL": "从URL导入。https://xxxx",
"Intro": "插件介绍",
"Invalid Schema": "Schema 无效",
"Invalid URL": "URL 无效",
Expand Down Expand Up @@ -1260,6 +1262,7 @@
"Usage": "已用额度(¥)"
},
"outlink": {
"Delete link tip": "确认删除该免登录链接?删除后,该链接将会立即失效,对话日志仍会保留,请确认!",
"Max usage points": "积分上限",
"Max usage points tip": "该链接最多允许使用多少积分,超出后将无法使用。-1 代表无限制。",
"Usage points": "积分消耗",
Expand Down
36 changes: 29 additions & 7 deletions projects/app/src/components/MyMenu/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
import React, { useRef, useState } from 'react';
import { Menu, MenuList, MenuItem, Box, useOutsideClick, MenuButton } from '@chakra-ui/react';
import {
Menu,
MenuList,
MenuItem,
Box,
useOutsideClick,
MenuButton,
MenuItemProps
} from '@chakra-ui/react';
import MyIcon from '@fastgpt/web/components/common/Icon';

type MenuItemType = 'primary' | 'danger';

interface Props {
width?: number | string;
offset?: [number, number];
Expand All @@ -11,6 +21,7 @@ interface Props {
isActive?: boolean;
label: string | React.ReactNode;
icon?: string;
type?: MenuItemType;
onClick: () => any;
}[];
}
Expand All @@ -22,15 +33,25 @@ const MyMenu = ({
Button,
menuList
}: Props) => {
const menuItemStyles = {
const typeMapStyle: Record<MenuItemType, MenuItemProps> = {
primary: {
_hover: {
backgroundColor: 'primary.50',
color: 'primary.600'
}
},
danger: {
_hover: {
color: 'red.600',
background: 'red.1'
}
}
};
const menuItemStyles: MenuItemProps = {
borderRadius: 'sm',
py: 3,
display: 'flex',
alignItems: 'center',
_hover: {
backgroundColor: 'myGray.05',
color: 'primary.600'
}
alignItems: 'center'
};
const ref = useRef<HTMLDivElement>(null);
const closeTimer = useRef<any>();
Expand Down Expand Up @@ -92,6 +113,7 @@ const MyMenu = ({
<MenuItem
key={i}
{...menuItemStyles}
{...typeMapStyle[item.type || 'primary']}
onClick={(e) => {
e.stopPropagation();
setIsOpen(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,12 +124,12 @@ const VariableEdit = ({
<TableContainer>
<Table bg={'white'}>
<Thead>
<Tr>
<Th w={'18px !important'} p={0} bg={'myGray.50'} />
<Th bg={'myGray.50'}>{t('core.module.variable.variable name')}</Th>
<Th bg={'myGray.50'}>{t('core.module.variable.key')}</Th>
<Th bg={'myGray.50'}>{t('common.Require Input')}</Th>
<Th bg={'myGray.50'}></Th>
<Tr bg={'myGray.50'}>
<Th w={'18px !important'} p={0} />
<Th>{t('core.module.variable.variable name')}</Th>
<Th>{t('core.module.variable.key')}</Th>
<Th>{t('common.Require Input')}</Th>
<Th></Th>
</Tr>
</Thead>
<Tbody>
Expand Down
24 changes: 16 additions & 8 deletions projects/app/src/components/support/apikey/Table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ import {
MenuList,
MenuItem,
MenuButton,
Menu
Menu,
IconButton
} from '@chakra-ui/react';
import {
getOpenApiKeys,
Expand All @@ -41,6 +42,7 @@ import { useRequest } from '@/web/common/hooks/useRequest';
import MyTooltip from '@/components/MyTooltip';
import { getDocPath } from '@/web/common/system/doc';
import MyMenu from '@/components/MyMenu';
import { useConfirm } from '@/web/common/hooks/useConfirm';

type EditProps = EditApiKeyProps & { _id?: string };
const defaultEditData: EditProps = {
Expand All @@ -59,6 +61,10 @@ const ApiKeyTable = ({ tips, appId }: { tips: string; appId?: string }) => {
const [baseUrl, setBaseUrl] = useState('https://fastgpt.in/api');
const [editData, setEditData] = useState<EditProps>();
const [apiKey, setApiKey] = useState('');
const { ConfirmModal, openConfirm } = useConfirm({
type: 'delete',
content: '确认删除该API密钥?删除后该密钥立即失效,对应的对话日志不会删除,请确认!'
});

const { mutate: onclickRemove, isLoading: isDeleting } = useMutation({
mutationFn: async (id: string) => delOpenApiById(id),
Expand Down Expand Up @@ -181,13 +187,12 @@ const ApiKeyTable = ({ tips, appId }: { tips: string; appId?: string }) => {
<MyMenu
offset={[-50, 5]}
Button={
<MyIcon
<IconButton
icon={<MyIcon name={'more'} w={'14px'} />}
name={'more'}
w={'14px'}
p={2}
_hover={{ bg: 'myWhite.600 ' }}
cursor={'pointer'}
borderRadius={'md'}
variant={'whitePrimary'}
size={'sm'}
aria-label={''}
/>
}
menuList={[
Expand All @@ -205,7 +210,8 @@ const ApiKeyTable = ({ tips, appId }: { tips: string; appId?: string }) => {
{
label: t('common.Delete'),
icon: 'delete',
onClick: () => onclickRemove(_id)
type: 'danger',
onClick: openConfirm(() => onclickRemove(_id))
}
]}
/>
Expand All @@ -216,6 +222,7 @@ const ApiKeyTable = ({ tips, appId }: { tips: string; appId?: string }) => {
</Table>
<Loading loading={isGetting || isDeleting} fixed={false} />
</TableContainer>

{!!editData && (
<EditKeyModal
defaultData={editData}
Expand All @@ -231,6 +238,7 @@ const ApiKeyTable = ({ tips, appId }: { tips: string; appId?: string }) => {
}}
/>
)}
<ConfirmModal />
<MyModal
isOpen={!!apiKey}
w={['400px', '600px']}
Expand Down
2 changes: 1 addition & 1 deletion projects/app/src/pages/api/common/system/getInitData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const defaultFeConfigs: FastGPTFeConfigsType = {
openAPIDocUrl: 'https://doc.fastgpt.in/docs/development/openapi',
systemTitle: 'FastGPT',
concatMd:
'* 项目开源地址: [FastGPT GitHub](https://github.com/labring/FastGPT)\n* 交流群: ![](https://oss.laf.run/htr4n1-images/fastgpt-qr-code.jpg)',
'项目开源地址: [FastGPT GitHub](https://github.com/labring/FastGPT)\n交流群: ![](https://oss.laf.run/htr4n1-images/fastgpt-qr-code.jpg)',
limit: {
exportDatasetLimitMinutes: 0,
websiteSyncLimitMinuted: 0
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import type { NextApiRequest, NextApiResponse } from 'next';
import { jsonRes } from '@fastgpt/service/common/response';
import * as SwaggerParser from '@apidevtools/swagger-parser';
import SwaggerParser from '@apidevtools/swagger-parser';

export default async function handler(req: NextApiRequest, res: NextApiResponse<any>) {
try {
const apiURL = req.body.url as string;

const api = await (SwaggerParser as any).validate(apiURL);
const api = await SwaggerParser.validate(apiURL);

return jsonRes(res, {
data: api
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,10 @@ const SelectUsingWayModal = ({ share, onClose }: { share: OutLinkSchema; onClose
data-open-icon="${getValues('scriptOpenIcon')}"
data-close-icon="${getValues('scriptCloseIcon')}"
defer
/>`
/>
<script>
console.log("Chat box loaded")
</script>`
}
};

Expand Down
Loading

0 comments on commit 5561ae7

Please sign in to comment.