V4.6.9-first commit (#899)

* perf: insert mongo dataset data session

* perf: dataset data index

* remove delay

* rename bill schema

* rename bill record

* perf: bill table

* perf: prompt

* perf: sub plan

* change the usage count

* feat: usage bill

* publish usages

* doc

* 新增团队聊天功能 (#20)

* perf: doc

* feat 添加标签部分

feat 信息团队标签配置

feat 新增团队同步管理

feat team分享页面

feat 完成team分享页面

feat 实现模糊搜索

style 格式化

fix 修复迷糊匹配

style 样式修改

fix 团队标签功能修复

* fix 修复鉴权功能

* merge 合并代码

* fix 修复引用错误

* fix 修复pr问题

* fix 修复ts格式问题

---------

Co-authored-by: archer <545436317@qq.com>
Co-authored-by: liuxingwan <liuxingwan.lxw@alibaba-inc.com>

* update extra plan

* fix: ts

* format

* perf: bill field

* feat: standard plan

* fix: ts

* feat 个人账号页面修改 (#22)

* feat 添加标签部分

feat 信息团队标签配置

feat 新增团队同步管理

feat team分享页面

feat 完成team分享页面

feat 实现模糊搜索

style 格式化

fix 修复迷糊匹配

style 样式修改

fix 团队标签功能修复

* fix 修复鉴权功能

* merge 合并代码

* fix 修复引用错误

* fix 修复pr问题

* fix 修复ts格式问题

* feat 修改个人账号页

---------

Co-authored-by: liuxingwan <liuxingwan.lxw@alibaba-inc.com>

* sub plan page (#23)

* fix chunk index; error page text

* feat: dataset process Integral prediction

* feat: stand plan field

* feat: sub plan limit

* perf: index

* query extension

* perf: share link push app name

* perf: plan point unit

* perf: get sub plan

* perf: account page

* feat 新增套餐详情弹窗代码 (#24)

* merge 合并代码

* fix 新增套餐详情弹框

* fix 修复pr问题

* feat: change http node input to prompt editor (#21)

* feat: change http node input to prompt editor

* fix

* split PromptEditor to HttpInput

* Team plans (#25)

* perf: pay check

* perf: team plan test

* plan limit check

* replace sensitive text

* perf: fix some null

* collection null check

* perf: plans modal

* perf: http module

* pacakge (#26)

* individuation page and pay modal amount (#27)

* feat: individuation page

* team chat config

* pay modal

* plan count and replace invalid chars (#29)

* fix: user oneapi

* fix: training queue

* fix: qa queue

* perf: remove space chars

* replace invalid chars

* change httpinput dropdown menu (#28)

* perf: http

* reseet free plan

* perf: plan code to packages

* remove llm config to package

* perf: code

* perf: faq

* fix: get team plan

---------

Co-authored-by: yst <77910600+yu-and-liu@users.noreply.github.com>
Co-authored-by: liuxingwan <liuxingwan.lxw@alibaba-inc.com>
Co-authored-by: heheer <71265218+newfish-cmyk@users.noreply.github.com>
This commit is contained in:
Archer
2024-02-28 13:19:15 +08:00
committed by GitHub
parent 32686f9e3e
commit 064c64e74c
282 changed files with 7223 additions and 4731 deletions

View File

@@ -10,6 +10,6 @@
"i18n-ally.keystyle": "nested",
"i18n-ally.sortKeys": true,
"i18n-ally.keepFulfilled": true,
"i18n-ally.sourceLanguage": "zh", // 根据此语言文件翻译其他语言文件的变量和内容
"i18n-ally.sourceLanguage": "en", // 根据此语言文件翻译其他语言文件的变量和内容
"i18n-ally.displayLanguage": "en", // 显示语言
}

View File

@@ -56,7 +56,7 @@ FastGPT 采用了`PostgresSQL`的`PG Vector`插件作为向量检索器,索引
### 检索方案
1. 通过`问题补全`实现指代消除和问题扩展,从而增加连续对话的检索能力以及语义丰富度。
1. 通过`问题优化`实现指代消除和问题扩展,从而增加连续对话的检索能力以及语义丰富度。
2. 通过`Concat query`来增加`Rerank`连续对话的时,排序的准确性。
3. 通过`RRF`合并方式,综合多个渠道的检索效果。
4. 通过`Rerank`来二次排序,提高精度。
@@ -97,7 +97,7 @@ FastGPT 采用了`PostgresSQL`的`PG Vector`插件作为向量检索器,索引
#### 结果重排
利用`ReRank`模型对搜索结果进行重排,绝大多数情况下,可以有效提高搜索结果的准确率。不过,重排模型与问题的完整度(主谓语齐全)有一些关系,通常会先走问题补全后再进行搜索-重排。重排后可以得到一个`0-1`的得分,代表着搜索内容与问题的相关度,该分数通常比向量的得分更加精确,可以根据得分进行过滤。
利用`ReRank`模型对搜索结果进行重排,绝大多数情况下,可以有效提高搜索结果的准确率。不过,重排模型与问题的完整度(主谓语齐全)有一些关系,通常会先走问题优化后再进行搜索-重排。重排后可以得到一个`0-1`的得分,代表着搜索内容与问题的相关度,该分数通常比向量的得分更加精确,可以根据得分进行过滤。
FastGPT 会使用 `RRF` 对重排结果、向量搜索结果、全文检索结果进行合并,得到最终的搜索结果。
@@ -115,7 +115,7 @@ FastGPT 会使用 `RRF` 对重排结果、向量搜索结果、全文检索结
该值仅在`语义检索`或使用`结果重排`时生效。
### 问题补全
### 问题优化
#### 背景
@@ -125,7 +125,7 @@ FastGPT 会使用 `RRF` 对重排结果、向量搜索结果、全文检索结
![](/imgs/coreferenceResolution2.jpg)
用户在提问“第二点是什么”的时候只会去知识库里查找“第二点是什么”压根查不到内容。实际上需要查询的是“QA结构是什么”。因此我们需要引入一个【问题补全】模块,来对用户当前的问题进行补全,从而使得知识库搜索能够搜索到合适的内容。使用补全后效果如下:
用户在提问“第二点是什么”的时候只会去知识库里查找“第二点是什么”压根查不到内容。实际上需要查询的是“QA结构是什么”。因此我们需要引入一个【问题优化】模块,来对用户当前的问题进行补全,从而使得知识库搜索能够搜索到合适的内容。使用补全后效果如下:
![](/imgs/coreferenceResolution3.jpg)

View File

@@ -13,163 +13,7 @@ weight: 708
这个配置文件中包含了系统级参数、AI 对话的模型、function 模型等……
## 4.6.8 以前版本完整配置参数
**使用时,请务必去除注释!**
以下配置适用于V4.6.6-alpha版本以后
```json
{
"systemEnv": {
"vectorMaxProcess": 15, // 向量生成最大进程,结合数据库性能和 key 来设置
"qaMaxProcess": 15, // QA 生成最大进程,结合数据库性能和 key 来设置
"pgHNSWEfSearch": 100 // pg vector 索引参数,越大精度高但速度慢
},
"chatModels": [ // 对话模型
{
"model": "gpt-3.5-turbo-1106",
"name": "GPT35-1106",
"inputPrice": 0, // 输入价格。 xx元/1k tokens
"outputPrice": 0, // 输出价格。 xx元/1k tokens
"maxContext": 16000, // 最大上下文长度
"maxResponse": 4000, // 最大回复长度
"quoteMaxToken": 2000, // 最大引用内容长度
"maxTemperature": 1.2, // 最大温度值
"censor": false, // 是否开启敏感词过滤(商业版)
"vision": false, // 支持图片输入
"defaultSystemChatPrompt": ""
},
{
"model": "gpt-3.5-turbo-16k",
"name": "GPT35-16k",
"maxContext": 16000,
"maxResponse": 16000,
"inputPrice": 0,
"outputPrice": 0,
"quoteMaxToken": 8000,
"maxTemperature": 1.2,
"censor": false,
"vision": false,
"defaultSystemChatPrompt": ""
},
{
"model": "gpt-4",
"name": "GPT4-8k",
"maxContext": 8000,
"maxResponse": 8000,
"inputPrice": 0,
"outputPrice": 0,
"quoteMaxToken": 4000,
"maxTemperature": 1.2,
"censor": false,
"vision": false,
"defaultSystemChatPrompt": ""
},
{
"model": "gpt-4-vision-preview",
"name": "GPT4-Vision",
"maxContext": 128000,
"maxResponse": 4000,
"inputPrice": 0,
"outputPrice": 0,
"quoteMaxToken": 100000,
"maxTemperature": 1.2,
"censor": false,
"vision": true,
"defaultSystemChatPrompt": ""
}
],
"qaModels": [ // QA 生成模型
{
"model": "gpt-3.5-turbo-16k",
"name": "GPT35-16k",
"maxContext": 16000,
"maxResponse": 16000,
"inputPrice": 0,
"outputPrice": 0
}
],
"cqModels": [ // 问题分类模型
{
"model": "gpt-3.5-turbo-1106",
"name": "GPT35-1106",
"maxContext": 16000,
"maxResponse": 4000,
"inputPrice": 0,
"outputPrice": 0,
"toolChoice": true, // 是否支持openai的 toolChoice 不支持的模型需要设置为 false会走提示词生成
"functionPrompt": ""
},
{
"model": "gpt-4",
"name": "GPT4-8k",
"maxContext": 8000,
"maxResponse": 8000,
"inputPrice": 0,
"outputPrice": 0,
"toolChoice": true,
"functionPrompt": ""
}
],
"extractModels": [ // 内容提取模型
{
"model": "gpt-3.5-turbo-1106",
"name": "GPT35-1106",
"maxContext": 16000,
"maxResponse": 4000,
"inputPrice": 0,
"outputPrice": 0,
"toolChoice": true,
"functionPrompt": ""
}
],
"qgModels": [ // 生成下一步指引
{
"model": "gpt-3.5-turbo-1106",
"name": "GPT35-1106",
"maxContext": 1600,
"maxResponse": 4000,
"inputPrice": 0,
"outputPrice": 0
}
],
"vectorModels": [ // 向量模型
{
"model": "text-embedding-ada-002",
"name": "Embedding-2",
"inputPrice": 0,
"defaultToken": 700,
"maxToken": 3000
}
],
"reRankModels": [], // 重排模型,暂时填空数组
"audioSpeechModels": [
{
"model": "tts-1",
"name": "OpenAI TTS1",
"inputPrice": 0,
"baseUrl": "",
"key": "",
"voices": [
{ "label": "Alloy", "value": "alloy", "bufferId": "openai-Alloy" },
{ "label": "Echo", "value": "echo", "bufferId": "openai-Echo" },
{ "label": "Fable", "value": "fable", "bufferId": "openai-Fable" },
{ "label": "Onyx", "value": "onyx", "bufferId": "openai-Onyx" },
{ "label": "Nova", "value": "nova", "bufferId": "openai-Nova" },
{ "label": "Shimmer", "value": "shimmer", "bufferId": "openai-Shimmer" }
]
}
],
"whisperModel": {
"model": "whisper-1",
"name": "Whisper1",
"inputPrice": 0
}
}
```
## 4.6.8 新配置文件
## 4.6.8+ 版本新配置文件
llm模型全部合并
@@ -189,11 +33,10 @@ llm模型全部合并
"maxResponse": 4000, // 最大回复
"quoteMaxToken": 13000, // 最大引用内容
"maxTemperature": 1.2, // 最大温度
"inputPrice": 0,
"outputPrice": 0,
"charsPointsPrice": 0,
"censor": false,
"vision": false, // 是否支持图片输入
"datasetProcess": false, // 是否设置为知识库处理模型
"datasetProcess": false, // 是否设置为知识库处理模型QA务必保证至少有一个为true否则知识库会报错
"toolChoice": true, // 是否支持工具选择
"functionCall": false, // 是否支持函数调用
"customCQPrompt": "", // 自定义文本分类提示词(不支持工具和函数调用的模型
@@ -208,8 +51,7 @@ llm模型全部合并
"maxResponse": 16000,
"quoteMaxToken": 13000,
"maxTemperature": 1.2,
"inputPrice": 0,
"outputPrice": 0,
"charsPointsPrice": 0,
"censor": false,
"vision": false,
"datasetProcess": true,
@@ -227,8 +69,7 @@ llm模型全部合并
"maxResponse": 4000,
"quoteMaxToken": 100000,
"maxTemperature": 1.2,
"inputPrice": 0,
"outputPrice": 0,
"charsPointsPrice": 0,
"censor": false,
"vision": false,
"datasetProcess": false,
@@ -246,10 +87,9 @@ llm模型全部合并
"maxResponse": 4000,
"quoteMaxToken": 100000,
"maxTemperature": 1.2,
"inputPrice": 0,
"outputPrice": 0,
"charsPointsPrice": 0,
"censor": false,
"vision": false,
"vision": true,
"datasetProcess": false,
"toolChoice": true,
"functionCall": false,
@@ -263,8 +103,7 @@ llm模型全部合并
{
"model": "text-embedding-ada-002",
"name": "Embedding-2",
"inputPrice": 0,
"outputPrice": 0,
"charsPointsPrice": 0,
"defaultToken": 700,
"maxToken": 3000,
"weight": 100,
@@ -276,8 +115,7 @@ llm模型全部合并
{
"model": "tts-1",
"name": "OpenAI TTS1",
"inputPrice": 0,
"outputPrice": 0,
"charsPointsPrice": 0,
"voices": [
{ "label": "Alloy", "value": "alloy", "bufferId": "openai-Alloy" },
{ "label": "Echo", "value": "echo", "bufferId": "openai-Echo" },
@@ -291,8 +129,7 @@ llm模型全部合并
"whisperModel": {
"model": "whisper-1",
"name": "Whisper1",
"inputPrice": 0,
"outputPrice": 0
"charsPointsPrice": 0
}
}
```
@@ -313,7 +150,7 @@ llm模型全部合并
{
"model": "bge-reranker-base", // 随意
"name": "检索重排-base", // 随意
"inputPrice": 0,
"charsPointsPrice": 0,
"requestUrl": "{{host}}/api/v1/rerank",
"requestAuth": "安全凭证,已自动补 Bearer"
}

View File

@@ -110,6 +110,7 @@ curl -O https://raw.githubusercontent.com/labring/FastGPT/main/projects/app/data
cd 项目目录
# 创建 mongo 密钥
openssl rand -base64 756 > ./mongodb.key
# 600不行可以用chmod 999
chmod 600 ./mongodb.key
chown 999:root ./mongodb.key
# 启动容器

View File

@@ -116,8 +116,7 @@ CHAT_API_KEY=sk-xxxxxx
"maxResponse": 4000, // 最大回复
"quoteMaxToken": 13000, // 最大引用内容
"maxTemperature": 1.2, // 最大温度
"inputPrice": 0,
"outputPrice": 0,
"charsPointsPrice": 0,
"censor": false,
"vision": false, // 是否支持图片输入
"datasetProcess": false, // 是否设置为知识库处理模型

View File

@@ -13,12 +13,25 @@ weight: 853
## 创建训练订单
## 创建训练订单(4.6.9地址发生改动)
{{< tabs tabTotal="2" >}}
{{< tab tabName="请求示例" >}}
{{< markdownify >}}
**新例子**
```bash
curl --location --request POST 'https://api.fastgpt.in/api/support/wallet/usage/createTrainingUsage' \
--header 'Authorization: Bearer {{apikey}}' \
--header 'Content-Type: application/json' \
--data-raw '{
"name": "可选,自定义订单名称,例如:文档训练-fastgpt.docx"
}'
```
**x例子**
```bash
curl --location --request POST 'https://api.fastgpt.in/api/support/wallet/bill/createTrainingBill' \
--header 'Authorization: Bearer {{apikey}}' \
@@ -154,7 +167,7 @@ curl --location --request GET 'http://localhost:3000/api/core/dataset/list?paren
"vectorModel": {
"model": "text-embedding-ada-002",
"name": "Embedding-2",
"inputPrice": 0,
"charsPointsPrice": 0,
"defaultToken": 512,
"maxToken": 8000,
"weight": 100
@@ -213,7 +226,7 @@ curl --location --request GET 'http://localhost:3000/api/core/dataset/detail?id=
"vectorModel": {
"model": "text-embedding-ada-002",
"name": "Embedding-2",
"inputPrice": 0,
"charsPointsPrice": 0,
"defaultToken": 512,
"maxToken": 8000,
"weight": 100
@@ -223,8 +236,7 @@ curl --location --request GET 'http://localhost:3000/api/core/dataset/detail?id=
"name": "FastAI-16k",
"maxContext": 16000,
"maxResponse": 16000,
"inputPrice": 0,
"outputPrice": 0
"charsPointsPrice": 0
},
"intro": "",
"permission": "private",
@@ -800,6 +812,33 @@ curl --location --request DELETE 'http://localhost:3000/api/core/dataset/collect
## 数据
### 数据的结构
**Data结构**
| 字段 | 类型 | 说明 | 必填 |
| --- | --- | --- | --- |
| teamId | String | 团队ID | ✅ |
| tmbId | String | 成员ID | ✅ |
| datasetId | String | 知识库ID | ✅ |
| collectionId | String | 集合ID | ✅ |
| q | String | 主要数据 | ✅ |
| a | String | 辅助数据 | ✖ |
| fullTextToken | String | 分词 | ✖ |
| indexes | Index[] | 向量索引 | ✅ |
| updateTime | Date | 更新时间 | ✅ |
| chunkIndex | Number | 分块下表 | ✖ |
**Index结构**
每组数据的自定义索引最多5个
| 字段 | 类型 | 说明 | 必填 |
| --- | --- | --- | --- |
| defaultIndex | Boolean | 是否为默认索引 | ✅ |
| dataId | String | 关联的向量ID | ✅ |
| text | String | 文本内容 | ✅ |
### 为集合批量添加添加数据
注意,每次最多推送 200 组数据。
@@ -825,11 +864,14 @@ curl --location --request POST 'https://api.fastgpt.in/api/core/dataset/data/pus
{
"q": "你会什么?",
"a": "我什么都会",
"indexes": [{
"defaultIndex": false,
"type":"custom",
"text":"自定义索引,不使用默认索引"
}]
"indexes": [
{
"text":"自定义索引1"
},
{
"text":"自定义索引2"
}
]
}
]
}'
@@ -850,7 +892,7 @@ curl --location --request POST 'https://api.fastgpt.in/api/core/dataset/data/pus
- data具体数据
- q: 主要数据(必填)
- a: 辅助数据(选填)
- indexes: 自定义索引(选填)不传入则默认使用q和a构建索引。也可以传入
- indexes: 自定义索引(选填)。可以不传或者传空数组默认都会使用q和a组成一个索引。
{{% /alert %}}
{{< /markdownify >}}
@@ -866,7 +908,6 @@ curl --location --request POST 'https://api.fastgpt.in/api/core/dataset/data/pus
"data": {
"insertLen": 1, // 最终插入成功的数量
"overToken": [], // 超出 token 的
"repeat": [], // 重复的数量
"error": [] // 其他错误
}
@@ -1050,7 +1091,16 @@ curl --location --request PUT 'http://localhost:3000/api/core/dataset/data/updat
"id":"65abd4b29d1448617cba61db",
"q":"测试111",
"a":"sss",
"indexes":[]
"indexes":[
{
"dataId": "xxx",
"defaultIndex":false,
"text":"自定义索引1"
},
{
"text":"修改后的自定义索引2。会删除原来的自定义索引2并插入新的自定义索引2"
}
]
}'
```
@@ -1064,7 +1114,7 @@ curl --location --request PUT 'http://localhost:3000/api/core/dataset/data/updat
- id: 数据的id
- q: 主要数据(选填)
- a: 辅助数据(选填)
- indexes: 自定义索引(选填),类型参考`为集合批量添加添加数据`建议直接不传。更新q,a后如果有默认索引则会直接更新默认索引。
- indexes: 自定义索引(选填),类型参考`为集合批量添加添加数据`。如果创建时候有自定义索引,
{{% /alert %}}
{{< /markdownify >}}

View File

@@ -169,8 +169,6 @@ curl --location --request POST '{{host}}/shareAuth/start' \
响应值与[chat 接口格式相同](/docs/development/openapi/chat/#响应),仅多了一个`token`
可以重点关注`responseData`里的`price`值,`price`与实际价格的倍率为`100000`,即 100000=1元。
```bash
curl --location --request POST '{{host}}/shareAuth/finish' \
--header 'Content-Type: application/json' \
@@ -178,72 +176,117 @@ curl --location --request POST '{{host}}/shareAuth/finish' \
"token": "{{authToken}}",
"responseData": [
{
"moduleName": "KB Search",
"price": 1.2000000000000002,
"model": "Embedding-2",
"tokens": 6,
"similarity": 0.61,
"limit": 3
"moduleName": "core.module.template.Dataset search",
"moduleType": "datasetSearchNode",
"totalPoints": 1.5278,
"query": "导演是谁\n《铃芽之旅》的导演是谁\n这部电影的导演是谁\n谁是《铃芽之旅》的导演",
"model": "Embedding-2(旧版,不推荐使用)",
"charsLength": 1524,
"similarity": 0.83,
"limit": 400,
"searchMode": "embedding",
"searchUsingReRank": false,
"extensionModel": "FastAI-4k",
"extensionResult": "《铃芽之旅》的导演是谁?\n这部电影的导演是谁\n谁是《铃芽之旅》的导演",
"runningTime": 2.15
},
{
"moduleName": "AI Chat",
"price": 454.5,
"moduleName": "AI 对话",
"moduleType": "chatNode",
"totalPoints": 0.593,
"model": "FastAI-4k",
"tokens": 303,
"question": "导演是谁",
"answer": "电影《铃芽之旅》的导演是新海诚。",
"maxToken": 2050,
"charsLength": 593,
"query": "导演是谁",
"maxToken": 2000,
"quoteList": [
{
"dataset_id": "646627f4f7b896cfd8910e38",
"id": "8099",
"q": "本作的主人公是谁?",
"a": "本作的主人公是名叫铃芽的少女。",
"source": "手动修改"
},
{
"dataset_id": "646627f4f7b896cfd8910e38",
"id": "8686",
"q": "电影《铃芽之旅》男主角是谁?",
"a": "电影《铃芽之旅》男主角是宗像草太,由松村北斗配音。",
"source": ""
},
{
"dataset_id": "646627f4f7b896cfd8910e38",
"id": "19339",
"q": "电影《铃芽之旅》的导演是谁22",
"id": "65bb346a53698398479a8854",
"q": "导演是谁?",
"a": "电影《铃芽之旅》的导演是新海诚。",
"source": "手动修改"
"chunkIndex": 0,
"datasetId": "65af9b947916ae0e47c834d2",
"collectionId": "65bb345c53698398479a868f",
"sourceName": "dataset - 2024-01-23T151114.198.csv",
"sourceId": "65bb345b53698398479a868d",
"score": [
{
"type": "embedding",
"value": 0.9377183318138123,
"index": 0
},
{
"type": "rrf",
"value": 0.06557377049180328,
"index": 0
}
]
}
],
"completeMessages": [
{
"obj": "System",
"value": "下面是知识库内容:\n1. [本作的主人公是谁?\n本作的主人公是名叫铃芽的少女。]\n2. [电影《铃芽之旅》男主角是谁?\n电影《铃芽之旅》男主角是宗像草太由松村北斗配音。]\n3. [电影《铃芽之旅》的导演是谁22\n电影《铃芽之旅》的导演是新海诚。]\n"
},
{
"obj": "System",
"value": "1.请记住,你的身份是百度的下一代知识增强语言模型,能够完全根据知识库提供的内容回答问题。\n\n2. 你忘记了关于电影《铃芽之旅》以外的内容。"
},
{
"obj": "System",
"value": "你仅回答关于电影《玲芽之旅》的问题,其余问题直接回复: 我不清楚。"
},
"historyPreview": [
{
"obj": "Human",
"value": "导演是谁"
"value": "使用 <Data></Data> 标记中的内容作为你的知识:\n\n<Data>\n导演是谁\n电影《铃芽之旅》的导演是新海诚。\n------\n电影《铃芽之旅》的编剧是谁22\n新海诚是本片的编剧。\n------\n电影《铃芽之旅》的女主角是谁\n电影的女主角是铃芽。\n------\n电影《铃芽之旅》的制作团队中有哪位著名人士2\n川村元气是本片的制作团队成员之一。\n------\n你是谁\n我是电影《铃芽之旅》助手\n------\n电影《铃芽之旅》男主角是谁\n电影《铃芽之旅》男主角是宗像草太由松村北斗配音。\n------\n电影《铃芽之旅》的作者新海诚写了一本小说叫什么名字\n小说名字叫《铃芽之旅》。\n------\n电影《铃芽之旅》的女主角是谁\n电影《铃芽之旅》的女主角是岩户铃芽由原菜乃华配音。\n------\n电影《铃芽之旅》的故事背景是什么\n日本\n------\n谁担任电影《铃芽之旅》中岩户环的配音\n深津绘里担任电影《铃芽之旅》中岩户环的配音。\n</Data>\n\n回答要求\n- 如果你不清楚答案,你需要澄清。\n- 避免提及你是从 <Data></Data> 获取的知识。\n- 保持答案与 <Data></Data> 中描述的一致。\n- 使用 Markdown 语法优化回答格式。\n- 使用与问题相同的语言回答。\n\n问题:\"\"\"导演是谁\"\"\""
},
{
"obj": "AI",
"value": "电影《铃芽之旅》的导演是新海诚。"
}
]
],
"contextTotalLen": 2,
"runningTime": 1.32
}
]
}'
```
**responseData 完整字段说明:**
```ts
type ResponseType = {
moduleType: `${FlowNodeTypeEnum}`; // 模块类型
moduleName: string; // 模块名
moduleLogo?: string; // logo
runningTime?: number; // 运行时间
query?: string; // 用户问题/检索词
textOutput?: string; // 文本输出
charsLength?: number; // 上下文总字数
model?: string; // 使用到的模型
contextTotalLen?: number; // 上下文总长度
totalPoints?: number; // 总消耗AI积分
temperature?: number; // 温度
maxToken?: number; // 模型的最大token
quoteList?: SearchDataResponseItemType[]; // 引用列表
historyPreview?: ChatItemType[]; // 上下文预览(历史记录会被裁剪)
similarity?: number; // 最低相关度
limit?: number; // 引用上限token
searchMode?: `${DatasetSearchModeEnum}`; // 搜索模式
searchUsingReRank?: boolean; // 是否使用rerank
extensionModel?: string; // 问题扩展模型
extensionResult?: string; // 问题扩展结果
extensionCharsLength?: number; // 问题扩展总字符长度
cqList?: ClassifyQuestionAgentItemType[]; // 分类问题列表
cqResult?: string; // 分类问题结果
extractDescription?: string; // 内容提取描述
extractResult?: Record<string, any>; // 内容提取结果
params?: Record<string, any>; // HTTP模块params
body?: Record<string, any>; // HTTP模块body
headers?: Record<string, any>; // HTTP模块headers
httpResult?: Record<string, any>; // HTTP模块结果
pluginOutput?: Record<string, any>; // 插件输出
pluginDetail?: ChatHistoryItemResType[]; // 插件详情
tfSwitchResult?: boolean; // 判断器结果
}
```
## 实践案例

View File

@@ -15,13 +15,13 @@ weight: 831
1. 主要是修改模型的`functionCall`字段,改成`toolChoice`即可。设置为`true`的模型,会默认走 openai 的 tools 模式;未设置或设置为`false`的,会走提示词生成模式。
问题补全模型与内容提取模型使用同一组配置。
问题优化模型与内容提取模型使用同一组配置。
2. 增加 `"ReRankModels": []`
## V4.6.5 功能介绍
1. 新增 - [问题补全模块](/docs/workflow/modules/coreferenceresolution/)
1. 新增 - [问题优化模块](/docs/workflow/modules/coreferenceresolution/)
2. 新增 - [文本编辑模块](/docs/workflow/modules/text_editor/)
3. 新增 - [判断器模块](/docs/workflow/modules/tfswitch/)
4. 新增 - [自定义反馈模块](/docs/workflow/modules/custom_feedback/)

View File

@@ -11,7 +11,7 @@ weight: 829
发起 1 个 HTTP 请求 ({{rootkey}} 替换成环境变量里的 `rootkey`{{host}} 替换成自己域名)
1. https://xxxxx/api/admin/initv464
1. https://xxxxx/api/admin/initv467
```bash
curl --location --request POST 'https://{{host}}/api/admin/initv467' \

View File

@@ -36,6 +36,7 @@ mongo:
cd 项目目录
# 创建 mongo 密钥
openssl rand -base64 756 > ./mongodb.key
# 600不行可以用chmod 999
chmod 600 ./mongodb.key
chown 999:root ./mongodb.key
# 重启 Mongo

View File

@@ -0,0 +1,30 @@
---
title: 'V4.6.9(进行中)'
description: 'FastGPT V4.6.9更新说明'
icon: 'upgrade'
draft: false
toc: true
weight: 827
---
## 初始化脚本
从任意终端,发起 1 个 HTTP 请求。其中 {{rootkey}} 替换成环境变量里的 `rootkey`{{host}} 替换成自己域名
```bash
curl --location --request POST 'https://{{host}}/api/init/v469' \
--header 'rootkey: {{rootkey}}' \
--header 'Content-Type: application/json'
```
会重置计量表。
## V4.6.9 更新说明
1. 新增 - 完善了HTTP模块的变量提示。
2. 新增 - HTTP模块支持OpenAI单接口导入。
3. 优化 - 问题补全。增加英文类型。同时可以设置为单独模块,方便复用。
4. 优化 - 重写了计量模式
5. 修复 - 标注功能。
6. 修复 - qa生成线程计数错误。

View File

@@ -66,7 +66,7 @@ Body:
Headers:
`Authorization: sk-xxx`
`Authorization: Bearer sk-xxx`
Response:

View File

@@ -135,7 +135,7 @@ export default async function (ctx: FunctionContext) {
},
{
"key": "model",
"type": "selectExtractModel",
"type": "selectLLMModel",
"valueType": "string",
"label": "core.module.input.label.LLM",
"required": true,
@@ -264,7 +264,7 @@ export default async function (ctx: FunctionContext) {
},
{
"key": "model",
"type": "selectChatModel",
"type": "selectLLMModel",
"label": "core.module.input.label.aiModel",
"required": true,
"valueType": "string",
@@ -635,7 +635,7 @@ export default async function (ctx: FunctionContext) {
},
{
"key": "model",
"type": "selectChatModel",
"type": "selectLLMModel",
"label": "core.module.input.label.aiModel",
"required": true,
"valueType": "string",

View File

@@ -139,7 +139,7 @@ HTTP 模块允许你调用任意 GET/POST 类型的 HTTP 接口,从而实现
},
{
"key": "model",
"type": "selectExtractModel",
"type": "selectLLMModel",
"valueType": "string",
"label": "core.module.input.label.LLM",
"required": true,
@@ -401,7 +401,7 @@ HTTP 模块允许你调用任意 GET/POST 类型的 HTTP 接口,从而实现
},
{
"key": "model",
"type": "selectCQModel",
"type": "selectLLMModel",
"valueType": "string",
"label": "core.module.input.label.Classify model",
"required": true,
@@ -614,7 +614,7 @@ HTTP 模块允许你调用任意 GET/POST 类型的 HTTP 接口,从而实现
},
{
"key": "model",
"type": "selectChatModel",
"type": "selectLLMModel",
"label": "core.module.input.label.aiModel",
"required": true,
"valueType": "string",
@@ -835,7 +835,7 @@ HTTP 模块允许你调用任意 GET/POST 类型的 HTTP 接口,从而实现
},
{
"key": "model",
"type": "selectExtractModel",
"type": "selectLLMModel",
"valueType": "string",
"label": "core.module.input.label.LLM",
"required": true,

View File

@@ -1,6 +1,6 @@
---
title: "问题补全(已合并到知识库搜索)"
description: "问题补全模块介绍和使用"
title: "问题优化(已合并到知识库搜索)"
description: "问题优化模块介绍和使用"
icon: "input"
draft: false
toc: true
@@ -23,7 +23,7 @@ weight: 364
![](/imgs/coreferenceResolution2.jpg)
用户在提问“第二点是什么”的时候只会去知识库里查找“第二点是什么”压根查不到内容。实际上需要查询的是“QA结构是什么”。因此我们需要引入一个【问题补全】模块,来对用户当前的问题进行补全,从而使得知识库搜索能够搜索到合适的内容。使用补全后效果如下:
用户在提问“第二点是什么”的时候只会去知识库里查找“第二点是什么”压根查不到内容。实际上需要查询的是“QA结构是什么”。因此我们需要引入一个【问题优化】模块,来对用户当前的问题进行补全,从而使得知识库搜索能够搜索到合适的内容。使用补全后效果如下:
![](/imgs/coreferenceResolution3.jpg)

View File

@@ -3,11 +3,25 @@ import { ErrType } from '../errorCode';
/* team: 500000 */
export enum TeamErrEnum {
teamOverSize = 'teamOverSize',
unAuthTeam = 'unAuthTeam'
unAuthTeam = 'unAuthTeam',
aiPointsNotEnough = 'aiPointsNotEnough',
datasetSizeNotEnough = 'datasetSizeNotEnough',
datasetAmountNotEnough = 'datasetAmountNotEnough',
appAmountNotEnough = 'appAmountNotEnough',
pluginAmountNotEnough = 'pluginAmountNotEnough',
websiteSyncNotEnough = 'websiteSyncNotEnough',
reRankNotEnough = 'reRankNotEnough'
}
const teamErr = [
{ statusText: TeamErrEnum.teamOverSize, message: 'error.team.overSize' },
{ statusText: TeamErrEnum.unAuthTeam, message: '无权操作该团队' }
{ statusText: TeamErrEnum.unAuthTeam, message: '无权操作该团队' },
{ statusText: TeamErrEnum.aiPointsNotEnough, message: 'AI积分已用完~' },
{ statusText: TeamErrEnum.datasetSizeNotEnough, message: '知识库容量不足,请先扩容~' },
{ statusText: TeamErrEnum.datasetAmountNotEnough, message: '知识库数量已达上限~' },
{ statusText: TeamErrEnum.appAmountNotEnough, message: '应用数量已达上限~' },
{ statusText: TeamErrEnum.pluginAmountNotEnough, message: '插件数量已达上限~' },
{ statusText: TeamErrEnum.websiteSyncNotEnough, message: '无权使用Web站点同步~' },
{ statusText: TeamErrEnum.reRankNotEnough, message: '无权使用检索重排~' }
];
export default teamErr.reduce((acc, cur, index) => {
return {

View File

@@ -1,7 +1,7 @@
import { replaceSensitiveLink } from '../string/tools';
import { replaceSensitiveText } from '../string/tools';
export const getErrText = (err: any, def = '') => {
const msg: string = typeof err === 'string' ? err : err?.message || def || '';
msg && console.log('error =>', msg);
return replaceSensitiveLink(msg);
return replaceSensitiveText(msg);
};

View File

@@ -0,0 +1,4 @@
export const formatNumber = (num: number, digit = 1e4) => Math.round(num * digit) / digit;
export const formatNumber2Million = (num: number) => Math.round(num / 1000000);
export const formatNumber2Thousand = (num: number) => Math.round(num / 1000);

View File

@@ -2,3 +2,4 @@ import dayjs from 'dayjs';
export const formatTime2YMDHM = (time?: Date) =>
time ? dayjs(time).format('YYYY-MM-DD HH:mm') : '';
export const formatTime2YMD = (time?: Date) => (time ? dayjs(time).format('YYYY-MM-DD') : '');

View File

@@ -38,10 +38,14 @@ export function replaceVariable(text: string, obj: Record<string, string | numbe
return text || '';
}
/* replace sensitive link */
export const replaceSensitiveLink = (text: string) => {
const urlRegex = /(?<=https?:\/\/)[^\s]+/g;
return text.replace(urlRegex, 'xxx');
/* replace sensitive text */
export const replaceSensitiveText = (text: string) => {
// 1. http link
text = text.replace(/(?<=https?:\/\/)[^\s]+/g, 'xxx');
// 2. nx-xxx 全部替换成xxx
text = text.replace(/ns-[\w-]+/g, 'xxx');
return text;
};
export const getNanoid = (size = 12) => {

View File

@@ -30,6 +30,7 @@ export type FastGPTFeConfigsType = {
show_pay?: boolean;
show_openai_account?: boolean;
show_promotion?: boolean;
show_team_chat?: boolean;
hide_app_flow?: boolean;
concatMd?: string;
docUrl?: string;

View File

@@ -6,8 +6,7 @@ export type LLMModelItemType = {
quoteMaxToken: number;
maxTemperature: number;
inputPrice: number;
outputPrice: number;
charsPointsPrice: number; // 1k chars=n points
censor?: boolean;
vision?: boolean;
@@ -27,8 +26,7 @@ export type VectorModelItemType = {
model: string;
name: string;
defaultToken: number;
inputPrice: number;
outputPrice: number;
charsPointsPrice: number;
maxToken: number;
weight: number;
hidden?: boolean;
@@ -38,8 +36,7 @@ export type VectorModelItemType = {
export type ReRankModelItemType = {
model: string;
name: string;
inputPrice: number;
outputPrice?: number;
charsPointsPrice: number;
requestUrl?: string;
requestAuth?: string;
};
@@ -47,14 +44,12 @@ export type ReRankModelItemType = {
export type AudioSpeechModelType = {
model: string;
name: string;
inputPrice: number;
outputPrice?: number;
charsPointsPrice: number;
voices: { label: string; value: string; bufferId: string }[];
};
export type WhisperModelType = {
model: string;
name: string;
inputPrice: number;
outputPrice?: number;
charsPointsPrice: number; // 60s = n points
};

View File

@@ -2,14 +2,13 @@ import type { LLMModelItemType, VectorModelItemType } from './model.d';
export const defaultQAModels: LLMModelItemType[] = [
{
model: 'gpt-3.5-turbo-16k',
name: 'gpt-3.5-turbo-16k',
model: 'gpt-3.5-turbo',
name: 'gpt-3.5-turbo',
maxContext: 16000,
maxResponse: 16000,
quoteMaxToken: 13000,
maxTemperature: 1.2,
inputPrice: 0,
outputPrice: 0,
charsPointsPrice: 0,
censor: false,
vision: false,
datasetProcess: true,
@@ -26,8 +25,7 @@ export const defaultVectorModels: VectorModelItemType[] = [
{
model: 'text-embedding-ada-002',
name: 'Embedding-2',
inputPrice: 0,
outputPrice: 0,
charsPointsPrice: 0,
defaultToken: 500,
maxToken: 3000,
weight: 100

View File

@@ -17,6 +17,7 @@ export interface AppUpdateParams {
intro?: string;
modules?: AppSchema['modules'];
permission?: AppSchema['permission'];
teamTags?: AppSchema['teamTags'];
}
export type FormatForm2ModulesProps = {

View File

@@ -5,7 +5,7 @@ import type { AIChatModuleProps, DatasetModuleProps } from '../module/node/type.
import { VariableInputEnum } from '../module/constants';
import { SelectedDatasetType } from '../module/api';
import { DatasetSearchModeEnum } from '../dataset/constants';
import { TeamTagsSchema as TeamTagsSchemaType } from '@fastgpt/global/support/user/team/type.d';
export interface AppSchema {
_id: string;
userId: string;
@@ -20,6 +20,7 @@ export interface AppSchema {
modules: ModuleItemType[];
permission: `${PermissionTypeEnum}`;
inited?: boolean;
teamTags: [string];
}
export type AppListItemType = {

View File

@@ -27,7 +27,8 @@ export enum ChatSourceEnum {
test = 'test',
online = 'online',
share = 'share',
api = 'api'
api = 'api',
team = 'team'
}
export const ChatSourceMap = {
[ChatSourceEnum.test]: {
@@ -41,6 +42,9 @@ export const ChatSourceMap = {
},
[ChatSourceEnum.api]: {
name: 'core.chat.logs.api'
},
[ChatSourceEnum.team]: {
name: 'core.chat.logs.team'
}
};

View File

@@ -4,6 +4,7 @@ import { ChatRoleEnum, ChatSourceEnum, ChatStatusEnum } from './constants';
import { FlowNodeTypeEnum } from '../module/node/constant';
import { ModuleOutputKeyEnum } from '../module/constants';
import { AppSchema } from '../app/type';
import type { AppSchema as AppType } from '@fastgpt/global/core/app/type.d';
import { DatasetSearchModeEnum } from '../dataset/constants';
export type ChatSchema = {
@@ -25,6 +26,23 @@ export type ChatSchema = {
metadata?: Record<string, any>;
};
export type teamInfoType = {
avatar: string;
balance: number;
createTime: string;
maxSize: number;
name: string;
ownerId: string;
tagsUrl: string;
_id: string;
};
export type chatAppListSchema = {
apps: AppType[];
teamInfo: teamInfoSchema;
uid?: string;
};
export type ChatWithAppSchema = Omit<ChatSchema, 'appId'> & {
appId: AppSchema;
};
@@ -88,15 +106,15 @@ export type ChatHistoryItemType = HistoryItemType & {
export type moduleDispatchResType = {
// common
moduleLogo?: string;
price?: number;
runningTime?: number;
inputTokens?: number;
outputTokens?: number;
query?: string;
textOutput?: string;
// bill
charsLength?: number;
model?: string;
query?: string;
contextTotalLen?: number;
textOutput?: string;
totalPoints?: number;
// chat
temperature?: number;
@@ -111,6 +129,7 @@ export type moduleDispatchResType = {
searchUsingReRank?: boolean;
extensionModel?: string;
extensionResult?: string;
extensionCharsLength?: number;
// cq
cqList?: ClassifyQuestionAgentItemType[];

View File

@@ -71,30 +71,6 @@ export const DatasetCollectionSyncResultMap = {
};
/* ------------ data -------------- */
export enum DatasetDataIndexTypeEnum {
chunk = 'chunk',
qa = 'qa',
summary = 'summary',
hypothetical = 'hypothetical',
custom = 'custom'
}
export const DatasetDataIndexTypeMap = {
[DatasetDataIndexTypeEnum.chunk]: {
name: 'dataset.data.indexes.chunk'
},
[DatasetDataIndexTypeEnum.summary]: {
name: 'dataset.data.indexes.summary'
},
[DatasetDataIndexTypeEnum.hypothetical]: {
name: 'dataset.data.indexes.hypothetical'
},
[DatasetDataIndexTypeEnum.qa]: {
name: 'dataset.data.indexes.qa'
},
[DatasetDataIndexTypeEnum.custom]: {
name: 'dataset.data.indexes.custom'
}
};
/* ------------ training -------------- */
export enum TrainingModeEnum {

View File

@@ -3,7 +3,6 @@ import { PermissionTypeEnum } from '../../support/permission/constant';
import { PushDatasetDataChunkProps } from './api';
import {
DatasetCollectionTypeEnum,
DatasetDataIndexTypeEnum,
DatasetStatusEnum,
DatasetTypeEnum,
SearchScoreTypeEnum,
@@ -64,7 +63,6 @@ export type DatasetCollectionSchemaType = {
export type DatasetDataIndexItemType = {
defaultIndex: boolean;
dataId: string; // pg data id
type: `${DatasetDataIndexTypeEnum}`;
text: string;
};
export type DatasetDataSchemaType = {
@@ -142,6 +140,7 @@ export type DatasetCollectionItemType = CollectionWithDatasetType & {
/* ================= data ===================== */
export type DatasetDataItemType = {
id: string;
teamId: string;
datasetId: string;
collectionId: string;
sourceName: string;
@@ -173,7 +172,7 @@ export type DatasetFileSchema = {
/* ============= search =============== */
export type SearchDataResponseItemType = Omit<
DatasetDataItemType,
'indexes' | 'isOwner' | 'canWrite'
'teamId' | 'indexes' | 'isOwner' | 'canWrite'
> & {
score: { type: `${SearchScoreTypeEnum}`; value: number; index: number }[];
// score: number;

View File

@@ -1,4 +1,4 @@
import { TrainingModeEnum, DatasetCollectionTypeEnum, DatasetDataIndexTypeEnum } from './constants';
import { TrainingModeEnum, DatasetCollectionTypeEnum } from './constants';
import { getFileIcon } from '../../common/file/icon';
import { strIsLink } from '../../common/string/tools';
@@ -41,7 +41,6 @@ export function getDefaultIndex(props?: { q?: string; a?: string; dataId?: strin
const qaStr = `${q}\n${a}`.trim();
return {
defaultIndex: true,
type: a ? DatasetDataIndexTypeEnum.qa : DatasetDataIndexTypeEnum.chunk,
text: a ? qaStr : q,
dataId
};

View File

@@ -89,9 +89,10 @@ export enum ModuleInputKeyEnum {
export enum ModuleOutputKeyEnum {
// common
responseData = 'responseData',
moduleDispatchBills = 'moduleDispatchBills',
userChatInput = 'userChatInput',
finish = 'finish',
responseData = 'responseData',
history = 'history',
answerText = 'answerText', // answer module text key
success = 'success',

View File

@@ -20,9 +20,7 @@ export enum FlowNodeInputTypeEnum {
aiSettings = 'aiSettings',
// ai model select
selectChatModel = 'selectChatModel',
selectCQModel = 'selectCQModel',
selectExtractModel = 'selectExtractModel',
selectLLMModel = 'selectLLMModel',
// dataset special input
selectDataset = 'selectDataset',
@@ -58,7 +56,7 @@ export enum FlowNodeTypeEnum {
pluginModule = 'pluginModule',
pluginInput = 'pluginInput',
pluginOutput = 'pluginOutput',
cfr = 'cfr'
queryExtension = 'cfr'
// abandon
}

View File

@@ -31,7 +31,7 @@ export const AiChatModule: FlowModuleTemplateType = {
Input_Template_Switch,
{
key: ModuleInputKeyEnum.aiModel,
type: FlowNodeInputTypeEnum.selectChatModel,
type: FlowNodeInputTypeEnum.selectLLMModel,
label: 'core.module.input.label.aiModel',
required: true,
valueType: ModuleIOValueTypeEnum.string,

View File

@@ -24,7 +24,7 @@ export const ClassifyQuestionModule: FlowModuleTemplateType = {
Input_Template_Switch,
{
key: ModuleInputKeyEnum.aiModel,
type: FlowNodeInputTypeEnum.selectCQModel,
type: FlowNodeInputTypeEnum.selectLLMModel,
valueType: ModuleIOValueTypeEnum.string,
label: 'core.module.input.label.Classify model',
required: true,

View File

@@ -24,7 +24,7 @@ export const ContextExtractModule: FlowModuleTemplateType = {
Input_Template_Switch,
{
key: ModuleInputKeyEnum.aiModel,
type: FlowNodeInputTypeEnum.selectExtractModel,
type: FlowNodeInputTypeEnum.selectLLMModel,
valueType: ModuleIOValueTypeEnum.string,
label: 'core.module.input.label.LLM',
required: true,

View File

@@ -85,7 +85,6 @@ export const HttpModule468: FlowModuleTemplateType = {
...Input_Template_AddInputParam,
editField: {
key: true,
name: true,
description: true,
required: true,
dataType: true
@@ -106,7 +105,6 @@ export const HttpModule468: FlowModuleTemplateType = {
...Output_Template_AddOutput,
editField: {
key: true,
name: true,
description: true,
dataType: true
},

View File

@@ -3,7 +3,7 @@ import {
FlowNodeOutputTypeEnum,
FlowNodeTypeEnum
} from '../../node/constant';
import { FlowModuleTemplateType } from '../../type.d';
import { FlowModuleTemplateType } from '../../type';
import {
ModuleIOValueTypeEnum,
ModuleInputKeyEnum,
@@ -17,19 +17,19 @@ import {
} from '../input';
import { Output_Template_UserChatInput } from '../output';
export const AiCFR: FlowModuleTemplateType = {
export const AiQueryExtension: FlowModuleTemplateType = {
id: FlowNodeTypeEnum.chatNode,
templateType: ModuleTemplateTypeEnum.other,
flowType: FlowNodeTypeEnum.cfr,
flowType: FlowNodeTypeEnum.queryExtension,
avatar: '/imgs/module/cfr.svg',
name: 'core.module.template.Query extension',
intro: '该模块已合并到知识库搜索参数中无需单独使用。模块将于2024/3/31弃用请尽快修改。',
intro: 'core.module.template.Query extension intro',
showStatus: true,
inputs: [
Input_Template_Switch,
{
key: ModuleInputKeyEnum.aiModel,
type: FlowNodeInputTypeEnum.selectExtractModel,
type: FlowNodeInputTypeEnum.selectLLMModel,
label: 'core.module.input.label.aiModel',
required: true,
valueType: ModuleIOValueTypeEnum.string,
@@ -39,7 +39,7 @@ export const AiCFR: FlowModuleTemplateType = {
{
key: ModuleInputKeyEnum.aiSystemPrompt,
type: FlowNodeInputTypeEnum.textarea,
label: 'core.module.input.label.Background',
label: 'core.app.edit.Query extension background prompt',
max: 300,
valueType: ModuleIOValueTypeEnum.string,
description: 'core.app.edit.Query extension background tip',
@@ -54,7 +54,8 @@ export const AiCFR: FlowModuleTemplateType = {
Output_Template_UserChatInput,
{
key: ModuleOutputKeyEnum.text,
label: 'core.module.output.label.cfr result',
label: 'core.module.output.label.query extension result',
description: 'core.module.output.description.query extension result',
valueType: ModuleIOValueTypeEnum.string,
type: FlowNodeOutputTypeEnum.source,
targets: []

View File

@@ -1,6 +1,14 @@
import { FlowNodeTypeEnum } from './node/constant';
import { ModuleIOValueTypeEnum, ModuleTemplateTypeEnum, VariableInputEnum } from './constants';
import {
ModuleIOValueTypeEnum,
ModuleOutputKeyEnum,
ModuleTemplateTypeEnum,
VariableInputEnum
} from './constants';
import { FlowNodeInputItemType, FlowNodeOutputItemType } from './node/type';
import { UserModelSchema } from 'support/user/type';
import { moduleDispatchResType } from '..//chat/type';
import { ChatModuleBillType } from '../../support/wallet/bill/type';
export type FlowModuleTemplateType = {
id: string; // module id, unique
@@ -105,7 +113,7 @@ export type ChatDispatchProps = {
mode: 'test' | 'chat';
teamId: string;
tmbId: string;
user: UserType;
user: UserModelSchema;
appId: string;
chatId?: string;
responseChatItemId?: string;
@@ -116,7 +124,10 @@ export type ChatDispatchProps = {
};
export type ModuleDispatchProps<T> = ChatDispatchProps & {
outputs: RunningModuleItemType['outputs'];
inputs: RunningModuleItemType['inputs'];
module: RunningModuleItemType;
params: T;
};
export type ModuleDispatchResponse<T> = T & {
[ModuleOutputKeyEnum.responseData]?: moduleDispatchResType;
[ModuleOutputKeyEnum.moduleDispatchBills]?: ChatModuleBillType[];
};

View File

@@ -1,6 +1,5 @@
export type OpenApiSchema = {
_id: string;
userId: string;
teamId: string;
tmbId: string;
createTime: Date;
@@ -8,9 +7,9 @@ export type OpenApiSchema = {
apiKey: string;
appId?: string;
name: string;
usage: number;
usagePoints: number;
limit?: {
expiredTime?: Date;
credit?: number;
maxUsagePoints: number;
};
};

View File

@@ -1,5 +1,5 @@
import type { HistoryItemType, ChatSiteItemType } from '../../core/chat/type.d';
import { OutLinkSchema } from '@fastgpt/global/support/outLink/type';
import { OutLinkSchema } from './type.d';
export type AuthOutLinkInitProps = {
outLinkUid: string;

View File

@@ -7,14 +7,14 @@ export type OutLinkSchema = {
tmbId: string;
appId: string;
name: string;
total: number;
usagePoints: number;
lastTime: Date;
type: `${OutLinkTypeEnum}`;
responseDetail: boolean;
limit?: {
expiredTime?: Date;
QPM: number;
credit: number;
maxUsagePoints: number;
hookUrl?: string;
};
};

View File

@@ -1,7 +1,6 @@
import { AuthUserTypeEnum } from './constant';
export type AuthResponseType = {
userId: string;
teamId: string;
tmbId: string;
isOwner: boolean;

View File

@@ -1,5 +1,6 @@
export const TeamCollectionName = 'teams';
export const TeamMemberCollectionName = 'team.members';
export const TeamTagsCollectionName = 'team.tags';
export enum TeamMemberRoleEnum {
owner = 'owner',

View File

@@ -15,6 +15,7 @@ export type UpdateTeamProps = {
teamId: string;
name?: string;
avatar?: string;
tagsUrl?: string;
};
/* ------------- member ----------- */

View File

@@ -9,11 +9,23 @@ export type TeamSchema = {
createTime: Date;
balance: number;
maxSize: number;
tagsUrl: string;
limit: {
lastExportDatasetTime: Date;
lastWebsiteSyncTime: Date;
};
};
export type tagsType = {
label: string,
key: string
}
export type TeamTagsSchema = {
_id: string;
label: string;
teamId: string;
key: string;
createTime: Date;
};
export type TeamMemberSchema = {
_id: string;
@@ -26,13 +38,13 @@ export type TeamMemberSchema = {
defaultTeam: boolean;
};
export type TeamMemberWithUserSchema = TeamMemberSchema & {
export type TeamMemberWithUserSchema = Omit<TeamMemberSchema, 'userId'> & {
userId: UserModelSchema;
};
export type TeamMemberWithTeamSchema = TeamMemberSchema & {
export type TeamMemberWithTeamSchema = Omit<TeamMemberSchema, 'teamId'> & {
teamId: TeamSchema;
};
export type TeamMemberWithTeamAndUserSchema = TeamMemberWithTeamSchema & {
export type TeamMemberWithTeamAndUserSchema = Omit<TeamMemberWithTeamSchema, 'userId'> & {
userId: UserModelSchema;
};

View File

@@ -29,4 +29,5 @@ export type UserType = {
promotionRate: UserModelSchema['promotionRate'];
openaiAccount: UserModelSchema['openaiAccount'];
team: TeamItemType;
standardInfo?: standardInfoType;
};

View File

@@ -1,25 +1,18 @@
import { BillSourceEnum } from './constants';
import { BillListItemCountType, BillListItemType } from './type';
export type CreateTrainingBillProps = {
name: string;
datasetId: string;
};
export type ConcatBillProps = BillListItemCountType & {
teamId: string;
tmbId: string;
billId?: string;
total: number;
listIndex?: number;
};
import { BillTypeEnum } from './constants';
export type CreateBillProps = {
teamId: string;
tmbId: string;
appName: string;
appId?: string;
total: number;
source: `${BillSourceEnum}`;
list: BillListItemType[];
type: `${BillTypeEnum}`;
// balance
balance?: number; // read
month?: number;
// extra dataset size
extraDatasetSize?: number; // 1k
extraPoints?: number; // 100w
};
export type CreateBillResponse = {
billId: string;
codeUrl: string;
readPrice: number;
};

View File

@@ -1,34 +1,57 @@
// model price: xxx/1k tokens
// ¥1 = 100000.
export const PRICE_SCALE = 100000;
export enum BillSourceEnum {
fastgpt = 'fastgpt',
api = 'api',
shareLink = 'shareLink',
training = 'training',
export enum BillTypeEnum {
balance = 'balance',
standSubPlan = 'standSubPlan',
extraDatasetSub = 'extraDatasetSub'
extraDatasetSub = 'extraDatasetSub',
extraPoints = 'extraPoints'
}
export const BillSourceMap = {
[BillSourceEnum.fastgpt]: {
label: '在线使用'
export const billTypeMap = {
[BillTypeEnum.balance]: {
label: 'support.wallet.subscription.type.balance'
},
[BillSourceEnum.api]: {
label: 'Api'
},
[BillSourceEnum.shareLink]: {
label: '免登录链接'
},
[BillSourceEnum.training]: {
label: 'dataset.Training Name'
},
[BillSourceEnum.standSubPlan]: {
[BillTypeEnum.standSubPlan]: {
label: 'support.wallet.subscription.type.standard'
},
[BillSourceEnum.extraDatasetSub]: {
[BillTypeEnum.extraDatasetSub]: {
label: 'support.wallet.subscription.type.extraDatasetSize'
},
[BillTypeEnum.extraPoints]: {
label: 'support.wallet.subscription.type.extraPoints'
}
};
export enum BillStatusEnum {
SUCCESS = 'SUCCESS',
REFUND = 'REFUND',
NOTPAY = 'NOTPAY',
CLOSED = 'CLOSED'
}
export const billStatusMap = {
[BillStatusEnum.SUCCESS]: {
label: 'support.wallet.bill.status.success'
},
[BillStatusEnum.REFUND]: {
label: 'support.wallet.bill.status.refund'
},
[BillStatusEnum.NOTPAY]: {
label: 'support.wallet.bill.status.notpay'
},
[BillStatusEnum.CLOSED]: {
label: 'support.wallet.bill.status.closed'
}
};
export enum BillPayWayEnum {
balance = 'balance',
wx = 'wx'
}
export const billPayWayMap = {
[BillPayWayEnum.balance]: {
label: 'support.wallet.bill.payWay.balance'
},
[BillPayWayEnum.wx]: {
label: 'support.wallet.bill.payWay.wx'
}
};
export const SUB_DATASET_SIZE_RATE = 1000;
export const SUB_EXTRA_POINT_RATE = 1000;

View File

@@ -1,26 +0,0 @@
/* bill common */
import { PRICE_SCALE } from './constants';
import { BillSourceEnum } from './constants';
import { AuthUserTypeEnum } from '../../permission/constant';
/**
* dataset price / PRICE_SCALE = real price
*/
export const formatStorePrice2Read = (val = 0, multiple = 1) => {
return Number(((val / PRICE_SCALE) * multiple).toFixed(10));
};
export const formatModelPrice2Read = (val = 0) => {
return Number((val / 1000).toFixed(10));
};
export const getBillSourceByAuthType = ({
shareId,
authType
}: {
shareId?: string;
authType?: `${AuthUserTypeEnum}`;
}) => {
if (shareId) return BillSourceEnum.shareLink;
if (authType === AuthUserTypeEnum.apikey) return BillSourceEnum.api;
return BillSourceEnum.fastgpt;
};

View File

@@ -1,35 +1,29 @@
import { CreateBillProps } from './api';
import { BillSourceEnum } from './constants';
import { StandardSubLevelEnum, SubModeEnum, SubTypeEnum } from '../sub/constants';
import { BillPayWayEnum, BillTypeEnum } from './constants';
export type BillListItemCountType = {
inputTokens?: number;
outputTokens?: number;
charsLength?: number;
duration?: number;
// sub
datasetSize?: number;
// abandon
tokenLen?: number;
};
export type BillListItemType = BillListItemCountType & {
moduleName: string;
amount: number;
model?: string;
};
export type BillSchema = CreateBillProps & {
export type BillSchemaType = {
_id: string;
time: Date;
userId: string;
teamId: string;
tmbId: string;
createTime: Date;
orderId: string;
status: 'SUCCESS' | 'REFUND' | 'NOTPAY' | 'CLOSED';
type: `${BillTypeEnum}`;
price: number;
metadata: {
payWay: `${BillPayWayEnum}`;
subMode?: `${SubModeEnum}`;
standSubLevel?: `${StandardSubLevelEnum}`;
month?: number;
datasetSize?: number;
extraPoints?: number;
};
};
export type BillItemType = {
id: string;
// memberName: string;
time: Date;
appName: string;
source: BillSchema['source'];
total: number;
list: BillSchema['list'];
export type ChatModuleBillType = {
totalPoints: number;
moduleName: string;
model?: string;
charsLength?: number;
};

View File

@@ -0,0 +1,3 @@
// model price: xxx/1k tokens
// ¥1 = 100000.
export const PRICE_SCALE = 100000;

View File

@@ -1,41 +0,0 @@
export enum PayTypeEnum {
balance = 'balance',
subStandard = 'subStandard',
subExtraDatasetSize = 'subExtraDatasetSize',
subExtraPoints = 'subExtraPoints'
}
export const payTypeMap = {
[PayTypeEnum.balance]: {
label: 'support.user.team.pay.type.balance'
},
[PayTypeEnum.subStandard]: {
label: 'support.wallet.subscription.type.standard'
},
[PayTypeEnum.subExtraDatasetSize]: {
label: 'support.wallet.subscription.type.extraDatasetSize'
},
[PayTypeEnum.subExtraPoints]: {
label: 'support.wallet.subscription.type.extraPoints'
}
};
export enum PayStatusEnum {
SUCCESS = 'SUCCESS',
REFUND = 'REFUND',
NOTPAY = 'NOTPAY',
CLOSED = 'CLOSED'
}
export const payStatusMap = {
[PayStatusEnum.SUCCESS]: {
label: 'support.user.team.pay.status.success'
},
[PayStatusEnum.REFUND]: {
label: 'support.user.team.pay.status.refund'
},
[PayStatusEnum.NOTPAY]: {
label: 'support.user.team.pay.status.notpay'
},
[PayStatusEnum.CLOSED]: {
label: 'support.user.team.pay.status.closed'
}
};

View File

@@ -1,18 +0,0 @@
import { SubModeEnum, SubTypeEnum } from '../sub/constants';
import { PayTypeEnum } from './constants';
export type PaySchema = {
_id: string;
userId: string;
teamId: string;
tmbId: string;
createTime: Date;
orderId: string;
status: 'SUCCESS' | 'REFUND' | 'NOTPAY' | 'CLOSED';
type: `${PayType}`;
price: number;
payWay: 'balance' | 'wx';
subMetadata: {};
};

View File

@@ -1,26 +1,14 @@
import { StandardSubLevelEnum, SubModeEnum } from './constants';
import { TeamSubSchema } from './type.d';
export type SubDatasetSizeParams = {
size: number;
};
export type StandardSubPlanParams = {
level: `${StandardSubLevelEnum}`;
mode: `${SubModeEnum}`;
};
export type SubDatasetSizePreviewCheckResponse = {
payForNewSub: boolean; // Does this change require payment
newSubSize: number; // new sub dataset size
alreadySubSize: number; // old sub dataset size
payPrice: number; // this change require payment
newPlanPrice: number; // the new sub price
newSubStartTime: Date;
newSubExpiredTime: Date;
balanceEnough: boolean; // team balance is enough
};
export type StandardSubPlanUpdateResponse = {
balanceEnough: boolean; // team balance is enough
teamBalance: number;
payPrice?: number;
planPrice: number;
planPointPrice: number;

View File

@@ -1,38 +1,36 @@
export const POINTS_SCALE = 10000;
export enum SubTypeEnum {
standard = 'standard',
extraDatasetSize = 'extraDatasetSize',
extraPoints = 'extraPoints'
}
export const subTypeMap = {
[SubTypeEnum.standard]: {
label: 'support.wallet.subscription.type.standard'
label: 'support.wallet.subscription.type.standard',
icon: 'support/account/plans'
},
[SubTypeEnum.extraDatasetSize]: {
label: 'support.wallet.subscription.type.extraDatasetSize'
label: 'support.wallet.subscription.type.extraDatasetSize',
icon: 'core/dataset/datasetLight'
},
[SubTypeEnum.extraPoints]: {
label: 'support.wallet.subscription.type.extraPoints'
label: 'support.wallet.subscription.type.extraPoints',
icon: 'core/chat/chatLight'
}
};
export enum SubStatusEnum {
active = 'active',
canceled = 'canceled'
expired = 'expired'
}
export const subStatusMap = {
[SubStatusEnum.active]: {
label: 'support.wallet.subscription.status.active'
},
[SubStatusEnum.canceled]: {
[SubStatusEnum.expired]: {
label: 'support.wallet.subscription.status.canceled'
}
};
export const subSelectMap = {
true: SubStatusEnum.active,
false: SubStatusEnum.canceled
};
export enum SubModeEnum {
month = 'month',
@@ -40,11 +38,11 @@ export enum SubModeEnum {
}
export const subModeMap = {
[SubModeEnum.month]: {
label: 'support.wallet.subscription.mode.month',
label: 'support.wallet.subscription.mode.Month',
durationMonth: 1
},
[SubModeEnum.year]: {
label: 'support.wallet.subscription.mode.year',
label: 'support.wallet.subscription.mode.Year',
durationMonth: 12
}
};
@@ -63,7 +61,7 @@ export const standardSubLevelMap = {
},
[StandardSubLevelEnum.experience]: {
label: 'support.wallet.subscription.standardSubLevel.experience',
desc: 'support.wallet.subscription.standardSubLevel.experience desc'
desc: ''
},
[StandardSubLevelEnum.team]: {
label: 'support.wallet.subscription.standardSubLevel.team',

View File

@@ -2,19 +2,19 @@ import { StandardSubLevelEnum, SubModeEnum, SubStatusEnum, SubTypeEnum } from '.
// Content of plan
export type TeamStandardSubPlanItemType = {
price: number; // read price
pointPrice: number; // read price/ one ten thousand
price: number; // read price / month
pointPrice: number; // read price/ one thousand
totalPoints: number; // n
maxTeamMember: number;
maxAppAmount: number; // max app or plugin amount
maxDatasetAmount: number;
chatHistoryStoreDuration: number; // n day
maxDatasetSize: number;
customApiKey: boolean;
customCopyright: boolean; // feature
websiteSyncInterval: number; // n hours
trainingWeight: number; // 1~4
reRankWeight: number; // 1~4
totalPoints: number; // n ten thousand
permissionCustomApiKey: boolean;
permissionCustomCopyright: boolean; // feature
permissionWebsiteSync: boolean;
permissionReRank: boolean;
};
export type StandSubPlanLevelMapType = Record<
@@ -27,6 +27,9 @@ export type SubPlanType = {
[SubTypeEnum.extraDatasetSize]: {
price: number;
};
[SubTypeEnum.extraPoints]: {
price: number;
};
};
export type TeamSubSchema = {
@@ -34,40 +37,30 @@ export type TeamSubSchema = {
teamId: string;
type: `${SubTypeEnum}`;
status: `${SubStatusEnum}`;
currentMode: `${SubModeEnum}`;
nextMode: `${SubModeEnum}`;
startTime: Date;
expiredTime: Date;
price: number;
currentMode: `${SubModeEnum}`;
nextMode: `${SubModeEnum}`;
currentSubLevel: `${StandardSubLevelEnum}`;
nextSubLevel: `${StandardSubLevelEnum}`;
pointPrice: number;
totalPoints: number;
currentExtraDatasetSize: number;
nextExtraDatasetSize: number;
currentExtraPoints: number;
nextExtraPoints: number;
surplusPoints: number;
// abandon
datasetStoreAmount?: number;
renew?: boolean;
currentExtraDatasetSize: number;
};
export type FeTeamSubType = {
export type FeTeamPlanStatusType = {
[SubTypeEnum.standard]?: TeamSubSchema;
[SubTypeEnum.extraDatasetSize]?: TeamSubSchema;
[SubTypeEnum.extraPoints]?: TeamSubSchema;
standardConstants?: TeamStandardSubPlanItemType;
standardMaxDatasetSize: number;
totalPoints: number;
usedPoints: number;
standardMaxPoints: number;
// standard + extra
datasetMaxSize: number;
usedDatasetSize: number;
};

View File

@@ -0,0 +1,26 @@
import { UsageSourceEnum } from './constants';
import { UsageListItemCountType, UsageListItemType } from './type';
export type CreateTrainingUsageProps = {
name: string;
datasetId: string;
};
export type ConcatUsageProps = UsageListItemCountType & {
teamId: string;
tmbId: string;
billId?: string;
totalPoints: number;
listIndex?: number;
};
export type CreateUsageProps = {
teamId: string;
tmbId: string;
appName: string;
appId?: string;
totalPoints: number;
// inputTokens: number;
source: `${UsageSourceEnum}`;
list: UsageListItemType[];
};

View File

@@ -0,0 +1,21 @@
export enum UsageSourceEnum {
fastgpt = 'fastgpt',
api = 'api',
shareLink = 'shareLink',
training = 'training'
}
export const UsageSourceMap = {
[UsageSourceEnum.fastgpt]: {
label: '在线使用'
},
[UsageSourceEnum.api]: {
label: 'Api'
},
[UsageSourceEnum.shareLink]: {
label: '免登录链接'
},
[UsageSourceEnum.training]: {
label: 'dataset.Training Name'
}
};

View File

@@ -0,0 +1,23 @@
/* bill common */
import { PRICE_SCALE } from '../constants';
import { UsageSourceEnum } from './constants';
import { AuthUserTypeEnum } from '../../permission/constant';
/**
* dataset price / PRICE_SCALE = real price
*/
export const formatStorePrice2Read = (val = 0, multiple = 1) => {
return Number(((val / PRICE_SCALE) * multiple).toFixed(10));
};
export const getUsageSourceByAuthType = ({
shareId,
authType
}: {
shareId?: string;
authType?: `${AuthUserTypeEnum}`;
}) => {
if (shareId) return UsageSourceEnum.shareLink;
if (authType === AuthUserTypeEnum.apikey) return UsageSourceEnum.api;
return UsageSourceEnum.fastgpt;
};

View File

@@ -0,0 +1,26 @@
import { CreateUsageProps } from './api';
import { UsageSourceEnum } from './constants';
export type UsageListItemCountType = {
charsLength?: number;
duration?: number;
};
export type UsageListItemType = UsageListItemCountType & {
moduleName: string;
amount: number;
model?: string;
};
export type UsageSchemaType = CreateUsageProps & {
_id: string;
time: Date;
};
export type UsageItemType = {
id: string;
time: Date;
appName: string;
source: UsageSchemaType['source'];
totalPoints: number;
list: UsageSchemaType['list'];
};

View File

@@ -3,7 +3,7 @@ import { sseResponseEventEnum } from './constant';
import { proxyError, ERROR_RESPONSE, ERROR_ENUM } from '@fastgpt/global/common/error/errorCode';
import { addLog } from '../system/log';
import { clearCookie } from '../../support/permission/controller';
import { replaceSensitiveLink } from '@fastgpt/global/common/string/tools';
import { replaceSensitiveText } from '@fastgpt/global/common/string/tools';
export interface ResponseType<T = any> {
code: number;
@@ -53,7 +53,7 @@ export const jsonRes = <T = any>(
res.status(code).json({
code,
statusText: '',
message: replaceSensitiveLink(message || msg),
message: replaceSensitiveText(message || msg),
data: data !== undefined ? data : null
});
};
@@ -91,7 +91,7 @@ export const sseErrRes = (res: NextApiResponse, error: any) => {
responseWrite({
res,
event: sseResponseEventEnum.error,
data: JSON.stringify({ message: replaceSensitiveLink(msg) })
data: JSON.stringify({ message: replaceSensitiveText(msg) })
});
};

View File

@@ -1,3 +1,4 @@
import { FastGPTConfigFileType } from '@fastgpt/global/common/system/types';
import { isIPv6 } from 'net';
export const SERVICE_LOCAL_PORT = `${process.env.PORT || 3000}`;
@@ -5,3 +6,16 @@ export const SERVICE_LOCAL_HOST =
process.env.HOSTNAME && isIPv6(process.env.HOSTNAME)
? `[${process.env.HOSTNAME}]:${SERVICE_LOCAL_PORT}`
: `${process.env.HOSTNAME || 'localhost'}:${SERVICE_LOCAL_PORT}`;
export const initFastGPTConfig = (config?: FastGPTConfigFileType) => {
if (!config) return;
global.feConfigs = config.feConfigs;
global.subPlans = config.subPlans;
global.llmModels = config.llmModels;
global.vectorModels = config.vectorModels;
global.audioSpeechModels = config.audioSpeechModels;
global.whisperModel = config.whisperModel;
global.reRankModels = config.reRankModels;
};

View File

@@ -11,7 +11,6 @@ const getVectorObj = () => {
export const initVectorStore = getVectorObj().init;
export const deleteDatasetDataVector = getVectorObj().delete;
export const recallFromVectorStore = getVectorObj().recall;
export const checkVectorDataExist = getVectorObj().checkDataExist;
export const getVectorDataByTime = getVectorObj().getVectorDataByTime;
export const getVectorCountByTeamId = getVectorObj().getVectorCountByTeamId;
@@ -38,22 +37,22 @@ export const insertDatasetDataVector = async ({
};
};
export const updateDatasetDataVector = async ({
id,
...props
}: InsertVectorProps & {
id: string;
query: string;
model: VectorModelItemType;
}) => {
// insert new vector
const { charsLength, insertId } = await insertDatasetDataVector(props);
// export const updateDatasetDataVector = async ({
// id,
// ...props
// }: InsertVectorProps & {
// id: string;
// query: string;
// model: VectorModelItemType;
// }) => {
// // insert new vector
// const { charsLength, insertId } = await insertDatasetDataVector(props);
// delete old vector
await deleteDatasetDataVector({
teamId: props.teamId,
id
});
// // delete old vector
// await deleteDatasetDataVector({
// teamId: props.teamId,
// id
// });
return { charsLength, insertId };
};
// return { charsLength, insertId };
// };

View File

@@ -4,8 +4,7 @@ import {
deleteDatasetDataVector,
embeddingRecall,
getVectorDataByTime,
getVectorCountByTeamId,
checkDataExist
getVectorCountByTeamId
} from './controller';
export class PgVector {
@@ -14,7 +13,6 @@ export class PgVector {
insert = insertDatasetDataVector;
delete = deleteDatasetDataVector;
recall = embeddingRecall;
checkDataExist = checkDataExist;
getVectorCountByTeamId = getVectorCountByTeamId;
getVectorDataByTime = getVectorDataByTime;
}

View File

@@ -25,6 +25,18 @@ export async function initPg() {
await PgClient.query(
`CREATE INDEX CONCURRENTLY IF NOT EXISTS vector_index ON ${PgDatasetTableName} USING hnsw (vector vector_ip_ops) WITH (m = 32, ef_construction = 64);`
);
await PgClient.query(
`CREATE INDEX CONCURRENTLY IF NOT EXISTS team_dataset_index ON ${PgDatasetTableName} USING btree(team_id, dataset_id);`
);
await PgClient.query(
` CREATE INDEX CONCURRENTLY IF NOT EXISTS team_collection_index ON ${PgDatasetTableName} USING btree(team_id, collection_id);`
);
await PgClient.query(
`CREATE INDEX CONCURRENTLY IF NOT EXISTS team_id_index ON ${PgDatasetTableName} USING btree(team_id, id);`
);
await PgClient.query(
`CREATE INDEX CONCURRENTLY IF NOT EXISTS create_time_index ON ${PgDatasetTableName} USING btree(createtime);`
);
console.log('init pg successful');
} catch (error) {
@@ -152,11 +164,6 @@ export const embeddingRecall = async (
}
};
export const checkDataExist = async (id: string) => {
const { rows } = await PgClient.query(`SELECT id FROM ${PgDatasetTableName} WHERE id=${id};`);
return rows.length > 0;
};
export const getVectorCountByTeamId = async (teamId: string) => {
const total = await PgClient.count(PgDatasetTableName, {
where: [['team_id', String(teamId)]]

View File

@@ -11,6 +11,7 @@ export const getAIApi = (props?: {
timeout?: number;
}) => {
const { userKey, timeout } = props || {};
return new OpenAI({
apiKey: userKey?.key || systemAIChatKey,
baseURL: userKey?.baseUrl || baseUrl,

View File

@@ -1,5 +1,6 @@
import { VectorModelItemType } from '@fastgpt/global/core/ai/model.d';
import { getAIApi } from '../config';
import { replaceValidChars } from '../../chat/utils';
type GetVectorProps = {
model: VectorModelItemType;
@@ -36,7 +37,7 @@ export async function getVectorsByText({ model, input }: GetVectorProps) {
}
return {
charsLength: input.length,
charsLength: replaceValidChars(input).length,
vectors: await Promise.all(res.data.map((item) => unityDimensional(item.embedding)))
};
});

View File

@@ -1,159 +0,0 @@
import { replaceVariable } from '@fastgpt/global/common/string/tools';
import { getAIApi } from '../config';
import { ChatItemType } from '@fastgpt/global/core/chat/type';
/*
cfr: coreference resolution - 指代消除
可以根据上下文,完事当前问题指代内容,利于检索。
*/
const defaultPrompt = `请不要回答任何问题。
你的任务是结合历史记录,为当前问题,实现代词替换,确保问题描述的对象清晰明确。例如:
历史记录:
"""
Q: 对话背景。
A: 关于 FatGPT 的介绍和使用等问题。
"""
当前问题: 怎么下载
输出: FastGPT 怎么下载?
----------------
历史记录:
"""
Q: 报错 "no connection"
A: FastGPT 报错"no connection"可能是因为……
"""
当前问题: 怎么解决
输出: FastGPT 报错"no connection"如何解决?
----------------
历史记录:
"""
Q: 作者是谁?
A: FastGPT 的作者是 labring。
"""
当前问题: 介绍下他
输出: 介绍下 FastGPT 的作者 labring。
----------------
历史记录:
"""
Q: 作者是谁?
A: FastGPT 的作者是 labring。
"""
当前问题: 我想购买商业版。
输出: FastGPT 商业版如何购买?
----------------
历史记录:
"""
Q: 对话背景。
A: 关于 FatGPT 的介绍和使用等问题。
"""
当前问题: nh
输出: nh
----------------
历史记录:
"""
Q: FastGPT 如何收费?
A: FastGPT 收费可以参考……
"""
当前问题: 你知道 laf 么?
输出: 你知道 laf 么?
----------------
历史记录:
"""
Q: FastGPT 的优势
A: 1. 开源
2. 简便
3. 扩展性强
"""
当前问题: 介绍下第2点。
输出: 介绍下 FastGPT 简便的优势。
----------------
历史记录:
"""
Q: 什么是 FastGPT
A: FastGPT 是一个 RAG 平台。
Q: 什么是 Sealos
A: Sealos 是一个云操作系统。
"""
当前问题: 它们有什么关系?
输出: FastGPT 和 Sealos 有什么关系?
----------------
历史记录:
"""
{{histories}}
"""
当前问题: {{query}}
输出: `;
export const queryCfr = async ({
chatBg,
query,
histories = [],
model
}: {
chatBg?: string;
query: string;
histories: ChatItemType[];
model: string;
}) => {
if (histories.length === 0 && !chatBg) {
return {
rawQuery: query,
cfrQuery: query,
model,
inputTokens: 0,
outputTokens: 0
};
}
const systemFewShot = chatBg
? `Q: 对话背景。
A: ${chatBg}
`
: '';
const historyFewShot = histories
.map((item) => {
const role = item.obj === 'Human' ? 'Q' : 'A';
return `${role}: ${item.value}`;
})
.join('\n');
const concatFewShot = `${systemFewShot}${historyFewShot}`.trim();
const ai = getAIApi({
timeout: 480000
});
const result = await ai.chat.completions.create({
model: model,
temperature: 0.01,
max_tokens: 150,
messages: [
{
role: 'user',
content: replaceVariable(defaultPrompt, {
query: `${query}`,
histories: concatFewShot
})
}
],
stream: false
});
const answer = result.choices?.[0]?.message?.content || '';
if (!answer) {
return {
rawQuery: query,
cfrQuery: query,
model,
inputTokens: 0,
outputTokens: 0
};
}
return {
rawQuery: query,
cfrQuery: answer,
model,
inputTokens: result.usage?.prompt_tokens || 0,
outputTokens: result.usage?.completion_tokens || 0
};
};

View File

@@ -1,5 +1,6 @@
import type { ChatMessageItemType } from '@fastgpt/global/core/ai/type.d';
import { getAIApi } from '../config';
import { countGptMessagesChars } from '../../chat/utils';
export const Prompt_QuestionGuide = `我不太清楚问你什么问题,请帮我生成 3 个问题引导我继续提问。问题的长度应小于20个字符按 JSON 格式返回: ["问题1", "问题2", "问题3"]`;
@@ -10,6 +11,13 @@ export async function createQuestionGuide({
messages: ChatMessageItemType[];
model: string;
}) {
const concatMessages: ChatMessageItemType[] = [
...messages,
{
role: 'user',
content: Prompt_QuestionGuide
}
];
const ai = getAIApi({
timeout: 480000
});
@@ -17,28 +25,21 @@ export async function createQuestionGuide({
model: model,
temperature: 0.1,
max_tokens: 200,
messages: [
...messages,
{
role: 'user',
content: Prompt_QuestionGuide
}
],
messages: concatMessages,
stream: false
});
const answer = data.choices?.[0]?.message?.content || '';
const inputTokens = data.usage?.prompt_tokens || 0;
const outputTokens = data.usage?.completion_tokens || 0;
const start = answer.indexOf('[');
const end = answer.lastIndexOf(']');
const charsLength = countGptMessagesChars(concatMessages);
if (start === -1 || end === -1) {
return {
result: [],
inputTokens,
outputTokens
charsLength: 0
};
}
@@ -50,14 +51,12 @@ export async function createQuestionGuide({
try {
return {
result: JSON.parse(jsonStr),
inputTokens,
outputTokens
charsLength
};
} catch (error) {
return {
result: [],
inputTokens,
outputTokens
charsLength: 0
};
}
}

View File

@@ -1,18 +1,19 @@
import { replaceVariable } from '@fastgpt/global/common/string/tools';
import { getAIApi } from '../config';
import { ChatItemType } from '@fastgpt/global/core/chat/type';
import { countGptMessagesChars } from '../../chat/utils';
/*
query extension - 问题扩展
可以根据上下文,消除指代性问题以及扩展问题,利于检索。
*/
const defaultPrompt = `作为一个向量检索助手,你的任务是结合历史记录,从不同角度,为“原问题”生成个不同版本的“检索词”,从而提高向量检索的语义丰富度,提高向量检索的精度。生成的问题要求指向对象清晰明确。例如:
const defaultPrompt = `作为一个向量检索助手,你的任务是结合历史记录,从不同角度,为“原问题”生成个不同版本的“检索词”,从而提高向量检索的语义丰富度,提高向量检索的精度。生成的问题要求指向对象清晰明确,并与原问题语言相同。例如:
历史记录:
"""
"""
原问题: 介绍下剧情。
检索词: ["发生了什么故事?","故事梗概是什么?","讲述了什么故事"]
检索词: ["介绍下故事的背景和主要人物。","故事的主题是什么?","剧情是是如何发展的"]
----------------
历史记录:
"""
@@ -20,7 +21,7 @@ Q: 对话背景。
A: 当前对话是关于 FatGPT 的介绍和使用等。
"""
原问题: 怎么下载
检索词: ["FastGPT 怎么下载?","下载 FastGPT 需要什么条件?","有哪些渠道可以下载 FastGPT"]
检索词: ["FastGPT 如何下载?","下载 FastGPT 需要什么条件?","有哪些渠道可以下载 FastGPT"]
----------------
历史记录:
"""
@@ -30,15 +31,15 @@ Q: 报错 "no connection"
A: 报错"no connection"可能是因为……
"""
原问题: 怎么解决
检索词: ["FastGPT 报错"no connection"如何解决?", "报错 'no connection' 是什么原因", "FastGPT提示'no connection',要怎么办?"]
检索词: ["FastGPT 报错"no connection"如何解决?", "造成 'no connection' 报错的原因", "FastGPT提示'no connection',要怎么办?"]
----------------
历史记录:
"""
Q: 作者是谁?
A: FastGPT 的作者是 labring。
"""
原问题: 介绍下他
检索词: ["介绍下 FastGPT 的作者 labring。","作者 labring 的背景信息。","labring 为什么要做 FastGPT?"]
原问题: Tell me about him
检索词: ["Introduce labring, the author of FastGPT." ," Background information on author labring." "," Why does labring do FastGPT?"]
----------------
历史记录:
"""
@@ -105,8 +106,7 @@ export const queryExtension = async ({
rawQuery: string;
extensionQueries: string[];
model: string;
inputTokens: number;
outputTokens: number;
charsLength: number;
}> => {
const systemFewShot = chatBg
? `Q: 对话背景。
@@ -125,18 +125,20 @@ A: ${chatBg}
timeout: 480000
});
const messages = [
{
role: 'user',
content: replaceVariable(defaultPrompt, {
query: `${query}`,
histories: concatFewShot
})
}
];
const result = await ai.chat.completions.create({
model: model,
temperature: 0.01,
messages: [
{
role: 'user',
content: replaceVariable(defaultPrompt, {
query: `${query}`,
histories: concatFewShot
})
}
],
// @ts-ignore
messages,
stream: false
});
@@ -146,8 +148,7 @@ A: ${chatBg}
rawQuery: query,
extensionQueries: [],
model,
inputTokens: 0,
outputTokens: 0
charsLength: 0
};
}
@@ -160,8 +161,7 @@ A: ${chatBg}
rawQuery: query,
extensionQueries: queries,
model,
inputTokens: result.usage?.prompt_tokens || 0,
outputTokens: result.usage?.completion_tokens || 0
charsLength: countGptMessagesChars(messages)
};
} catch (error) {
console.log(error);
@@ -169,8 +169,7 @@ A: ${chatBg}
rawQuery: query,
extensionQueries: [],
model,
inputTokens: 0,
outputTokens: 0
charsLength: 0
};
}
};

View File

@@ -61,6 +61,9 @@ const AppSchema = new Schema({
type: String,
enum: Object.keys(PermissionTypeMap),
default: PermissionTypeEnum.private
},
teamTags: {
type: [String]
}
});

View File

@@ -92,6 +92,8 @@ try {
ChatItemSchema.index({ appId: 1, chatId: 1, dataId: 1 }, { background: true });
// admin charts
ChatItemSchema.index({ time: -1, obj: 1 }, { background: true });
// timer, clear history
ChatItemSchema.index({ teamId: 1, time: -1 }, { background: true });
} catch (error) {
console.log(error);
}

View File

@@ -83,6 +83,9 @@ try {
ChatSchema.index({ teamId: 1, appId: 1, updateTime: -1 }, { background: true });
// get share chat history
ChatSchema.index({ shareId: 1, outLinkUid: 1, updateTime: -1, source: 1 }, { background: true });
// timer, clear history
ChatSchema.index({ teamId: 1, updateTime: -1 }, { background: true });
} catch (error) {
console.log(error);
}

View File

@@ -2,7 +2,10 @@ import type { ChatItemType } from '@fastgpt/global/core/chat/type.d';
import { ChatRoleEnum, IMG_BLOCK_KEY } from '@fastgpt/global/core/chat/constants';
import { countMessagesTokens, countPromptTokens } from '@fastgpt/global/common/string/tiktoken';
import { adaptRole_Chat2Message } from '@fastgpt/global/core/chat/adapt';
import type { ChatCompletionContentPart } from '@fastgpt/global/core/ai/type.d';
import type {
ChatCompletionContentPart,
ChatMessageItemType
} from '@fastgpt/global/core/ai/type.d';
import axios from 'axios';
/* slice chat context by tokens */
@@ -56,6 +59,16 @@ export function ChatContextFilter({
return [...systemPrompts, ...chats];
}
export const replaceValidChars = (str: string) => {
const reg = /[\s\r\n]+/g;
return str.replace(reg, '');
};
export const countMessagesChars = (messages: ChatItemType[]) => {
return messages.reduce((sum, item) => sum + replaceValidChars(item.value).length, 0);
};
export const countGptMessagesChars = (messages: ChatMessageItemType[]) =>
messages.reduce((sum, item) => sum + replaceValidChars(item.content).length, 0);
/**
string to vision model. Follow the markdown code block rule for interception:

View File

@@ -147,8 +147,6 @@ export async function delCollectionAndRelatedSources({
collectionId: { $in: collectionIds }
});
await delay(2000);
// delete dataset.datas
await MongoDatasetData.deleteMany({ teamId, collectionId: { $in: collectionIds } }, { session });
// delete imgs

View File

@@ -66,6 +66,11 @@ export async function delDatasetRelevantData({
if (!datasets.length) return;
const teamId = datasets[0].teamId;
if (!teamId) {
return Promise.reject('teamId is required');
}
const datasetIds = datasets.map((item) => String(item._id));
// Get _id, teamId, fileId, metadata.relatedImgId for all collections

View File

@@ -7,10 +7,6 @@ import {
} from '@fastgpt/global/support/user/team/constant';
import { DatasetCollectionName } from '../schema';
import { DatasetColCollectionName } from '../collection/schema';
import {
DatasetDataIndexTypeEnum,
DatasetDataIndexTypeMap
} from '@fastgpt/global/core/dataset/constants';
export const DatasetDataCollectionName = 'dataset.datas';
@@ -54,11 +50,6 @@ const DatasetDataSchema = new Schema({
type: Boolean,
default: false
},
type: {
type: String,
enum: Object.keys(DatasetDataIndexTypeMap),
default: DatasetDataIndexTypeEnum.custom
},
dataId: {
type: String,
required: true

View File

@@ -14,22 +14,54 @@ export const datasetSearchQueryExtension = async ({
extensionBg?: string;
histories?: ChatItemType[];
}) => {
// concat query
let queries = [query];
let rewriteQuery =
histories.length > 0
? `${histories
.map((item) => {
return `${item.obj}: ${item.value}`;
})
.join('\n')}
Human: ${query}
`
: query;
const filterSamQuery = (queries: string[]) => {
const set = new Set<string>();
const filterSameQueries = queries.filter((item) => {
// 删除所有的标点符号与空格等,只对文本进行比较
const str = hashStr(item.replace(/[^\p{L}\p{N}]/gu, ''));
if (set.has(str)) return false;
set.add(str);
return true;
});
return filterSameQueries;
};
let { queries, rewriteQuery, alreadyExtension } = (() => {
// concat query
let rewriteQuery =
histories.length > 0
? `${histories
.map((item) => {
return `${item.obj}: ${item.value}`;
})
.join('\n')}
Human: ${query}
`
: query;
/* if query already extension, direct parse */
try {
const jsonParse = JSON.parse(query);
const queries: string[] = Array.isArray(jsonParse) ? filterSamQuery(jsonParse) : [query];
const alreadyExtension = Array.isArray(jsonParse);
return {
queries,
rewriteQuery: alreadyExtension ? queries.join('\n') : rewriteQuery,
alreadyExtension: alreadyExtension
};
} catch (error) {
return {
queries: [query],
rewriteQuery,
alreadyExtension: false
};
}
})();
// ai extension
const aiExtensionResult = await (async () => {
if (!extensionModel) return;
if (!extensionModel || alreadyExtension) return;
const result = await queryExtension({
chatBg: extensionBg,
query,
@@ -39,23 +71,13 @@ export const datasetSearchQueryExtension = async ({
if (result.extensionQueries?.length === 0) return;
return result;
})();
if (aiExtensionResult) {
queries = queries.concat(aiExtensionResult.extensionQueries);
queries = filterSamQuery(queries.concat(aiExtensionResult.extensionQueries));
rewriteQuery = queries.join('\n');
}
const set = new Set<string>();
const filterSameQueries = queries.filter((item) => {
// 删除所有的标点符号与空格等,只对文本进行比较
const str = hashStr(item.replace(/[^\p{L}\p{N}]/gu, ''));
if (set.has(str)) return false;
set.add(str);
return true;
});
return {
concatQueries: filterSameQueries,
concatQueries: queries,
rewriteQuery,
aiExtensionResult
};

View File

@@ -11,7 +11,7 @@ import { simpleText } from '@fastgpt/global/common/string/tools';
import { countPromptTokens } from '@fastgpt/global/common/string/tiktoken';
import type { VectorModelItemType, LLMModelItemType } from '@fastgpt/global/core/ai/model.d';
export const lockTrainingDataByTeamId = async (teamId: string, retry = 3): Promise<any> => {
export const lockTrainingDataByTeamId = async (teamId: string): Promise<any> => {
try {
await MongoDatasetTraining.updateMany(
{
@@ -21,13 +21,7 @@ export const lockTrainingDataByTeamId = async (teamId: string, retry = 3): Promi
lockTime: new Date('2999/5/5')
}
);
} catch (error) {
if (retry > 0) {
await delay(1000);
return lockTrainingDataByTeamId(teamId, retry - 1);
}
return Promise.reject(error);
}
} catch (error) {}
};
export async function pushDataListToTrainingQueue({
@@ -51,17 +45,15 @@ export async function pushDataListToTrainingQueue({
datasetId: { _id: datasetId, vectorModel, agentModel }
} = await getCollectionWithDataset(collectionId);
const checkModelValid = async ({ collectionId }: { collectionId: string }) => {
if (!collectionId) return Promise.reject(`CollectionId is empty`);
const checkModelValid = async () => {
if (trainingMode === TrainingModeEnum.chunk) {
const vectorModelData = vectorModelList?.find((item) => item.model === vectorModel);
if (!vectorModelData) {
return Promise.reject(`Model ${vectorModel} is inValid`);
return Promise.reject(`File model ${vectorModel} is inValid`);
}
return {
maxToken: vectorModelData.maxToken * 1.5,
maxToken: vectorModelData.maxToken * 1.3,
model: vectorModelData.model,
weight: vectorModelData.weight
};
@@ -70,7 +62,7 @@ export async function pushDataListToTrainingQueue({
if (trainingMode === TrainingModeEnum.qa) {
const qaModelData = datasetModelList?.find((item) => item.model === agentModel);
if (!qaModelData) {
return Promise.reject(`Model ${agentModel} is inValid`);
return Promise.reject(`Vector model ${agentModel} is inValid`);
}
return {
maxToken: qaModelData.maxContext * 0.8,
@@ -81,9 +73,7 @@ export async function pushDataListToTrainingQueue({
return Promise.reject(`Training mode "${trainingMode}" is inValid`);
};
const { model, maxToken, weight } = await checkModelValid({
collectionId
});
const { model, maxToken, weight } = await checkModelValid();
// format q and a, remove empty char
data.forEach((item) => {

View File

@@ -2,7 +2,7 @@
import { connectionMongo, type Model } from '../../../common/mongo';
const { Schema, model, models } = connectionMongo;
import { DatasetTrainingSchemaType } from '@fastgpt/global/core/dataset/type';
import { DatasetDataIndexTypeMap, TrainingTypeMap } from '@fastgpt/global/core/dataset/constants';
import { TrainingTypeMap } from '@fastgpt/global/core/dataset/constants';
import { DatasetColCollectionName } from '../collection/schema';
import { DatasetCollectionName } from '../schema';
import {
@@ -86,11 +86,6 @@ const TrainingDataSchema = new Schema({
indexes: {
type: [
{
type: {
type: String,
enum: Object.keys(DatasetDataIndexTypeMap),
required: true
},
text: {
type: String,
required: true

View File

@@ -15,7 +15,7 @@
"nextjs-cors": "^2.1.2",
"node-cron": "^3.0.3",
"pg": "^8.10.0",
"date-fns": "^2.30.0",
"date-fns": "2.30.0",
"tunnel": "^0.0.6"
},
"devDependencies": {

View File

@@ -19,14 +19,15 @@ export async function authOpenApiKey({ apikey }: { apikey: string }) {
// auth limit
// @ts-ignore
if (global.feConfigs?.isPlus) {
await POST('/support/openapi/authLimit', { openApi } as AuthOpenApiLimitProps);
await POST('/support/openapi/authLimit', {
openApi: openApi.toObject()
} as AuthOpenApiLimitProps);
}
updateApiKeyUsedTime(openApi._id);
return {
apikey,
userId: String(openApi.userId),
teamId: String(openApi.teamId),
tmbId: String(openApi.tmbId),
appId: openApi.appId || ''

View File

@@ -1,8 +1,6 @@
import { connectionMongo, type Model } from '../../common/mongo';
const { Schema, model, models } = connectionMongo;
import type { OpenApiSchema } from '@fastgpt/global/support/openapi/type';
import { PRICE_SCALE } from '@fastgpt/global/support/wallet/bill/constants';
import { formatStorePrice2Read } from '@fastgpt/global/support/wallet/bill/tools';
import {
TeamCollectionName,
TeamMemberCollectionName
@@ -10,10 +8,6 @@ import {
const OpenApiSchema = new Schema(
{
userId: {
type: Schema.Types.ObjectId,
ref: 'user'
},
teamId: {
type: Schema.Types.ObjectId,
ref: TeamCollectionName,
@@ -44,22 +38,17 @@ const OpenApiSchema = new Schema(
type: String,
default: 'Api Key'
},
usage: {
// total usage. value from bill total
usagePoints: {
type: Number,
default: 0,
get: (val: number) => formatStorePrice2Read(val)
default: 0
},
limit: {
expiredTime: {
type: Date
},
credit: {
// value from user settings
maxUsagePoints: {
type: Number,
default: -1,
set: (val: number) => val * PRICE_SCALE,
get: (val: number) => formatStorePrice2Read(val)
default: -1
}
}
},

View File

@@ -8,15 +8,21 @@ export function updateApiKeyUsedTime(id: string) {
});
}
export function updateApiKeyUsage({ apikey, usage }: { apikey: string; usage: number }) {
export function updateApiKeyUsage({
apikey,
totalPoints
}: {
apikey: string;
totalPoints: number;
}) {
MongoOpenApi.findOneAndUpdate(
{ apiKey: apikey },
{
$inc: {
usage
usagePoints: totalPoints
}
}
).catch((err) => {
console.log('update apiKey usage error', err);
console.log('update apiKey totalPoints error', err);
});
}

View File

@@ -35,8 +35,7 @@ const OutLinkSchema = new Schema({
type: String,
required: true
},
total: {
// total amount
usagePoints: {
type: Number,
default: 0
},
@@ -48,6 +47,10 @@ const OutLinkSchema = new Schema({
default: false
},
limit: {
maxUsagePoints: {
type: Number,
default: -1
},
expiredTime: {
type: Date
},
@@ -55,16 +58,18 @@ const OutLinkSchema = new Schema({
type: Number,
default: 1000
},
credit: {
type: Number,
default: -1
},
hookUrl: {
type: String
}
}
});
try {
OutLinkSchema.index({ shareId: -1 });
} catch (error) {
console.log(error);
}
export const MongoOutLink: Model<SchemaType> =
models['outlinks'] || model('outlinks', OutLinkSchema);

View File

@@ -1,18 +1,19 @@
import axios from 'axios';
import { MongoOutLink } from './schema';
import { FastGPTProUrl } from '../../common/system/constants';
import { ChatHistoryItemResType } from '@fastgpt/global/core/chat/type';
export const updateOutLinkUsage = async ({
export const addOutLinkUsage = async ({
shareId,
total
totalPoints
}: {
shareId: string;
total: number;
totalPoints: number;
}) => {
MongoOutLink.findOneAndUpdate(
{ shareId },
{
$inc: { total },
$inc: { usagePoints: totalPoints },
lastTime: new Date()
}
).catch((err) => {
@@ -23,11 +24,13 @@ export const updateOutLinkUsage = async ({
export const pushResult2Remote = async ({
outLinkUid,
shareId,
appName,
responseData
}: {
outLinkUid?: string; // raw id, not parse
shareId?: string;
responseData?: any[];
appName: string;
responseData?: ChatHistoryItemResType[];
}) => {
if (!shareId || !outLinkUid || !FastGPTProUrl) return;
try {
@@ -42,6 +45,7 @@ export const pushResult2Remote = async ({
url: '/shareAuth/finish',
data: {
token: outLinkUid,
appName,
responseData
}
});

View File

@@ -107,7 +107,7 @@ export async function authDatasetCollection({
collection: CollectionWithDatasetType;
}
> {
const { userId, teamId, tmbId } = await parseHeaderCert(props);
const { teamId, tmbId } = await parseHeaderCert(props);
const { role } = await getTmbInfoByTmbId({ tmbId });
const { collection, isOwner, canWrite } = await (async () => {
@@ -143,7 +143,6 @@ export async function authDatasetCollection({
})();
return {
userId,
teamId,
tmbId,
collection,
@@ -163,7 +162,7 @@ export async function authDatasetFile({
file: DatasetFileSchema;
}
> {
const { userId, teamId, tmbId } = await parseHeaderCert(props);
const { teamId, tmbId } = await parseHeaderCert(props);
const [file, collection] = await Promise.all([
getFileById({ bucketName: BucketNameEnum.dataset, fileId }),
@@ -190,7 +189,6 @@ export async function authDatasetFile({
});
return {
userId,
teamId,
tmbId,
file,

View File

@@ -12,7 +12,7 @@ export async function authUserNotVisitor(props: AuthModeType): Promise<
role: `${TeamMemberRoleEnum}`;
}
> {
const { userId, teamId, tmbId } = await parseHeaderCert(props);
const { teamId, tmbId } = await parseHeaderCert(props);
const team = await getTmbInfoByTmbId({ tmbId });
if (team.role === TeamMemberRoleEnum.visitor) {
@@ -20,7 +20,6 @@ export async function authUserNotVisitor(props: AuthModeType): Promise<
}
return {
userId,
teamId,
tmbId,
team,

View File

@@ -94,10 +94,10 @@ export async function parseHeaderCert({
})();
// auth apikey
const { userId, teamId, tmbId, appId: apiKeyAppId = '' } = await authOpenApiKey({ apikey });
const { teamId, tmbId, appId: apiKeyAppId = '' } = await authOpenApiKey({ apikey });
return {
uid: userId,
uid: '',
teamId,
tmbId,
apikey,

View File

@@ -1,23 +0,0 @@
import { StandSubPlanLevelMapType } from '@fastgpt/global/support/wallet/sub/type';
import { getVectorCountByTeamId } from '../../../common/vectorStore/controller';
import { getTeamDatasetMaxSize } from '../../wallet/sub/utils';
export const checkDatasetLimit = async ({
teamId,
insertLen = 0,
standardPlans
}: {
teamId: string;
insertLen?: number;
standardPlans?: StandSubPlanLevelMapType;
}) => {
const [{ maxSize }, usedSize] = await Promise.all([
getTeamDatasetMaxSize({ teamId, standardPlans }),
getVectorCountByTeamId(teamId)
]);
if (usedSize + insertLen >= maxSize) {
return Promise.reject(`数据库容量不足,无法继续添加。可以在账号页面进行扩容。`);
}
return;
};

View File

@@ -0,0 +1,91 @@
import { getVectorCountByTeamId } from '../../common/vectorStore/controller';
import { getTeamPlanStatus, getTeamStandPlan } from '../../support/wallet/sub/utils';
import { MongoApp } from '../../core/app/schema';
import { MongoPlugin } from '../../core/plugin/schema';
import { MongoDataset } from '../../core/dataset/schema';
import { DatasetTypeEnum } from '@fastgpt/global/core/dataset/constants';
import { TeamErrEnum } from '@fastgpt/global/common/error/code/team';
export const checkDatasetLimit = async ({
teamId,
insertLen = 0
}: {
teamId: string;
insertLen?: number;
}) => {
const [{ standardConstants, totalPoints, usedPoints, datasetMaxSize }, usedSize] =
await Promise.all([getTeamPlanStatus({ teamId }), getVectorCountByTeamId(teamId)]);
if (!standardConstants) return;
if (usedSize + insertLen >= datasetMaxSize) {
return Promise.reject(TeamErrEnum.datasetSizeNotEnough);
}
if (usedPoints >= totalPoints) {
return Promise.reject(TeamErrEnum.aiPointsNotEnough);
}
return;
};
export const checkTeamAIPoints = async (teamId: string) => {
const { standardConstants, totalPoints, usedPoints } = await getTeamPlanStatus({
teamId
});
if (!standardConstants) return;
if (usedPoints >= totalPoints) {
return Promise.reject(TeamErrEnum.aiPointsNotEnough);
}
return {
totalPoints,
usedPoints
};
};
export const checkTeamDatasetLimit = async (teamId: string) => {
const [{ standardConstants }, datasetCount] = await Promise.all([
getTeamStandPlan({ teamId }),
MongoDataset.countDocuments({
teamId,
type: { $ne: DatasetTypeEnum.folder }
})
]);
if (standardConstants && datasetCount >= standardConstants.maxDatasetAmount) {
return Promise.reject(TeamErrEnum.datasetAmountNotEnough);
}
};
export const checkTeamAppLimit = async (teamId: string) => {
const [{ standardConstants }, appCount] = await Promise.all([
getTeamStandPlan({ teamId }),
MongoApp.count({ teamId })
]);
if (standardConstants && appCount >= standardConstants.maxAppAmount) {
return Promise.reject(TeamErrEnum.appAmountNotEnough);
}
};
export const checkTeamPluginLimit = async (teamId: string) => {
const [{ standardConstants }, pluginCount] = await Promise.all([
getTeamStandPlan({ teamId }),
MongoPlugin.count({ teamId })
]);
if (standardConstants && pluginCount >= standardConstants.maxAppAmount) {
return Promise.reject(TeamErrEnum.pluginAmountNotEnough);
}
};
export const checkTeamReRankPermission = async (teamId: string) => {
const { standardConstants } = await getTeamStandPlan({
teamId
});
if (standardConstants && !standardConstants?.permissionReRank) {
return false;
}
return true;
};

View File

@@ -2,7 +2,6 @@ import { UserType } from '@fastgpt/global/support/user/type';
import { MongoUser } from './schema';
import { getTmbInfoByTmbId, getUserDefaultTeam } from './team/controller';
import { ERROR_ENUM } from '@fastgpt/global/common/error/errorCode';
import { UserErrEnum } from '@fastgpt/global/common/error/code/user';
export async function authUserExist({ userId, username }: { userId?: string; username?: string }) {
if (userId) {
@@ -47,22 +46,3 @@ export async function getUserDetail({
team: tmb
};
}
export async function getUserAndAuthBalance({
tmbId,
minBalance
}: {
tmbId: string;
minBalance?: number;
}) {
const user = await getUserDetail({ tmbId });
if (!user) {
return Promise.reject(UserErrEnum.unAuthUser);
}
if (minBalance !== undefined && user.team.balance < minBalance) {
return Promise.reject(UserErrEnum.balanceNotEnough);
}
return user;
}

View File

@@ -1,7 +1,7 @@
import { connectionMongo, type Model } from '../../common/mongo';
const { Schema, model, models } = connectionMongo;
import { hashStr } from '@fastgpt/global/common/string/tools';
import { PRICE_SCALE } from '@fastgpt/global/support/wallet/bill/constants';
import { PRICE_SCALE } from '@fastgpt/global/support/wallet/constants';
import type { UserModelSchema } from '@fastgpt/global/support/user/type';
import { UserStatusEnum, userStatusMap } from '@fastgpt/global/support/user/constant';
@@ -63,6 +63,8 @@ const UserSchema = new Schema({
});
try {
// login
UserSchema.index({ username: 1, password: 1 });
UserSchema.index({ createTime: -1 });
} catch (error) {
console.log(error);

View File

@@ -36,7 +36,7 @@ export async function getTmbInfoByTmbId({ tmbId }: { tmbId: string }) {
return Promise.reject('tmbId or userId is required');
}
return getTeamMember({
_id: new Types.ObjectId(tmbId),
_id: new Types.ObjectId(String(tmbId)),
status: notLeaveStatus
});
}

View File

@@ -27,7 +27,10 @@ const TeamSchema = new Schema({
},
maxSize: {
type: Number,
default: 3
default: 1
},
tagsUrl: {
type: String
},
limit: {
lastExportDatasetTime: {

View File

@@ -0,0 +1,35 @@
import { connectionMongo, type Model } from '../../../common/mongo';
const { Schema, model, models } = connectionMongo;
import { TeamTagsSchema as TeamTagsSchemaType } from '@fastgpt/global/support/user/team/type.d';
import {
TeamCollectionName,
TeamTagsCollectionName
} from '@fastgpt/global/support/user/team/constant';
const TeamTagsSchema = new Schema({
label: {
type: String,
required: true
},
teamId: {
type: Schema.Types.ObjectId,
ref: TeamCollectionName,
required: true
},
key: {
type: String
},
createTime: {
type: Date,
default: () => new Date()
}
});
try {
TeamTagsSchema.index({ teamId: 1 });
} catch (error) {
console.log(error);
}
export const MongoTeamTags: Model<TeamTagsSchemaType> =
models[TeamTagsCollectionName] || model(TeamTagsCollectionName, TeamTagsSchema);

View File

@@ -1,3 +1,8 @@
/*
user sub plan
1. type=standard: There will only be 1, and each team will have one
2. type=extraDatasetSize/extraPoints: Can buy multiple
*/
import { connectionMongo, type Model } from '../../../common/mongo';
const { Schema, model, models } = connectionMongo;
import { TeamCollectionName } from '@fastgpt/global/support/user/team/constant';
@@ -23,25 +28,10 @@ const SubSchema = new Schema({
required: true
},
status: {
// active: continue sub; canceled: canceled sub;
type: String,
enum: Object.keys(subStatusMap),
required: true
},
mode: {
type: String,
enum: Object.keys(subModeMap)
},
currentMode: {
type: String,
enum: Object.keys(subModeMap),
required: true
},
nextMode: {
type: String,
enum: Object.keys(subModeMap),
required: true
},
startTime: {
type: Date,
default: () => new Date()
@@ -55,12 +45,16 @@ const SubSchema = new Schema({
type: Number,
required: true
},
pointPrice: {
// stand level point total price
type: Number
},
// sub content
// standard sub
currentMode: {
type: String,
enum: Object.keys(subModeMap)
},
nextMode: {
type: String,
enum: Object.keys(subModeMap)
},
currentSubLevel: {
type: String,
enum: Object.keys(standardSubLevelMap)
@@ -69,79 +63,32 @@ const SubSchema = new Schema({
type: String,
enum: Object.keys(standardSubLevelMap)
},
// stand sub and extra points sub. Plan total points
totalPoints: {
type: Number
},
pointPrice: {
// stand level point total price
type: Number
},
surplusPoints: {
// plan surplus points
type: Number
},
// extra dataset size
currentExtraDatasetSize: {
type: Number
},
nextExtraDatasetSize: {
type: Number
},
currentExtraPoints: {
type: Number
},
nextExtraPoints: {
type: Number
},
// standard sub limit
// maxTeamMember: {
// type: Number
// },
// maxAppAmount: {
// type: Number
// },
// maxDatasetAmount: {
// type: Number
// },
// chatHistoryStoreDuration: {
// // n day
// type: Number
// },
// maxDatasetSize: {
// type: Number
// },
// trainingWeight: {
// // 0 1 2 3
// type: Number
// },
// customApiKey: {
// type: Boolean
// },
// customCopyright: {
// type: Boolean
// },
// websiteSyncInterval: {
// // hours
// type: Number
// },
// reRankWeight: {
// // 0 1 2 3
// type: Number
// },
// totalPoints: {
// // record standard sub points
// type: Number
// },
surplusPoints: {
// standard sub / extra points sub
type: Number
},
// abandon
renew: Boolean, //决定是否续费
datasetStoreAmount: Number
}
});
try {
SubSchema.index({ teamId: 1 });
SubSchema.index({ status: 1 });
SubSchema.index({ type: 1 });
SubSchema.index({ expiredTime: -1 });
// get team plan
SubSchema.index({ teamId: 1, type: 1, expiredTime: -1 });
// timer task. check expired plan; update standard plan;
SubSchema.index({ type: 1, currentSubLevel: 1, expiredTime: -1 });
} catch (error) {
console.log(error);
}

View File

@@ -1,87 +1,147 @@
import { SubTypeEnum } from '@fastgpt/global/support/wallet/sub/constants';
import {
StandardSubLevelEnum,
SubModeEnum,
SubStatusEnum,
SubTypeEnum
} from '@fastgpt/global/support/wallet/sub/constants';
import { MongoTeamSub } from './schema';
import { addHours } from 'date-fns';
import { FeTeamSubType, StandSubPlanLevelMapType } from '@fastgpt/global/support/wallet/sub/type.d';
import { FeTeamPlanStatusType } from '@fastgpt/global/support/wallet/sub/type.d';
import { getVectorCountByTeamId } from '../../../common/vectorStore/controller';
import dayjs from 'dayjs';
import { ClientSession } from '../../../common/mongo';
import { addMonths } from 'date-fns';
/* get team dataset max size */
export const getTeamDatasetMaxSize = async ({
teamId,
standardPlans
}: {
teamId: string;
standardPlans?: StandSubPlanLevelMapType;
}) => {
if (!standardPlans) {
return {
maxSize: Infinity,
sub: null
};
}
export const getStandardPlans = () => {
return global?.subPlans?.standard;
};
export const getStandardPlan = (level: `${StandardSubLevelEnum}`) => {
return global.subPlans?.standard?.[level];
};
const plans = await MongoTeamSub.find({
teamId,
expiredTime: { $gte: addHours(new Date(), -3) }
}).lean();
const standard = plans.find((plan) => plan.type === SubTypeEnum.standard);
const extraDatasetSize = plans.find((plan) => plan.type === SubTypeEnum.extraDatasetSize);
const standardMaxDatasetSize =
standard?.currentSubLevel && standardPlans
? standardPlans[standard.currentSubLevel]?.maxDatasetSize || Infinity
: Infinity;
const totalDatasetSize =
standardMaxDatasetSize + (extraDatasetSize?.currentExtraDatasetSize || 0);
export const getTeamStandPlan = async ({ teamId }: { teamId: string }) => {
const standardPlans = global.subPlans?.standard;
const standard = await MongoTeamSub.findOne({ teamId, type: SubTypeEnum.standard }).lean();
return {
maxSize: totalDatasetSize,
sub: extraDatasetSize
[SubTypeEnum.standard]: standard,
standardConstants:
standard?.currentSubLevel && standardPlans
? standardPlans[standard.currentSubLevel]
: undefined
};
};
export const getTeamSubPlanStatus = async ({
export const initTeamStandardPlan2Free = async ({
teamId,
standardPlans
session
}: {
teamId: string;
standardPlans?: StandSubPlanLevelMapType;
}): Promise<FeTeamSubType> => {
session?: ClientSession;
}) => {
const freePoints = global?.subPlans?.standard?.free?.totalPoints || 100;
const teamStandardSub = await MongoTeamSub.findOne({ teamId, type: SubTypeEnum.standard });
if (teamStandardSub) {
teamStandardSub.status = SubStatusEnum.active;
teamStandardSub.currentMode = SubModeEnum.month;
teamStandardSub.nextMode = SubModeEnum.month;
teamStandardSub.startTime = new Date();
teamStandardSub.expiredTime = addMonths(new Date(), 1);
teamStandardSub.currentSubLevel = StandardSubLevelEnum.free;
teamStandardSub.nextSubLevel = StandardSubLevelEnum.free;
teamStandardSub.price = 0;
teamStandardSub.pointPrice = 0;
teamStandardSub.totalPoints = freePoints;
teamStandardSub.surplusPoints =
teamStandardSub.surplusPoints && teamStandardSub.surplusPoints < 0
? teamStandardSub.surplusPoints + freePoints
: freePoints;
return teamStandardSub.save({ session });
}
return MongoTeamSub.create(
[
{
teamId,
type: SubTypeEnum.standard,
status: SubStatusEnum.active,
currentMode: SubModeEnum.month,
nextMode: SubModeEnum.month,
startTime: new Date(),
expiredTime: addMonths(new Date(), 1),
price: 0,
pointPrice: 0,
currentSubLevel: StandardSubLevelEnum.free,
nextSubLevel: StandardSubLevelEnum.free,
totalPoints: freePoints,
surplusPoints: freePoints
}
],
{ session }
);
};
export const getTeamPlanStatus = async ({
teamId
}: {
teamId: string;
}): Promise<FeTeamPlanStatusType> => {
const standardPlans = global.subPlans?.standard;
const [plans, usedDatasetSize] = await Promise.all([
MongoTeamSub.find({ teamId }).lean(),
getVectorCountByTeamId(teamId)
]);
const standard = plans.find((plan) => plan.type === SubTypeEnum.standard);
const extraDatasetSize = plans.find((plan) => plan.type === SubTypeEnum.extraDatasetSize);
const extraPoints = plans.find((plan) => plan.type === SubTypeEnum.extraPoints);
const extraDatasetSize = plans.filter((plan) => plan.type === SubTypeEnum.extraDatasetSize);
const extraPoints = plans.filter((plan) => plan.type === SubTypeEnum.extraPoints);
// Free user, first login after expiration. The free subscription plan will be reset
if (
standard &&
standard.expiredTime &&
standard.currentSubLevel === StandardSubLevelEnum.free &&
dayjs(standard.expiredTime).isBefore(new Date())
) {
console.log('Init free stand plan', { teamId });
await initTeamStandardPlan2Free({ teamId });
return getTeamPlanStatus({ teamId });
}
const totalPoints = standardPlans
? (standard?.totalPoints || 0) +
extraPoints.reduce((acc, cur) => acc + (cur.totalPoints || 0), 0)
: Infinity;
const surplusPoints =
(standard?.surplusPoints || 0) +
extraPoints.reduce((acc, cur) => acc + (cur.surplusPoints || 0), 0);
const standardMaxDatasetSize =
standard?.currentSubLevel && standardPlans
? standardPlans[standard.currentSubLevel]?.maxDatasetSize || Infinity
: Infinity;
const totalDatasetSize =
standardMaxDatasetSize + (extraDatasetSize?.currentExtraDatasetSize || 0);
const standardMaxPoints =
standard?.currentSubLevel && standardPlans
? standardPlans[standard.currentSubLevel]?.totalPoints || Infinity
: Infinity;
const totalPoints = standardMaxPoints + (extraPoints?.currentExtraPoints || 0);
const surplusPoints = (standard?.surplusPoints || 0) + (extraPoints?.surplusPoints || 0);
standardMaxDatasetSize +
extraDatasetSize.reduce((acc, cur) => acc + (cur.currentExtraDatasetSize || 0), 0);
return {
[SubTypeEnum.standard]: standard,
[SubTypeEnum.extraDatasetSize]: extraDatasetSize,
[SubTypeEnum.extraPoints]: extraPoints,
standardConstants:
standard?.currentSubLevel && standardPlans
? standardPlans[standard.currentSubLevel]
: undefined,
standardMaxDatasetSize,
datasetMaxSize: totalDatasetSize,
usedDatasetSize,
standardMaxPoints,
totalPoints,
usedPoints: totalPoints - surplusPoints
usedPoints: totalPoints - surplusPoints,
datasetMaxSize: totalDatasetSize,
usedDatasetSize
};
};

View File

@@ -1,8 +1,8 @@
import { BillSourceEnum } from '@fastgpt/global/support/wallet/bill/constants';
import { MongoBill } from './schema';
import { UsageSourceEnum } from '@fastgpt/global/support/wallet/usage/constants';
import { MongoUsage } from './schema';
import { ClientSession } from '../../../common/mongo';
export const createTrainingBill = async ({
export const createTrainingUsage = async ({
teamId,
tmbId,
appName,
@@ -14,33 +14,33 @@ export const createTrainingBill = async ({
teamId: string;
tmbId: string;
appName: string;
billSource: `${BillSourceEnum}`;
billSource: `${UsageSourceEnum}`;
vectorModel: string;
agentModel: string;
session?: ClientSession;
}) => {
const [{ _id }] = await MongoBill.create(
const [{ _id }] = await MongoUsage.create(
[
{
teamId,
tmbId,
appName,
source: billSource,
totalPoints: 0,
list: [
{
moduleName: 'wallet.moduleName.index',
moduleName: 'support.wallet.moduleName.index',
model: vectorModel,
charsLength: 0,
amount: 0
},
{
moduleName: 'wallet.moduleName.qa',
moduleName: 'support.wallet.moduleName.qa',
model: agentModel,
charsLength: 0,
amount: 0
}
],
total: 0
]
}
],
{ session }

Some files were not shown because too many files have changed in this diff Show More