Skip to content

Commit

Permalink
4.6.4 (#588)
Browse files Browse the repository at this point in the history
  • Loading branch information
c121914yu authored Dec 11, 2023
1 parent 84cf6b5 commit d2d7eac
Show file tree
Hide file tree
Showing 105 changed files with 1,088 additions and 798 deletions.
Binary file added docSite/assets/imgs/webSync1.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docSite/assets/imgs/webSync10.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docSite/assets/imgs/webSync2.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docSite/assets/imgs/webSync3.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docSite/assets/imgs/webSync4.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docSite/assets/imgs/webSync5.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docSite/assets/imgs/webSync6.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docSite/assets/imgs/webSync7.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docSite/assets/imgs/webSync8.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docSite/assets/imgs/webSync9.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
78 changes: 78 additions & 0 deletions docSite/content/docs/course/webSync.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
---
title: 'Web 站点同步'
description: 'FastGPT Web 站点同步功能介绍和使用方式'
icon: 'language'
draft: false
toc: true
weight: 105
---

![](/imgs/webSync1.jpg)

## 什么是 Web 站点同步

Web 站点同步利用爬虫的技术,可以通过一个入口网站,自动捕获`同域名`下的所有网站,目前最多支持`200`个子页面。出于合规与安全角度,FastGPT 仅支持`静态站点`的爬取,主要用于各个文档站点快速构建知识库。

Tips: 国内的媒体站点基本不可用,公众号、csdn、知乎等。可以通过终端发送`curl`请求检测是否为静态站点,例如:

```bash
curl ai.fastgpt.in
```

## 如何使用

### 1. 新建知识库,选择 Web 站点同步

![](/imgs/webSync2.jpg)

![](/imgs/webSync3.jpg)

### 2. 点击配置站点信息

![](/imgs/webSync4.jpg)

### 3. 填写网址和选择器

![](/imgs/webSync5.jpg)

好了, 现在点击开始同步,静等系统自动抓取网站信息即可。


## 创建应用,绑定知识库

![](/imgs/webSync6.jpg)

## 选择器如何使用

选择器是 HTML CSS JS 的产物,你可以通过选择器来定位到你需要抓取的具体内容,而不是整个站点。使用方式为:

### 首先打开浏览器调试面板(通常是 F12,或者【右键 - 检查】)

![](/imgs/webSync7.jpg)

![](/imgs/webSync8.jpg)

### 输入对应元素的选择器

[菜鸟教程 css 选择器](https://www.runoob.com/cssref/css-selectors.html),具体选择器的使用方式可以参考菜鸟教程。

上图中,我们选中了一个区域,对应的是`div`标签,它有 `data-prismjs-copy`, `data-prismjs-copy-success`, `data-prismjs-copy-error` 三个属性,这里我们用到一个就够。所以选择器是:
**`div[data-prismjs-copy]`**

除了属性选择器,常见的还有类和ID选择器。例如:

![](/imgs/webSync9.jpg)

上图 class 里的是类名(可能包含多个类名,都是空格隔开的,选择一个即可),选择器可以为:**`.docs-content`**

### 多选择器使用

在开头的演示中,我们对 FastGPT 文档是使用了多选择器的方式来选择,通过逗号隔开了两个选择器。

![](/imgs/webSync10.jpg)

我们希望选中上图两个标签中的内容,此时就需要两组选择器。一组是:`.docs-content .mb-0.d-flex`,含义是 `docs-content` 类下同时包含 `mb-0``d-flex` 两个类的子元素;

另一组是`.docs-content div[data-prismjs-copy]`,含义是`docs-content` 类下包含`data-prismjs-copy`属性的`div`元素。

把两组选择器用逗号隔开即可:`.docs-content .mb-0.d-flex, .docs-content div[data-prismjs-copy]`
7 changes: 3 additions & 4 deletions docSite/content/docs/development/one-api.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
---
title: '接入微软、ChatGLM、本地模型等'
description: '通过接入 One API 来实现对各种大模型的支持'
description: '部署和接入 OneAPI,实现对各种大模型的支持'
icon: 'Api'
draft: false
toc: true
weight: 708
---

* 默认情况下,FastGPT 只配置了 GPT 的 3 个模型,如果你需要接入其他模型,需要进行一些额外配置。
* 默认情况下,FastGPT 只配置了 GPT 的模型,如果你需要接入其他模型,需要进行一些额外配置。
* [One API](https://github.com/songquanpeng/one-api) 是一个 OpenAI 接口管理 & 分发系统,可以通过标准的 OpenAI API 格式访问所有的大模型,开箱即用。

FastGPT 可以通过接入 One API 来实现对各种大模型的支持。部署方法也很简单。
* FastGPT 可以通过接入 OneAPI 来实现对不同大模型的支持。OneAPI 的部署方法也很简单。

## MySQL 版本

Expand Down
2 changes: 1 addition & 1 deletion docSite/content/docs/development/openapi/dataset.md
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ curl --location --request POST 'https://fastgpt.run/api/core/dataset/searchTest'
{{< tab tabName="响应示例" >}}
{{< markdownify >}}

返回 top limit 结果
返回 top k 结果, limit 为预估条数,会按每条数据 800 tokens 的长度进行预估,20条也就是返回 16000 tokens 长度的数据,最多测试 30000 tokens 的数据。

```bash
{
Expand Down
41 changes: 41 additions & 0 deletions docSite/content/docs/development/upgrading/464.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
---
title: 'V4.6.4(需要初始化)'
description: 'FastGPT V4.6.4'
icon: 'upgrade'
draft: false
toc: true
weight: 832
---

## 1。执行初始化 API

发起 1 个 HTTP 请求 ({{rootkey}} 替换成环境变量里的 `rootkey`,{{host}} 替换成自己域名)

1. https://xxxxx/api/admin/initv464

```bash
curl --location --request POST 'https://{{host}}/api/admin/initv464' \
--header 'rootkey: {{rootkey}}' \
--header 'Content-Type: application/json'
```

初始化说明:
1. 初始化 PG 的createTime字段
2. 初始化 Mongo 中 chat 的 feedback 字段


## V4.6.4 功能介绍

1. 重写 - 分享链接身份逻辑,采用 localID 记录用户的ID。
2. 商业版新增 - 分享链接 SSO 方案,通过`身份鉴权`地址,仅需`3个接口`即可完全接入已有用户系统。具体参考[分享链接身份鉴权](/docs/development/openapi/share/)
3. 调整 - 知识库搜索模块 topk 逻辑,采用 MaxToken 计算,兼容不同长度的文本块
4. 调整鉴权顺序,提高 apikey 的优先级,避免cookie抢占 apikey 的鉴权。
5. 链接读取支持多选择器。参考[Web 站点同步用法](/docs/course/webSync)
6. 修复 - 分享链接图片上传鉴权问题
7. 修复 - Mongo 连接池未释放问题。
8. 修复 - Dataset Intro 无法更新
9. 修复 - md 代码块问题
10. 修复 - root 权限问题
11. 优化 docker file


2 changes: 2 additions & 0 deletions packages/global/common/system/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export const HUMAN_ICON = `/icon/human.svg`;
export const LOGO_ICON = `/icon/logo.svg`;
1 change: 1 addition & 0 deletions packages/global/common/system/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export type FeConfigsType = {
hide_app_flow?: boolean;
concatMd?: string;
docUrl?: string;
chatbotUrl?: string;
openAPIDocUrl?: string;
systemTitle?: string;
googleClientVerKey?: string;
Expand Down
8 changes: 8 additions & 0 deletions packages/global/core/chat/api.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export type UpdateChatFeedbackProps = {
chatId: string;
chatItemId: string;
shareId?: string;
outLinkUid?: string;
userBadFeedback?: string;
userGoodFeedback?: string;
};
3 changes: 0 additions & 3 deletions packages/global/core/chat/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,6 @@ export enum ChatStatusEnum {
finish = 'finish'
}

export const HUMAN_ICON = `/icon/human.svg`;
export const LOGO_ICON = `/icon/logo.svg`;

export const IMG_BLOCK_KEY = 'img-block';
export const FILE_BLOCK_KEY = 'file-block';

Expand Down
7 changes: 5 additions & 2 deletions packages/global/core/chat/type.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ export type ChatItemSchema = {
time: Date;
obj: `${ChatRoleEnum}`;
value: string;
userFeedback?: string;
userGoodFeedback?: string;
userBadFeedback?: string;
robotBadFeedback?: string;
adminFeedback?: AdminFbkType;
[ModuleOutputKeyEnum.responseData]?: ChatHistoryItemResType[];
};
Expand All @@ -56,7 +58,8 @@ export type ChatItemType = {
dataId?: string;
obj: ChatItemSchema['obj'];
value: any;
userFeedback?: string;
userGoodFeedback?: string;
userBadFeedback?: string;
adminFeedback?: ChatItemSchema['feedback'];
[ModuleOutputKeyEnum.responseData]?: ChatHistoryItemResType[];
};
Expand Down
3 changes: 3 additions & 0 deletions packages/global/core/dataset/api.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ export type CreateDatasetCollectionParams = {
chunkSize?: number;
fileId?: string;
rawLink?: string;
qaPrompt?: string;
hashRawText?: string;
metadata?: Record<string, any>;
};

Expand All @@ -40,6 +42,7 @@ export type PgSearchRawType = {
export type PushDatasetDataChunkProps = {
q: string; // embedding content
a?: string; // bonus content
chunkIndex?: number;
indexes?: Omit<DatasetDataIndexItemType, 'dataId'>[];
};

Expand Down
3 changes: 3 additions & 0 deletions packages/global/core/dataset/type.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ export type DatasetCollectionSchemaType = {
chunkSize: number;
fileId?: string;
rawLink?: string;
qaPrompt?: string;
hashRawText?: string;
metadata?: Record<string, any>;
};

Expand Down Expand Up @@ -134,6 +136,7 @@ export type DatasetDataItemType = {
sourceId?: string;
q: string;
a: string;
chunkIndex: number;
indexes: DatasetDataIndexItemType[];
isOwner: boolean;
canWrite: boolean;
Expand Down
18 changes: 18 additions & 0 deletions packages/global/support/user/constant.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,22 @@
export enum UserStatusEnum {
active = 'active',
forbidden = 'forbidden'
}
export const userStatusMap = {
[UserStatusEnum.active]: {
label: 'support.user.status.active'
},
[UserStatusEnum.forbidden]: {
label: 'support.user.status.forbidden'
}
};

export enum OAuthEnum {
github = 'github',
google = 'google'
}

export enum UserAuthTypeEnum {
register = 'register',
findPassword = 'findPassword'
}
3 changes: 2 additions & 1 deletion packages/global/support/user/type.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { InformTypeEnum } from './constant';
import { InformTypeEnum, UserStatusEnum } from './constant';
import { TeamItemType } from './team/type';

export type UserModelSchema = {
Expand All @@ -12,6 +12,7 @@ export type UserModelSchema = {
openaiKey: string;
createTime: number;
timezone: string;
status: `${UserStatusEnum}`;
openaiAccount?: {
key: string;
baseUrl: string;
Expand Down
2 changes: 1 addition & 1 deletion packages/service/common/api/plusRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ instance.interceptors.request.use(requestStart, (err) => Promise.reject(err));
instance.interceptors.response.use(responseSuccess, (err) => Promise.reject(err));

export function request(url: string, data: any, config: ConfigType, method: Method): any {
if (!global.systemEnv?.pluginBaseUrl) {
if (global.systemEnv && !global.systemEnv?.pluginBaseUrl) {
return Promise.reject('该功能为商业版特有...');
}

Expand Down
11 changes: 9 additions & 2 deletions packages/service/common/file/image/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ const ImageSchema = new Schema({
ref: TeamCollectionName,
required: true
},
createTime: {
type: Date,
default: () => new Date()
},
binary: {
type: Buffer
},
Expand All @@ -25,7 +29,10 @@ try {
console.log(error);
}

export const MongoImage: Model<{ teamId: string; binary: Buffer; metadata?: Record<string, any> }> =
models['image'] || model('image', ImageSchema);
export const MongoImage: Model<{
teamId: string;
binary: Buffer;
metadata?: { fileId?: string };
}> = models['image'] || model('image', ImageSchema);

MongoImage.syncIndexes();
26 changes: 0 additions & 26 deletions packages/service/common/mongo/controller.ts

This file was deleted.

35 changes: 0 additions & 35 deletions packages/service/common/mongo/init.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import mongoose from './index';
import { createLogger, format, transports } from 'winston';
import 'winston-mongodb';

/**
* connect MongoDB and init data
Expand Down Expand Up @@ -36,7 +34,6 @@ export async function connectMongo({
});

console.log('mongo connected');
initLogger();

afterHook && (await afterHook());
} catch (error) {
Expand All @@ -45,35 +42,3 @@ export async function connectMongo({
global.mongodb = undefined;
}
}

function initLogger() {
global.logger = createLogger({
transports: [
new transports.MongoDB({
db: process.env.MONGODB_URI as string,
collection: 'server_logs',
options: {
useUnifiedTopology: true
},
cappedSize: 500000000,
tryReconnect: true,
metaKey: 'meta',
format: format.combine(format.timestamp(), format.json())
}),
new transports.Console({
format: format.combine(
format.timestamp({ format: 'YYYY-MM-DD HH:mm:ss' }),
format.printf((info) => {
if (info.level === 'error') {
console.log(info.meta);
return `[${info.level.toLocaleUpperCase()}]: ${[info.timestamp]}: ${info.message}`;
}
return `[${info.level.toLocaleUpperCase()}]: ${[info.timestamp]}: ${info.message}${
info.meta ? `: ${JSON.stringify(info.meta)}` : ''
}`;
})
)
})
]
});
}
1 change: 0 additions & 1 deletion packages/service/common/mongo/type.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,4 @@ import type { Logger } from 'winston';

declare global {
var mongodb: Mongoose | undefined;
var logger: Logger;
}
Loading

0 comments on commit d2d7eac

Please sign in to comment.