Skip to content

Commit 9639139

Browse files
authored
1 parent d9f5f4e commit 9639139

Some content is hidden

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

58 files changed

+4737
-305
lines changed
+84
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
name: Build fastgpt-sandbox images and copy image to docker hub
2+
on:
3+
workflow_dispatch:
4+
push:
5+
paths:
6+
- 'projects/sandbox/**'
7+
tags:
8+
- 'v*'
9+
jobs:
10+
build-fastgpt-sandbox-images:
11+
runs-on: ubuntu-20.04
12+
steps:
13+
- name: Checkout
14+
uses: actions/checkout@v3
15+
with:
16+
fetch-depth: 0
17+
- name: Install Dependencies
18+
run: |
19+
sudo apt update && sudo apt install -y nodejs npm
20+
- name: Set up QEMU (optional)
21+
uses: docker/setup-qemu-action@v2
22+
- name: Set up Docker Buildx
23+
uses: docker/setup-buildx-action@v2
24+
with:
25+
driver-opts: network=host
26+
- name: Cache Docker layers
27+
uses: actions/cache@v2
28+
with:
29+
path: /tmp/.buildx-cache
30+
key: ${{ runner.os }}-buildx-${{ github.sha }}
31+
restore-keys: |
32+
${{ runner.os }}-buildx-
33+
- name: Login to GitHub Container Registry
34+
uses: docker/login-action@v2
35+
with:
36+
registry: ghcr.io
37+
username: ${{ github.repository_owner }}
38+
password: ${{ secrets.GH_PAT }}
39+
- name: Set DOCKER_REPO_TAGGED based on branch or tag
40+
run: |
41+
if [[ "${{ github.ref_name }}" == "main" ]]; then
42+
echo "DOCKER_REPO_TAGGED=ghcr.io/${{ github.repository_owner }}/fastgpt-sandbox:latest" >> $GITHUB_ENV
43+
else
44+
echo "DOCKER_REPO_TAGGED=ghcr.io/${{ github.repository_owner }}/fastgpt-sandbox:${{ github.ref_name }}" >> $GITHUB_ENV
45+
fi
46+
- name: Build and publish image for main branch or tag push event
47+
env:
48+
DOCKER_REPO_TAGGED: ${{ env.DOCKER_REPO_TAGGED }}
49+
run: |
50+
docker buildx build \
51+
-f projects/sandbox/Dockerfile \
52+
--platform linux/amd64,linux/arm64 \
53+
--label "org.opencontainers.image.source=https://github.com/${{ github.repository_owner }}/fastgpt-sandbox" \
54+
--label "org.opencontainers.image.description=fastgpt-sandbox image" \
55+
--push \
56+
--cache-from=type=local,src=/tmp/.buildx-cache \
57+
--cache-to=type=local,dest=/tmp/.buildx-cache \
58+
-t ${DOCKER_REPO_TAGGED} \
59+
.
60+
push-to-ali-hub:
61+
needs: build-fastgpt-sandbox-images
62+
runs-on: ubuntu-20.04
63+
steps:
64+
- name: Checkout code
65+
uses: actions/checkout@v3
66+
- name: Login to Ali Hub
67+
uses: docker/login-action@v2
68+
with:
69+
registry: registry.cn-hangzhou.aliyuncs.com
70+
username: ${{ secrets.ALI_HUB_USERNAME }}
71+
password: ${{ secrets.ALI_HUB_PASSWORD }}
72+
- name: Set DOCKER_REPO_TAGGED based on branch or tag
73+
run: |
74+
if [[ "${{ github.ref_name }}" == "main" ]]; then
75+
echo "IMAGE_TAG=latest" >> $GITHUB_ENV
76+
else
77+
echo "IMAGE_TAG=${{ github.ref_name }}" >> $GITHUB_ENV
78+
fi
79+
- name: Pull image from GitHub Container Registry
80+
run: docker pull ghcr.io/${{ github.repository_owner }}/fastgpt-sandbox:${{env.IMAGE_TAG}}
81+
- name: Tag image with Docker Hub repository name and version tag
82+
run: docker tag ghcr.io/${{ github.repository_owner }}/fastgpt-sandbox:${{env.IMAGE_TAG}} ${{ secrets.ALI_IMAGE_NAME }}/fastgpt-sandbox:${{env.IMAGE_TAG}}
83+
- name: Push image to Docker Hub
84+
run: docker push ${{ secrets.ALI_IMAGE_NAME }}/fastgpt-sandbox:${{env.IMAGE_TAG}}

.github/workflows/fastgpt-image.yml

+1-2
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,14 @@ jobs:
4949
DOCKER_REPO_TAGGED: ${{ env.DOCKER_REPO_TAGGED }}
5050
run: |
5151
docker buildx build \
52-
--build-arg name=app \
52+
-f projects/app/Dockerfile \
5353
--platform linux/amd64,linux/arm64 \
5454
--label "org.opencontainers.image.source=https://github.com/${{ github.repository_owner }}/FastGPT" \
5555
--label "org.opencontainers.image.description=fastgpt image" \
5656
--push \
5757
--cache-from=type=local,src=/tmp/.buildx-cache \
5858
--cache-to=type=local,dest=/tmp/.buildx-cache \
5959
-t ${DOCKER_REPO_TAGGED} \
60-
-f Dockerfile \
6160
.
6261
push-to-docker-hub:
6362
needs: build-fastgpt-images

.github/workflows/preview-image.yml

+4-5
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,14 @@ jobs:
4444
DOCKER_REPO_TAGGED: ${{ env.DOCKER_REPO_TAGGED }}
4545
run: |
4646
docker buildx build \
47-
--build-arg name=app \
48-
--label "org.opencontainers.image.source= https://github.com/ ${{ github.repository_owner }}/FastGPT" \
49-
--label "org.opencontainers.image.description=fastgpt-pr image" \
50-
--label "org.opencontainers.image.licenses=Apache" \
47+
-f projects/app/Dockerfile \
48+
--label "org.opencontainers.image.source=https://github.com/${{ github.repository_owner }}/FastGPT" \
49+
--label "org.opencontainers.image.description=fastgpt-pr imae" \
50+
--label "org.opencontainers.image.licenses=Apache" \g
5151
--push \
5252
--cache-from=type=local,src=/tmp/.buildx-cache \
5353
--cache-to=type=local,dest=/tmp/.buildx-cache \
5454
-t ${DOCKER_REPO_TAGGED} \
55-
-f Dockerfile \
5655
.
5756
5857
helm-check:

Makefile

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# 定义默认变量
2+
proxy=null
3+
image=null
4+
5+
# 定义目标
6+
.PHONY: build
7+
8+
# 检查 target 是否定义
9+
ifndef name
10+
$(error name is not defined)
11+
endif
12+
13+
filePath=./projects/$(name)/Dockerfile
14+
15+
dev:
16+
pnpm --prefix ./projects/$(name) dev
17+
18+
build:
19+
ifeq ($(proxy), taobao)
20+
docker build -f $(filePath) -t $(image) . --build-arg proxy=taobao
21+
else ifeq ($(proxy), clash)
22+
docker build -f $(filePath) -t $(image) . --network host --build-arg HTTP_PROXY=http://127.0.0.1:7890 --build-arg HTTPS_PROXY=http://127.0.0.1:7890
23+
else
24+
docker build -f $(filePath) -t $(image) .
25+
endif

dev.md

+34-11
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,40 @@
1-
# 打包命令
1+
## Premise
2+
3+
Since FastGPT is managed in the same way as monorepo, it is recommended to install 'make' first during development.
4+
5+
monorepo Project Name:
6+
7+
- app: main project
8+
-......
9+
10+
## Dev
211

312
```sh
4-
# Build image, not proxy
5-
docker build -t registry.cn-hangzhou.aliyuncs.com/fastgpt/fastgpt:v4.4.7 --build-arg name=app .
13+
# Give automatic script code execution permission (on non-Linux systems, you can manually execute the postinstall.sh file content)
14+
chmod -R +x ./scripts/
15+
# Executing under the code root directory installs all dependencies within the root package, projects, and packages
16+
pnpm i
17+
18+
# Not make cmd
19+
cd projects/app
20+
pnpm dev
621

7-
# build image with proxy
8-
docker build -t registry.cn-hangzhou.aliyuncs.com/fastgpt/fastgpt:v4.4.7 --build-arg name=app --build-arg proxy=taobao .
22+
# Make cmd
23+
make dev name=app
924
```
1025

11-
# Pg 常用索引
1226

13-
```sql
14-
CREATE INDEX IF NOT EXISTS modelData_dataset_id_index ON modeldata (dataset_id);
15-
CREATE INDEX IF NOT EXISTS modelData_collection_id_index ON modeldata (collection_id);
16-
CREATE INDEX IF NOT EXISTS modelData_teamId_index ON modeldata (team_id);
17-
```
27+
## Build
28+
29+
```sh
30+
# Docker cmd: Build image, not proxy
31+
docker build -f ./projects/app/Dockerfile -t registry.cn-hangzhou.aliyuncs.com/fastgpt/fastgpt:v4.8.1 . --build-arg name=app
32+
# Make cmd: Build image, not proxy
33+
make build name=app image=registry.cn-hangzhou.aliyuncs.com/fastgpt/fastgpt:v4.8.1
34+
35+
# Docker cmd: Build image with proxy
36+
docker build -f ./projects/app/Dockerfile -t registry.cn-hangzhou.aliyuncs.com/fastgpt/fastgpt:v4.8.1 . --build-arg name=app --build-arg proxy=taobao
37+
# Make cmd: Build image with proxy
38+
make build name=app image=registry.cn-hangzhou.aliyuncs.com/fastgpt/fastgpt:v4.8.1 proxy=taobao
39+
```
40+

docSite/content/docs/development/intro.md

+24-13
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@ weight: 705
1616

1717
- [Git](http://git-scm.com/)
1818
- [Docker](https://www.docker.com/)(构建镜像)
19-
- [Node.js v18.x (不推荐最新的,可能有兼容问题)](http://nodejs.org)
20-
- [pnpm](https://pnpm.io/) 版本 8.x.x
19+
- [Node.js v18.17 / v20.x](http://nodejs.org)
20+
- [pnpm](https://pnpm.io/) 版本 8.6.0 (目前官方的开发环境)
21+
- make命令: 根据不同平台,百度安装 (官方是GNU Make 4.3)
2122

2223
## 开始本地开发
2324

@@ -72,24 +73,34 @@ Mongo 数据库需要注意,需要注意在连接地址中增加 `directConnec
7273

7374
### 5. 运行
7475

76+
可参考项目根目录下的 `dev.md`
77+
7578
```bash
7679
# 给自动化脚本代码执行权限(非 linux 系统, 可以手动执行里面的 postinstall.sh 文件内容)
7780
chmod -R +x ./scripts/
7881
# 代码根目录下执行,会安装根 package、projects 和 packages 内所有依赖
7982
pnpm i
80-
# 切换到应用目录
81-
cd projects/app
82-
# 开发模式运行
83+
84+
# 非 Make 运行
85+
cd projects/app
8386
pnpm dev
87+
88+
# Make 运行
89+
make dev name=app
8490
```
8591

8692
### 6. 部署打包
8793

8894
```bash
89-
# 根目录下执行
90-
docker build -t dockername/fastgpt:tag --build-arg name=app .
91-
# 使用代理
92-
docker build -t dockername/fastgpt:tag --build-arg name=app --build-arg proxy=taobao .
95+
# Docker cmd: Build image, not proxy
96+
docker build -f ./projects/app/Dockerfile -t registry.cn-hangzhou.aliyuncs.com/fastgpt/fastgpt:v4.8.1 . --build-arg name=app
97+
# Make cmd: Build image, not proxy
98+
make build name=app image=registry.cn-hangzhou.aliyuncs.com/fastgpt/fastgpt:v4.8.1
99+
100+
# Docker cmd: Build image with proxy
101+
docker build -f ./projects/app/Dockerfile -t registry.cn-hangzhou.aliyuncs.com/fastgpt/fastgpt:v4.8.1 . --build-arg name=app --build-arg proxy=taobao
102+
# Make cmd: Build image with proxy
103+
make build name=app image=registry.cn-hangzhou.aliyuncs.com/fastgpt/fastgpt:v4.8.1 proxy=taobao
93104
```
94105

95106
## 提交代码至开源仓库
@@ -101,21 +112,21 @@ docker build -t dockername/fastgpt:tag --build-arg name=app --build-arg proxy=ta
101112
如果遇到问题,比如合并冲突或不知道如何打开拉取请求,请查看 GitHub 的[拉取请求教程](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests),了解如何解决合并冲突和其他问题。一旦您的 PR 被合并,您将自豪地被列为[贡献者表](https://github.com/labring/FastGPT/graphs/contributors)中的一员。
102113

103114

104-
105115
## QA
106116

107117
### 本地数据库无法连接
108118

109119
1. 如果你是连接远程的数据库,先检查对应的端口是否开放。
110120
2. 如果是本地运行的数据库,可尝试`host`改成`localhost``127.0.0.1`
121+
3. 本地连接远程的 Mongo,需要增加 `directConnection=true` 参数,才能连接上副本集的数据库。
122+
4. mongo使用`mongocompass`客户端进行连接测试和可视化管理。
123+
5. pg使用`navicat`进行连接和管理。
111124

112125
### sh ./scripts/postinstall.sh 没权限
113126

114127
FastGPT 在`pnpm i`后会执行`postinstall`脚本,用于自动生成`ChakraUI``Type`。如果没有权限,可以先执行`chmod -R +x ./scripts/`,再执行`pnpm i`
115128

116-
### 长时间运行后崩溃
117-
118-
似乎是由于 tiktoken 库的开发环境问题,生产环境中未遇到,暂时可忽略。
129+
仍不可行的话,可以手动执行`./scripts/postinstall.sh`里的内容。
119130

120131
### TypeError: Cannot read properties of null (reading 'useMemo' )
121132

packages/global/core/workflow/constants.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,11 @@ export enum NodeInputKeyEnum {
108108
ifElseList = 'ifElseList',
109109

110110
// variable update
111-
updateList = 'updateList'
111+
updateList = 'updateList',
112+
113+
// code
114+
code = 'code',
115+
codeType = 'codeType' // js|py
112116
}
113117

114118
export enum NodeOutputKeyEnum {
@@ -121,6 +125,7 @@ export enum NodeOutputKeyEnum {
121125
error = 'error',
122126
text = 'system_text',
123127
addOutputParam = 'system_addOutputParam',
128+
rawResponse = 'system_rawResponse',
124129

125130
// dataset
126131
datasetQuoteQA = 'quoteQA',

packages/global/core/workflow/node/constant.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,8 @@ export enum FlowNodeTypeEnum {
113113
stopTool = 'stopTool',
114114
lafModule = 'lafModule',
115115
ifElseNode = 'ifElseNode',
116-
variableUpdate = 'variableUpdate'
116+
variableUpdate = 'variableUpdate',
117+
code = 'code'
117118
}
118119

119120
export const EDGE_TYPE = 'default';

packages/global/core/workflow/runtime/type.d.ts

+2
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ export type DispatchNodeResponseType = {
3131
runningTime?: number;
3232
query?: string;
3333
textOutput?: string;
34+
customInputs?: Record<string, any>;
35+
customOutputs?: Record<string, any>;
3436

3537
// bill
3638
tokens?: number;

packages/global/core/workflow/template/constants.ts

+7-3
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import type { FlowNodeTemplateType } from '../type';
2222
import { LafModule } from './system/laf';
2323
import { IfElseNode } from './system/ifElse/index';
2424
import { VariableUpdateNode } from './system/variableUpdate';
25+
import { CodeNode } from './system/sandbox';
2526

2627
/* app flow module templates */
2728
export const appSystemModuleTemplates: FlowNodeTemplateType[] = [
@@ -40,7 +41,8 @@ export const appSystemModuleTemplates: FlowNodeTemplateType[] = [
4041
AiQueryExtension,
4142
LafModule,
4243
IfElseNode,
43-
VariableUpdateNode
44+
VariableUpdateNode,
45+
CodeNode
4446
];
4547
/* plugin flow module templates */
4648
export const pluginSystemModuleTemplates: FlowNodeTemplateType[] = [
@@ -59,7 +61,8 @@ export const pluginSystemModuleTemplates: FlowNodeTemplateType[] = [
5961
AiQueryExtension,
6062
LafModule,
6163
IfElseNode,
62-
VariableUpdateNode
64+
VariableUpdateNode,
65+
CodeNode
6366
];
6467

6568
/* all module */
@@ -84,5 +87,6 @@ export const moduleTemplatesFlat: FlowNodeTemplateType[] = [
8487
AiQueryExtension,
8588
LafModule,
8689
IfElseNode,
87-
VariableUpdateNode
90+
VariableUpdateNode,
91+
CodeNode
8892
];
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
export const JS_TEMPLATE = `function main({data1, data2}){
2+
3+
return {
4+
result: data1,
5+
data2
6+
}
7+
}`;

0 commit comments

Comments
 (0)