Skip to content

Commit bfd8be5

Browse files
authored
v4.6-3 (#471)
1 parent 592e1a9 commit bfd8be5

File tree

181 files changed

+2484
-1537
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

181 files changed

+2484
-1537
lines changed
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
name: Build FastGPT images in Personal warehouse
2+
on:
3+
workflow_dispatch:
4+
push:
5+
paths:
6+
- 'projects/app/**'
7+
- 'packages/**'
8+
branches:
9+
- 'main'
10+
jobs:
11+
build-fastgpt-images:
12+
runs-on: ubuntu-20.04
13+
if: github.repository != 'labring/FastGPT'
14+
steps:
15+
- name: Checkout
16+
uses: actions/checkout@v3
17+
with:
18+
fetch-depth: 0
19+
- name: Set up Docker Buildx
20+
uses: docker/setup-buildx-action@v2
21+
with:
22+
driver-opts: network=host
23+
- name: Cache Docker layers
24+
uses: actions/cache@v3
25+
with:
26+
path: /tmp/.buildx-cache
27+
key: ${{ runner.os }}-buildx-${{ github.sha }}
28+
restore-keys: |
29+
${{ runner.os }}-buildx-
30+
- name: Login to GitHub Container Registry
31+
uses: docker/login-action@v2
32+
with:
33+
registry: ghcr.io
34+
username: ${{ github.repository_owner }}
35+
password: ${{ secrets.GH_PAT }}
36+
- name: Set DOCKER_REPO_TAGGED based on branch or tag
37+
run: |
38+
echo "DOCKER_REPO_TAGGED=ghcr.io/${{ github.repository_owner }}/fastgpt:latest" >> $GITHUB_ENV
39+
- name: Build and publish image for main branch or tag push event
40+
env:
41+
DOCKER_REPO_TAGGED: ${{ env.DOCKER_REPO_TAGGED }}
42+
run: |
43+
docker buildx build \
44+
--build-arg name=app \
45+
--label "org.opencontainers.image.source=https://github.com/${{ github.repository_owner }}/FastGPT" \
46+
--label "org.opencontainers.image.description=fastgpt image" \
47+
--push \
48+
--cache-from=type=local,src=/tmp/.buildx-cache \
49+
--cache-to=type=local,dest=/tmp/.buildx-cache \
50+
-t ${DOCKER_REPO_TAGGED} \
51+
-f Dockerfile \
52+
.

.github/workflows/fastgpt-image.yml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ on:
55
paths:
66
- 'projects/app/**'
77
- 'packages/**'
8-
branches:
9-
- 'main'
108
tags:
119
- 'v*.*.*'
1210
jobs:
@@ -53,9 +51,8 @@ jobs:
5351
docker buildx build \
5452
--build-arg name=app \
5553
--platform linux/amd64,linux/arm64 \
56-
--label "org.opencontainers.image.source= https://github.com/ ${{ github.repository_owner }}/FastGPT" \
54+
--label "org.opencontainers.image.source=https://github.com/${{ github.repository_owner }}/FastGPT" \
5755
--label "org.opencontainers.image.description=fastgpt image" \
58-
--label "org.opencontainers.image.licenses=Apache" \
5956
--push \
6057
--cache-from=type=local,src=/tmp/.buildx-cache \
6158
--cache-to=type=local,dest=/tmp/.buildx-cache \

.github/workflows/preview-image.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ jobs:
2424
with:
2525
driver-opts: network=host
2626
- name: Cache Docker layers
27-
uses: actions/cache@v2
27+
uses: actions/cache@v3
2828
with:
2929
path: /tmp/.buildx-cache
3030
key: ${{ runner.os }}-buildx-${{ github.sha }}
@@ -48,6 +48,7 @@ jobs:
4848
--label "org.opencontainers.image.source= https://github.com/ ${{ github.repository_owner }}/FastGPT" \
4949
--label "org.opencontainers.image.description=fastgpt-pr image" \
5050
--label "org.opencontainers.image.licenses=Apache" \
51+
--push \
5152
--cache-from=type=local,src=/tmp/.buildx-cache \
5253
--cache-to=type=local,dest=/tmp/.buildx-cache \
5354
-t ${DOCKER_REPO_TAGGED} \

docSite/content/docs/installation/upgrading/46.md

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,20 @@ toc: true
77
weight: 836
88
---
99

10-
未正式发布
10+
# V4.6 版本加入了简单的团队功能,可以邀请其他用户进来管理资源。该版本升级后无法执行旧的升级脚本,且无法回退
1111

12-
V4.6 版本加入了简单的团队功能,可以邀请其他用户进来管理资源。该版本升级后无法执行旧的升级脚本,且无法回退。
12+
# 1. 更新镜像并变更配置文件
1313

14-
## 1. 更新镜像并变更配置文件
15-
16-
更新镜像至 latest 或者 v4.6 版本。商业版镜像更新至 V0.2.
14+
更新镜像至 latest 或者 v4.6 版本。商业版镜像更新至 V0.2.1
1715

1816
最新配置可参考: [V46版本最新 config.json](/docs/development/configuration),商业镜像配置文件也更新,参考最新的飞书文档。
1917

2018

21-
## 2. 执行初始化 API
19+
# 2. 执行初始化 API
20+
21+
发起 2 个 HTTP 请求({{rootkey}} 替换成环境变量里的`rootkey`,{{host}}替换成自己域名)
2222

23-
发起 1 个 HTTP 请求({{rootkey}} 替换成环境变量里的`rootkey`,{{host}}替换成自己域名)
23+
**该初始化接口可能速度很慢,返回超时不用管,注意看日志即可,需要注意的是,需确保initv46成功后,在执行initv46-2**
2424

2525
1. https://xxxxx/api/admin/initv46
2626

@@ -30,16 +30,25 @@ curl --location --request POST 'https://{{host}}/api/admin/initv46' \
3030
--header 'Content-Type: application/json'
3131
```
3232

33+
2. https://xxxxx/api/admin/initv46-2
34+
35+
```bash
36+
curl --location --request POST 'https://{{host}}/api/admin/initv46-2' \
37+
--header 'rootkey: {{rootkey}}' \
38+
--header 'Content-Type: application/json'
39+
```
40+
3341
初始化内容:
3442
1. 创建默认团队
3543
2. 初始化 Mongo 所有资源的团队字段
3644
3. 初始化 Pg 的字段
45+
4. 初始化 Mongo Data
3746

38-
**该初始化接口可能速度很慢,返回超时不用管,注意看日志即可**
39-
40-
41-
## 功能介绍
4247

43-
### Fast GPT V4.6
48+
# V4.6功能介绍
4449

4550
1. 新增 - 团队空间
51+
2. 新增 - 多路向量(多个向量映射一组数据)
52+
3. 新增 - tts语音
53+
4. 线上环境新增 - ReRank向量召回,提高召回精度
54+
5. 优化 - 知识库导出,可直接触发流下载,无需等待转圈圈
Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
import { getErrText } from '../error/utils';
2+
import { countPromptTokens } from './tiktoken';
3+
4+
/**
5+
* text split into chunks
6+
* maxLen - one chunk len. max: 3500
7+
* overlapLen - The size of the before and after Text
8+
* maxLen > overlapLen
9+
* markdown
10+
*/
11+
export const splitText2Chunks = (props: { text: string; maxLen: number; overlapLen?: number }) => {
12+
const { text = '', maxLen, overlapLen = Math.floor(maxLen * 0.2) } = props;
13+
const tempMarker = 'SPLIT_HERE_SPLIT_HERE';
14+
15+
const stepReg: Record<number, RegExp> = {
16+
0: /^(#\s[^\n]+)\n/gm,
17+
1: /^(##\s[^\n]+)\n/gm,
18+
2: /^(###\s[^\n]+)\n/gm,
19+
3: /^(####\s[^\n]+)\n/gm,
20+
21+
4: /(\n\n)/g,
22+
5: /([\n])/g,
23+
6: /[]|(?!<[^a-zA-Z])\.\s/g,
24+
7: /([]|!\s|\?\s)/g,
25+
8: /([]|;\s)/g,
26+
9: /([]|,\s)/g
27+
};
28+
29+
const splitTextRecursively = ({
30+
text = '',
31+
step,
32+
lastChunk,
33+
overlayChunk
34+
}: {
35+
text: string;
36+
step: number;
37+
lastChunk: string;
38+
overlayChunk: string;
39+
}) => {
40+
if (text.length <= maxLen) {
41+
return [text];
42+
}
43+
const reg = stepReg[step];
44+
const isMarkdownSplit = step < 4;
45+
46+
if (!reg) {
47+
// use slice-maxLen to split text
48+
const chunks: string[] = [];
49+
let chunk = '';
50+
for (let i = 0; i < text.length; i += maxLen - overlapLen) {
51+
chunk = text.slice(i, i + maxLen);
52+
chunks.push(chunk);
53+
}
54+
return chunks;
55+
}
56+
57+
// split text by special char
58+
const splitTexts = text
59+
.replace(reg, isMarkdownSplit ? `${tempMarker}$1` : `$1${tempMarker}`)
60+
.split(`${tempMarker}`)
61+
.filter((part) => part);
62+
63+
let chunks: string[] = [];
64+
for (let i = 0; i < splitTexts.length; i++) {
65+
let text = splitTexts[i];
66+
let chunkToken = countPromptTokens(lastChunk, '');
67+
const textToken = countPromptTokens(text, '');
68+
69+
// next chunk is too large / new chunk is too large(The current chunk must be smaller than maxLen)
70+
if (textToken >= maxLen || chunkToken + textToken > maxLen * 1.4) {
71+
// last chunk is too large, push it to chunks, not add to next chunk
72+
if (chunkToken > maxLen * 0.7) {
73+
chunks.push(lastChunk);
74+
lastChunk = '';
75+
overlayChunk = '';
76+
}
77+
// chunk is small, insert to next chunks
78+
const innerChunks = splitTextRecursively({
79+
text,
80+
step: step + 1,
81+
lastChunk,
82+
overlayChunk
83+
});
84+
if (innerChunks.length === 0) continue;
85+
chunks = chunks.concat(innerChunks);
86+
lastChunk = '';
87+
overlayChunk = '';
88+
continue;
89+
}
90+
91+
// size less than maxLen, push text to last chunk
92+
lastChunk += text;
93+
chunkToken += textToken; // Definitely less than 1.4 * maxLen
94+
95+
// size over lapLen, push it to next chunk
96+
if (
97+
overlapLen !== 0 &&
98+
!isMarkdownSplit &&
99+
chunkToken >= maxLen - overlapLen &&
100+
textToken < overlapLen
101+
) {
102+
overlayChunk += text;
103+
}
104+
if (chunkToken >= maxLen) {
105+
chunks.push(lastChunk);
106+
lastChunk = overlayChunk;
107+
overlayChunk = '';
108+
}
109+
}
110+
111+
/* If the last chunk is independent, it needs to be push chunks. */
112+
if (lastChunk && chunks[chunks.length - 1] && !chunks[chunks.length - 1].endsWith(lastChunk)) {
113+
chunks.push(lastChunk);
114+
}
115+
116+
return chunks;
117+
};
118+
119+
try {
120+
const chunks = splitTextRecursively({ text, step: 0, lastChunk: '', overlayChunk: '' });
121+
122+
const tokens = chunks.reduce((sum, chunk) => sum + countPromptTokens(chunk, 'system'), 0);
123+
124+
return {
125+
chunks,
126+
tokens
127+
};
128+
} catch (err) {
129+
throw new Error(getErrText(err));
130+
}
131+
};
File renamed without changes.

projects/app/src/global/common/tiktoken/index.ts renamed to packages/global/common/string/tiktoken/index.ts

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
/* Only the token of gpt-3.5-turbo is used */
2-
import type { ChatItemType } from '@fastgpt/global/core/chat/type';
2+
import type { ChatItemType } from '../../../core/chat/type';
33
import { Tiktoken } from 'js-tiktoken/lite';
4-
import { adaptChat2GptMessages } from '@/utils/common/adapt/message';
5-
import { ChatCompletionRequestMessageRoleEnum } from '@fastgpt/global/core/ai/constant';
4+
import { adaptChat2GptMessages } from '../../../core/chat/adapt';
5+
import { ChatCompletionRequestMessageRoleEnum } from '../../../core/ai/constant';
66
import encodingJson from './cl100k_base.json';
77

88
/* init tikToken obj */
@@ -55,17 +55,6 @@ export function countMessagesTokens({ messages }: { messages: ChatItemType[] })
5555
return totalTokens;
5656
}
5757

58-
export function sliceTextByTokens({ text, length }: { text: string; length: number }) {
59-
const enc = getTikTokenEnc();
60-
61-
try {
62-
const encodeText = enc.encode(text);
63-
return enc.decode(encodeText.slice(0, length));
64-
} catch (error) {
65-
return text.slice(0, length);
66-
}
67-
}
68-
6958
/* slice messages from top to bottom by maxTokens */
7059
export function sliceMessagesTB({
7160
messages,
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import type { Tiktoken } from 'js-tiktoken';
2+
3+
declare global {
4+
var TikToken: Tiktoken;
5+
}

packages/global/common/string/tools.ts

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
import crypto from 'crypto';
22

3+
/* check string is a web link */
34
export function strIsLink(str?: string) {
45
if (!str) return false;
56
if (/^((http|https)?:\/\/|www\.|\/)[^\s/$.?#].[^\s]*$/i.test(str)) return true;
67
return false;
78
}
89

9-
export const hashStr = (psw: string) => {
10-
return crypto.createHash('sha256').update(psw).digest('hex');
10+
/* hash string */
11+
export const hashStr = (str: string) => {
12+
return crypto.createHash('sha256').update(str).digest('hex');
1113
};
1214

1315
/* simple text, remove chinese space and extra \n */
@@ -20,3 +22,16 @@ export const simpleText = (text: string) => {
2022

2123
return text;
2224
};
25+
26+
/*
27+
replace {{variable}} to value
28+
*/
29+
export function replaceVariable(text: string, obj: Record<string, string | number>) {
30+
for (const key in obj) {
31+
const val = obj[key];
32+
if (!['string', 'number'].includes(typeof val)) continue;
33+
34+
text = text.replace(new RegExp(`{{(${key})}}`, 'g'), String(val));
35+
}
36+
return text || '';
37+
}

packages/global/core/ai/api.d.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export type PostReRankProps = {
2+
query: string;
3+
inputs: { id: string; text: string }[];
4+
};
5+
export type PostReRankResponse = { id: string; score: number }[];

0 commit comments

Comments
 (0)