Commit 40168c56 by Archer Committed by GitHub

perf: logger (#186)

* feat: finish response

* perf: logger

* docs

* perf: log

* docs
parent 324e4a0e
...@@ -17,10 +17,5 @@ OPENAI_BASE_URL=https://api.openai.com/v1 ...@@ -17,10 +17,5 @@ OPENAI_BASE_URL=https://api.openai.com/v1
# 此处逻辑:优先走 ONEAPI_URL,如果填写了 ONEAPI_URL,key 也需要是 ONEAPI 的 key # 此处逻辑:优先走 ONEAPI_URL,如果填写了 ONEAPI_URL,key 也需要是 ONEAPI 的 key
CHAT_API_KEY=sk-xxxx CHAT_API_KEY=sk-xxxx
# db # db
MONGODB_URI=mongodb://username:password@0.0.0.0:27017/?authSource=admin MONGODB_URI=mongodb://username:password@0.0.0.0:27017/fastgpt
MONGODB_NAME=fastgpt PG_URL=postgresql://username:password@host:port/postgres
PG_HOST=0.0.0.0 \ No newline at end of file
PG_PORT=8100
PG_USER=root
PG_PASSWORD=psw
PG_DB_NAME=dbname
\ No newline at end of file
...@@ -58,6 +58,8 @@ ...@@ -58,6 +58,8 @@
"request-ip": "^3.3.0", "request-ip": "^3.3.0",
"sass": "^1.58.3", "sass": "^1.58.3",
"tunnel": "^0.0.6", "tunnel": "^0.0.6",
"winston": "^3.10.0",
"winston-mongodb": "^5.1.1",
"zustand": "^4.3.5" "zustand": "^4.3.5"
}, },
"devDependencies": { "devDependencies": {
......
...@@ -182,8 +182,9 @@ export const ChatModule: FlowModuleTemplateType = { ...@@ -182,8 +182,9 @@ export const ChatModule: FlowModuleTemplateType = {
{ {
key: TaskResponseKeyEnum.answerText, key: TaskResponseKeyEnum.answerText,
label: '模型回复', label: '模型回复',
description: '直接响应,无需配置', description: '如果外接了内容,会在回复结束时自动添加\n\n',
type: FlowOutputItemTypeEnum.hidden, valueType: FlowValueTypeEnum.string,
type: FlowOutputItemTypeEnum.source,
targets: [] targets: []
}, },
{ {
...@@ -285,7 +286,16 @@ export const AnswerModule: FlowModuleTemplateType = { ...@@ -285,7 +286,16 @@ export const AnswerModule: FlowModuleTemplateType = {
'可以使用 \\n 来实现换行。也可以通过外部模块输入实现回复,外部模块输入时会覆盖当前填写的内容' '可以使用 \\n 来实现换行。也可以通过外部模块输入实现回复,外部模块输入时会覆盖当前填写的内容'
} }
], ],
outputs: [] outputs: [
{
key: 'finish',
label: '回复结束',
description: '回复完成后触发',
valueType: FlowValueTypeEnum.boolean,
type: FlowOutputItemTypeEnum.source,
targets: []
}
]
}; };
export const TFSwitchModule: FlowModuleTemplateType = { export const TFSwitchModule: FlowModuleTemplateType = {
logo: '', logo: '',
......
...@@ -2,7 +2,7 @@ import type { NextApiRequest, NextApiResponse } from 'next'; ...@@ -2,7 +2,7 @@ import type { NextApiRequest, NextApiResponse } from 'next';
import { connectToDatabase } from '@/service/mongo'; import { connectToDatabase } from '@/service/mongo';
import { authUser, authApp, authShareChat, AuthUserTypeEnum } from '@/service/utils/auth'; import { authUser, authApp, authShareChat, AuthUserTypeEnum } from '@/service/utils/auth';
import { sseErrRes, jsonRes } from '@/service/response'; import { sseErrRes, jsonRes } from '@/service/response';
import { withNextCors } from '@/service/utils/tools'; import { addLog, withNextCors } from '@/service/utils/tools';
import { ChatRoleEnum, ChatSourceEnum, sseResponseEventEnum } from '@/constants/chat'; import { ChatRoleEnum, ChatSourceEnum, sseResponseEventEnum } from '@/constants/chat';
import { import {
dispatchHistory, dispatchHistory,
...@@ -181,7 +181,7 @@ export default withNextCors(async function handler(req: NextApiRequest, res: Nex ...@@ -181,7 +181,7 @@ export default withNextCors(async function handler(req: NextApiRequest, res: Nex
}); });
} }
console.log(`finish time: ${(Date.now() - startTime) / 1000}s`); addLog.info(`completions running time: ${(Date.now() - startTime) / 1000}s`);
if (stream) { if (stream) {
sseResponse({ sseResponse({
...@@ -351,6 +351,7 @@ export async function dispatchModules({ ...@@ -351,6 +351,7 @@ export async function dispatchModules({
res, res,
stream, stream,
detail, detail,
outputs: module.outputs,
userOpenaiAccount: user?.openaiAccount, userOpenaiAccount: user?.openaiAccount,
...params ...params
}; };
......
...@@ -4,6 +4,7 @@ import NodeCard from '../modules/NodeCard'; ...@@ -4,6 +4,7 @@ import NodeCard from '../modules/NodeCard';
import { FlowModuleItemType } from '@/types/flow'; import { FlowModuleItemType } from '@/types/flow';
import Container from '../modules/Container'; import Container from '../modules/Container';
import RenderInput from '../render/RenderInput'; import RenderInput from '../render/RenderInput';
import RenderOutput from '../render/RenderOutput';
const NodeAnswer = ({ data }: NodeProps<FlowModuleItemType>) => { const NodeAnswer = ({ data }: NodeProps<FlowModuleItemType>) => {
const { moduleId, inputs, outputs, onChangeNode } = data; const { moduleId, inputs, outputs, onChangeNode } = data;
...@@ -11,6 +12,7 @@ const NodeAnswer = ({ data }: NodeProps<FlowModuleItemType>) => { ...@@ -11,6 +12,7 @@ const NodeAnswer = ({ data }: NodeProps<FlowModuleItemType>) => {
<NodeCard minW={'400px'} {...data}> <NodeCard minW={'400px'} {...data}>
<Container borderTop={'2px solid'} borderTopColor={'myGray.200'}> <Container borderTop={'2px solid'} borderTopColor={'myGray.200'}>
<RenderInput moduleId={moduleId} onChangeNode={onChangeNode} flowInputList={inputs} /> <RenderInput moduleId={moduleId} onChangeNode={onChangeNode} flowInputList={inputs} />
<RenderOutput onChangeNode={onChangeNode} moduleId={moduleId} flowOutputList={outputs} />
</Container> </Container>
</NodeCard> </NodeCard>
); );
......
...@@ -43,7 +43,7 @@ export async function generateQA(): Promise<any> { ...@@ -43,7 +43,7 @@ export async function generateQA(): Promise<any> {
// task preemption // task preemption
if (!data) { if (!data) {
reduceQueue(); reduceQueue();
global.qaQueueLen <= 0 && console.log(`没有需要【QA】的数据, ${global.qaQueueLen}`); global.qaQueueLen <= 0 && console.log(`【QA】任务完成`);
return; return;
} }
......
...@@ -44,7 +44,7 @@ export async function generateVector(): Promise<any> { ...@@ -44,7 +44,7 @@ export async function generateVector(): Promise<any> {
// task preemption // task preemption
if (!data) { if (!data) {
reduceQueue(); reduceQueue();
global.vectorQueueLen <= 0 && console.log(`没有需要【索引】的数据, ${global.vectorQueueLen}`); global.vectorQueueLen <= 0 && console.log(`【索引】任务完成`);
return; return;
} }
......
...@@ -3,6 +3,7 @@ import { BillSourceEnum } from '@/constants/user'; ...@@ -3,6 +3,7 @@ import { BillSourceEnum } from '@/constants/user';
import { getModel } from '../utils/data'; import { getModel } from '../utils/data';
import { ChatHistoryItemResType } from '@/types/chat'; import { ChatHistoryItemResType } from '@/types/chat';
import { formatPrice } from '@/utils/user'; import { formatPrice } from '@/utils/user';
import { addLog } from '../utils/tools';
export const pushTaskBill = async ({ export const pushTaskBill = async ({
appName, appName,
...@@ -48,7 +49,11 @@ export const pushTaskBill = async ({ ...@@ -48,7 +49,11 @@ export const pushTaskBill = async ({
: []) : [])
]); ]);
console.log('finish bill:', formatPrice(total)); addLog.info(`finish completions`, {
source,
userId,
price: formatPrice(total)
});
}; };
export const updateShareChatBill = async ({ export const updateShareChatBill = async ({
...@@ -66,8 +71,8 @@ export const updateShareChatBill = async ({ ...@@ -66,8 +71,8 @@ export const updateShareChatBill = async ({
lastTime: new Date() lastTime: new Date()
} }
); );
} catch (error) { } catch (err) {
console.log('update shareChat error', error); addLog.error('update shareChat error', { err });
} }
}; };
...@@ -82,7 +87,7 @@ export const pushSplitDataBill = async ({ ...@@ -82,7 +87,7 @@ export const pushSplitDataBill = async ({
totalTokens: number; totalTokens: number;
appName: string; appName: string;
}) => { }) => {
console.log(`splitData generate success. token len: ${totalTokens}.`); addLog.info('splitData generate success', { totalTokens });
let billId; let billId;
...@@ -107,8 +112,8 @@ export const pushSplitDataBill = async ({ ...@@ -107,8 +112,8 @@ export const pushSplitDataBill = async ({
await User.findByIdAndUpdate(userId, { await User.findByIdAndUpdate(userId, {
$inc: { balance: -total } $inc: { balance: -total }
}); });
} catch (error) { } catch (err) {
console.log('创建账单失败:', error); addLog.error('Create completions bill error', { err });
billId && Bill.findByIdAndDelete(billId); billId && Bill.findByIdAndDelete(billId);
} }
}; };
...@@ -156,8 +161,8 @@ export const pushGenerateVectorBill = async ({ ...@@ -156,8 +161,8 @@ export const pushGenerateVectorBill = async ({
await User.findByIdAndUpdate(userId, { await User.findByIdAndUpdate(userId, {
$inc: { balance: -total } $inc: { balance: -total }
}); });
} catch (error) { } catch (err) {
console.log('创建账单失败:', error); addLog.error('Create generateVector bill error', { err });
billId && Bill.findByIdAndDelete(billId); billId && Bill.findByIdAndDelete(billId);
} }
} catch (error) { } catch (error) {
......
...@@ -17,6 +17,7 @@ import { ChatModelItemType } from '@/types/model'; ...@@ -17,6 +17,7 @@ import { ChatModelItemType } from '@/types/model';
import { UserModelSchema } from '@/types/mongoSchema'; import { UserModelSchema } from '@/types/mongoSchema';
import { textCensor } from '@/service/api/plugins'; import { textCensor } from '@/service/api/plugins';
import { ChatCompletionRequestMessageRoleEnum } from 'openai'; import { ChatCompletionRequestMessageRoleEnum } from 'openai';
import { AppModuleItemType } from '@/types/app';
export type ChatProps = { export type ChatProps = {
res: NextApiResponse; res: NextApiResponse;
...@@ -31,6 +32,7 @@ export type ChatProps = { ...@@ -31,6 +32,7 @@ export type ChatProps = {
systemPrompt?: string; systemPrompt?: string;
limitPrompt?: string; limitPrompt?: string;
userOpenaiAccount: UserModelSchema['openaiAccount']; userOpenaiAccount: UserModelSchema['openaiAccount'];
outputs: AppModuleItemType['outputs'];
}; };
export type ChatResponse = { export type ChatResponse = {
[TaskResponseKeyEnum.answerText]: string; [TaskResponseKeyEnum.answerText]: string;
...@@ -52,8 +54,12 @@ export const dispatchChatCompletion = async (props: Record<string, any>): Promis ...@@ -52,8 +54,12 @@ export const dispatchChatCompletion = async (props: Record<string, any>): Promis
userChatInput, userChatInput,
systemPrompt = '', systemPrompt = '',
limitPrompt = '', limitPrompt = '',
userOpenaiAccount userOpenaiAccount,
outputs
} = props as ChatProps; } = props as ChatProps;
if (!userChatInput) {
return Promise.reject('Question is empty');
}
// temperature adapt // temperature adapt
const modelConstantsData = getChatModel(model); const modelConstantsData = getChatModel(model);
...@@ -142,6 +148,8 @@ export const dispatchChatCompletion = async (props: Record<string, any>): Promis ...@@ -142,6 +148,8 @@ export const dispatchChatCompletion = async (props: Record<string, any>): Promis
messages: completeMessages messages: completeMessages
}); });
targetResponse({ res, detail, outputs });
return { return {
answerText: answer, answerText: answer,
totalTokens, totalTokens,
...@@ -304,6 +312,28 @@ function getMaxTokens({ ...@@ -304,6 +312,28 @@ function getMaxTokens({
}; };
} }
function targetResponse({
res,
outputs,
detail
}: {
res: NextApiResponse;
outputs: AppModuleItemType['outputs'];
detail: boolean;
}) {
const targets =
outputs.find((output) => output.key === TaskResponseKeyEnum.answerText)?.targets || [];
if (targets.length === 0) return;
sseResponse({
res,
event: detail ? sseResponseEventEnum.answer : undefined,
data: textAdaptGptResponse({
text: '\n'
})
});
}
async function streamResponse({ async function streamResponse({
res, res,
detail, detail,
......
...@@ -11,6 +11,7 @@ export type AnswerProps = { ...@@ -11,6 +11,7 @@ export type AnswerProps = {
}; };
export type AnswerResponse = { export type AnswerResponse = {
[TaskResponseKeyEnum.answerText]: string; [TaskResponseKeyEnum.answerText]: string;
finish: boolean;
}; };
export const dispatchAnswer = (props: Record<string, any>): AnswerResponse => { export const dispatchAnswer = (props: Record<string, any>): AnswerResponse => {
...@@ -27,6 +28,7 @@ export const dispatchAnswer = (props: Record<string, any>): AnswerResponse => { ...@@ -27,6 +28,7 @@ export const dispatchAnswer = (props: Record<string, any>): AnswerResponse => {
} }
return { return {
[TaskResponseKeyEnum.answerText]: text [TaskResponseKeyEnum.answerText]: text,
finish: true
}; };
}; };
...@@ -7,6 +7,8 @@ import { PRICE_SCALE } from '@/constants/common'; ...@@ -7,6 +7,8 @@ import { PRICE_SCALE } from '@/constants/common';
import { connectPg, PgClient } from './pg'; import { connectPg, PgClient } from './pg';
import { createHashPassword } from '@/utils/tools'; import { createHashPassword } from '@/utils/tools';
import { PgTrainingTableName } from '@/constants/plugin'; import { PgTrainingTableName } from '@/constants/plugin';
import { createLogger, format, transports } from 'winston';
import 'winston-mongodb';
/** /**
* connect MongoDB and init data * connect MongoDB and init data
...@@ -32,6 +34,9 @@ export async function connectToDatabase(): Promise<void> { ...@@ -32,6 +34,9 @@ export async function connectToDatabase(): Promise<void> {
}); });
} }
// logger
initLogger();
// init function // init function
getInitConfig(); getInitConfig();
...@@ -39,7 +44,6 @@ export async function connectToDatabase(): Promise<void> { ...@@ -39,7 +44,6 @@ export async function connectToDatabase(): Promise<void> {
mongoose.set('strictQuery', true); mongoose.set('strictQuery', true);
global.mongodb = await mongoose.connect(process.env.MONGODB_URI as string, { global.mongodb = await mongoose.connect(process.env.MONGODB_URI as string, {
bufferCommands: true, bufferCommands: true,
dbName: process.env.MONGODB_NAME,
maxConnecting: Number(process.env.DB_MAX_LINK || 5), maxConnecting: Number(process.env.DB_MAX_LINK || 5),
maxPoolSize: Number(process.env.DB_MAX_LINK || 5), maxPoolSize: Number(process.env.DB_MAX_LINK || 5),
minPoolSize: 2 minPoolSize: 2
...@@ -57,6 +61,37 @@ export async function connectToDatabase(): Promise<void> { ...@@ -57,6 +61,37 @@ export async function connectToDatabase(): Promise<void> {
startQueue(); startQueue();
} }
function initLogger() {
global.logger = createLogger({
transports: [
new transports.MongoDB({
db: process.env.MONGODB_URI as string,
collection: 'server_logs',
options: {
useUnifiedTopology: true
},
cappedSize: 500000000,
tryReconnect: true,
metaKey: 'meta',
format: format.combine(format.timestamp(), format.json())
}),
new transports.Console({
format: format.combine(
format.timestamp({ format: 'YYYY-MM-DD HH:mm:ss' }),
format.printf((info) => {
if (info.level === 'error') {
console.log(info.meta);
return `${info.level}: ${[info.timestamp]}: ${info.message}`;
}
return `${info.level}: ${[info.timestamp]}: ${info.message}${
info.meta ? `: ${JSON.stringify(info.meta)}` : ''
}`;
})
)
})
]
});
}
async function initRootUser() { async function initRootUser() {
try { try {
const rootUser = await User.findOne({ const rootUser = await User.findOne({
......
...@@ -8,13 +8,9 @@ export const connectPg = async () => { ...@@ -8,13 +8,9 @@ export const connectPg = async () => {
} }
global.pgClient = new Pool({ global.pgClient = new Pool({
host: process.env.PG_HOST, connectionString: process.env.PG_URL,
port: process.env.PG_PORT ? +process.env.PG_PORT : 5432,
user: process.env.PG_USER,
password: process.env.PG_PASSWORD,
database: process.env.PG_DB_NAME,
max: Number(process.env.DB_MAX_LINK || 5), max: Number(process.env.DB_MAX_LINK || 5),
idleTimeoutMillis: 30000, keepAlive: true,
connectionTimeoutMillis: 5000 connectionTimeoutMillis: 5000
}); });
......
...@@ -7,7 +7,7 @@ import { ...@@ -7,7 +7,7 @@ import {
ERROR_RESPONSE, ERROR_RESPONSE,
ERROR_ENUM ERROR_ENUM
} from './errorCode'; } from './errorCode';
import { clearCookie, sseResponse } from './utils/tools'; import { clearCookie, sseResponse, addLog } from './utils/tools';
export interface ResponseType<T = any> { export interface ResponseType<T = any> {
code: number; code: number;
...@@ -52,7 +52,24 @@ export const jsonRes = <T = any>( ...@@ -52,7 +52,24 @@ export const jsonRes = <T = any>(
} else if (openaiError[error?.response?.statusText]) { } else if (openaiError[error?.response?.statusText]) {
msg = openaiError[error.response.statusText]; msg = openaiError[error.response.statusText];
} }
console.log(error);
addLog.error(msg, {
message: error.message,
stack: error.stack,
...(error.config && {
config: {
headers: error.config.headers,
url: error.config.url,
data: error.config.data
}
}),
...(error.response && {
response: {
status: error.response.status,
statusText: error.response.statusText
}
})
});
} }
res.status(code).json({ res.status(code).json({
...@@ -92,7 +109,24 @@ export const sseErrRes = (res: NextApiResponse, error: any) => { ...@@ -92,7 +109,24 @@ export const sseErrRes = (res: NextApiResponse, error: any) => {
} else if (openaiError[error?.response?.statusText]) { } else if (openaiError[error?.response?.statusText]) {
msg = openaiError[error.response.statusText]; msg = openaiError[error.response.statusText];
} }
console.log('sse error => ', error);
addLog.error(`sse error: ${msg}`, {
message: error.message,
stack: error.stack,
...(error.config && {
config: {
headers: error.config.headers,
url: error.config.url,
data: error.config.data
}
}),
...(error.response && {
response: {
status: error.response.status,
statusText: error.response.statusText
}
})
});
sseResponse({ sseResponse({
res, res,
......
...@@ -65,6 +65,7 @@ export function withNextCors(handler: NextApiHandler): NextApiHandler { ...@@ -65,6 +65,7 @@ export function withNextCors(handler: NextApiHandler): NextApiHandler {
}; };
} }
/* start task */
export const startQueue = () => { export const startQueue = () => {
for (let i = 0; i < global.systemEnv.qaMaxProcess; i++) { for (let i = 0; i < global.systemEnv.qaMaxProcess; i++) {
generateQA(); generateQA();
...@@ -87,3 +88,13 @@ export const sseResponse = ({ ...@@ -87,3 +88,13 @@ export const sseResponse = ({
event && res.write(`event: ${event}\n`); event && res.write(`event: ${event}\n`);
res.write(`data: ${data}\n\n`); res.write(`data: ${data}\n\n`);
}; };
/* add logger */
export const addLog = {
info: (msg: string, obj?: Record<string, any>) => {
global.logger.info(msg, { meta: obj });
},
error: (msg: string, obj?: Record<string, any>) => {
global.logger.error(msg, { meta: obj });
}
};
...@@ -2,6 +2,7 @@ import type { Mongoose } from 'mongoose'; ...@@ -2,6 +2,7 @@ import type { Mongoose } from 'mongoose';
import type { Agent } from 'http'; import type { Agent } from 'http';
import type { Pool } from 'pg'; import type { Pool } from 'pg';
import type { Tiktoken } from '@dqbd/tiktoken'; import type { Tiktoken } from '@dqbd/tiktoken';
import type { Logger } from 'winston';
import { ChatModelItemType, QAModelItemType, VectorModelItemType } from './model'; import { ChatModelItemType, QAModelItemType, VectorModelItemType } from './model';
export type PagingData<T> = { export type PagingData<T> = {
...@@ -55,6 +56,9 @@ declare global { ...@@ -55,6 +56,9 @@ declare global {
var qaQueueLen: number; var qaQueueLen: number;
var vectorQueueLen: number; var vectorQueueLen: number;
var OpenAiEncMap: Tiktoken; var OpenAiEncMap: Tiktoken;
var logger: Logger;
var sendInformQueue: (() => Promise<void>)[]; var sendInformQueue: (() => Promise<void>)[];
var sendInformQueueLen: number; var sendInformQueueLen: number;
......
...@@ -89,15 +89,9 @@ services: ...@@ -89,15 +89,9 @@ services:
- TOKEN_KEY=any - TOKEN_KEY=any
- ROOT_KEY=root_key - ROOT_KEY=root_key
# mongo 配置,不需要改 # mongo 配置,不需要改
- MONGODB_URI=mongodb://username:password@mongo:27017 - MONGODB_URI=mongodb://username:password@mongo:27017/fastgpt
# - MONGODB_URI=mongodb://username:password@mongo:27017/?authSource=admin # pg配置. 不需要改
- MONGODB_NAME=fastgpt - PG_URL=postgresql://username:password@pg:5432/postgres
# pg配置.
- PG_HOST=pg
- PG_PORT=5432
- PG_USER=username
- PG_PASSWORD=password
- PG_DB_NAME=postgres
networks: networks:
fastgpt: fastgpt:
``` ```
...@@ -149,15 +143,9 @@ services: ...@@ -149,15 +143,9 @@ services:
# root key, 最高权限,可以内部接口互相调用 # root key, 最高权限,可以内部接口互相调用
- ROOT_KEY=root_key - ROOT_KEY=root_key
# mongo 配置,不需要改 # mongo 配置,不需要改
- MONGODB_URI=mongodb://username:password@0.0.0.0:27017 - MONGODB_URI=mongodb://username:password@0.0.0.0:27017/fastgpt
# - MONGODB_URI=mongodb://username:password@0.0.0.0:27017/?authSource=admin # pg配置. 不需要改
- MONGODB_NAME=fastgpt - PG_URL=postgresql://username:password@0.0.0.0:5432/postgres
# pg 配置
- PG_HOST=0.0.0.0
- PG_PORT=5432
- PG_USER=username
- PG_PASSWORD=password
- PG_DB_NAME=postgres
``` ```
## 四、运行 docker-compose ## 四、运行 docker-compose
......
# V4 版本初始化 # V4.0 版本初始化
新版 mongo 表进行了不少的变更,需要执行一些初始化脚本。 新版 mongo 表进行了不少的变更,需要执行一些初始化脚本。
......
...@@ -2,6 +2,15 @@ ...@@ -2,6 +2,15 @@
新版重新设置了对话存储结构,需要初始化原来的存储内容 新版重新设置了对话存储结构,需要初始化原来的存储内容
## 更新环境变量
优化了 PG 和 Mongo 的连接变量,只需要 1 个 url 即可。
```
MONGODB_URI=mongodb://username:password@0.0.0.0:27017/fastgpt
PG_URL=postgresql://username:password@0.0.0.0:5432/postgres
```
## 执行初始化 API ## 执行初始化 API
部署新版项目,并发起 3 个 HTTP 请求(记得携带 headers.rootkey,这个值是环境变量里的) 部署新版项目,并发起 3 个 HTTP 请求(记得携带 headers.rootkey,这个值是环境变量里的)
......
...@@ -28,8 +28,7 @@ const config = { ...@@ -28,8 +28,7 @@ const config = {
({ ({
docs: { docs: {
sidebarPath: require.resolve('./sidebars.js'), sidebarPath: require.resolve('./sidebars.js'),
editUrl: editUrl: 'https://github.com/labring/FastGPT/blob/main/docSite/'
'https://github.com/facebook/docusaurus/tree/main/packages/create-docusaurus/templates/shared/'
}, },
theme: { theme: {
customCss: require.resolve('./src/css/custom.css') customCss: require.resolve('./src/css/custom.css')
......
...@@ -14,6 +14,9 @@ ...@@ -14,6 +14,9 @@
"sidebar.docSidebar.category.Deploy": { "sidebar.docSidebar.category.Deploy": {
"message": "部署" "message": "部署"
}, },
"sidebar.docSidebar.category.Version Updating": {
"message": "版本更新"
},
"sidebar.docSidebar.category.Datasets": { "sidebar.docSidebar.category.Datasets": {
"message": "知识库实践" "message": "知识库实践"
}, },
......
...@@ -89,15 +89,9 @@ services: ...@@ -89,15 +89,9 @@ services:
- TOKEN_KEY=any - TOKEN_KEY=any
- ROOT_KEY=root_key - ROOT_KEY=root_key
# mongo 配置,不需要改 # mongo 配置,不需要改
- MONGODB_URI=mongodb://username:password@mongo:27017 # 如果这个连不上,尝试下面的 - MONGODB_URI=mongodb://username:password@mongo:27017/fastgpt
# - MONGODB_URI=mongodb://username:password@mongo:27017/?authSource=admin # pg配置. 不需要改
- MONGODB_NAME=fastgpt - PG_URL=postgresql://username:password@pg:5432/postgres
# pg配置.
- PG_HOST=pg
- PG_PORT=5432
- PG_USER=username
- PG_PASSWORD=password
- PG_DB_NAME=postgres
networks: networks:
fastgpt: fastgpt:
``` ```
...@@ -153,15 +147,9 @@ environment: ...@@ -153,15 +147,9 @@ environment:
# root key, 最高权限,可以内部接口互相调用 # root key, 最高权限,可以内部接口互相调用
- ROOT_KEY=root_key - ROOT_KEY=root_key
# mongo 配置,不需要改 # mongo 配置,不需要改
- MONGODB_URI=mongodb://username:password@0.0.0.0:27017 - MONGODB_URI=mongodb://username:password@0.0.0.0:27017/fastgpt
# - MONGODB_URI=mongodb://username:password@0.0.0.0:27017/?authSource=admin # pg配置. 不需要改
- MONGODB_NAME=fastgpt - PG_URL=postgresql://username:password@0.0.0.0:5432/postgres
# pg 配置
- PG_HOST=0.0.0.0
- PG_PORT=5432
- PG_USER=username
- PG_PASSWORD=password
- PG_DB_NAME=postgres
``` ```
## 四、运行 docker-compose ## 四、运行 docker-compose
......
# V4 版本初始化 # V4.0 版本初始化
新版 mongo 表进行了不少的变更,需要执行一些初始化脚本。 新版 mongo 表进行了不少的变更,需要执行一些初始化脚本。
......
...@@ -2,6 +2,15 @@ ...@@ -2,6 +2,15 @@
新版重新设置了对话存储结构,需要初始化原来的存储内容 新版重新设置了对话存储结构,需要初始化原来的存储内容
## 更新环境变量
优化了 PG 和 Mongo 的连接变量,只需要 1 个 url 即可。
```
MONGODB_URI=mongodb://username:password@0.0.0.0:27017/fastgpt
PG_URL=postgresql://username:password@0.0.0.0:5432/postgres
```
## 执行初始化 API ## 执行初始化 API
部署新版项目,并发起 3 个 HTTP 请求(记得携带 headers.rootkey,这个值是环境变量里的) 部署新版项目,并发起 3 个 HTTP 请求(记得携带 headers.rootkey,这个值是环境变量里的)
......
...@@ -53,7 +53,20 @@ const sidebars = { ...@@ -53,7 +53,20 @@ const sidebars = {
} }
] ]
}, },
'develop/oneapi' 'develop/oneapi',
{
type: 'category',
label: 'Version Updating',
link: {
type: 'generated-index'
},
items: [
{
type: 'autogenerated',
dirName: 'develop/update'
}
]
}
] ]
}, },
{ {
......
...@@ -54,14 +54,9 @@ services: ...@@ -54,14 +54,9 @@ services:
- TOKEN_KEY=any - TOKEN_KEY=any
- ROOT_KEY=root_key - ROOT_KEY=root_key
# mongo 配置,不需要改 # mongo 配置,不需要改
- MONGODB_URI=mongodb://username:password@mongo:27017/?authSource=admin - MONGODB_URI=mongodb://username:password@mongo:27017/fastgpt
- MONGODB_NAME=fastgpt # pg配置. 不需要改
# pg配置. - PG_URL=postgresql://username:password@pg:5432/postgres
- PG_HOST=pg
- PG_PORT=5432
- PG_USER=username
- PG_PASSWORD=password
- PG_DB_NAME=postgres
volumes: volumes:
- ./config.json:/app/data/config.json - ./config.json:/app/data/config.json
networks: networks:
...@@ -116,11 +111,6 @@ networks: ...@@ -116,11 +111,6 @@ networks:
# # root key, 最高权限,可以内部接口互相调用 # # root key, 最高权限,可以内部接口互相调用
# - ROOT_KEY=root_key # - ROOT_KEY=root_key
# # mongo 配置,不需要改 # # mongo 配置,不需要改
# - MONGODB_URI=mongodb://username:password@0.0.0.0:27017/?authSource=admin # - MONGODB_URI=mongodb://username:password@0.0.0.0:27017/fastgpt
# - MONGODB_NAME=fastgpt # # pg配置. 不需要改
# # pg 配置 # - PG_URL=postgresql://username:password@0.0.0.0:5432/postgres
# - PG_HOST=0.0.0.0
# - PG_PORT=5432
# - PG_USER=username
# - PG_PASSWORD=password
# - PG_DB_NAME=postgres
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment