-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* fix if-else find variables (#92) * fix if-else find variables * change workflow output type * fix tooltip style * fix * 4.8 (#93) * api middleware * perf: app version histories * faq * perf: value type show * fix: ts * fix: Run the same node multiple times * feat: auto save workflow * perf: auto save workflow --------- Co-authored-by: heheer <[email protected]>
- Loading branch information
1 parent
c8412e7
commit d407e87
Showing
87 changed files
with
1,576 additions
and
1,748 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
{ | ||
// Place your FastGPT 工作区 snippets here. Each snippet is defined under a snippet name and has a scope, prefix, body and | ||
// description. Add comma separated ids of the languages where the snippet is applicable in the scope field. If scope | ||
// is left empty or omitted, the snippet gets applied to all languages. The prefix is what is | ||
// used to trigger the snippet and the body will be expanded and inserted. Possible variables are: | ||
// $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders. | ||
// Placeholders with the same ids are connected. | ||
// Example: | ||
"Next api template": { | ||
"scope": "javascript,typescript", | ||
"prefix": "nextapi", | ||
"body": [ | ||
"import type { NextApiRequest, NextApiResponse } from 'next';", | ||
"import { NextAPI } from '@/service/middle/entry';", | ||
"", | ||
"type Props = {};", | ||
"", | ||
"type Response = {};", | ||
"", | ||
"async function handler(req: NextApiRequest, res: NextApiResponse<any>): Promise<{}> {", | ||
" $1", | ||
" return {}", | ||
"}", | ||
"", | ||
"export default NextAPI(handler);" | ||
], | ||
"description": "FastGPT Next API template" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { StoreNodeItemType } from '../workflow/type'; | ||
import { StoreEdgeItemType } from '../workflow/type/edge'; | ||
|
||
export type AppVersionSchemaType = { | ||
appId: string; | ||
time: Date; | ||
nodes: StoreNodeItemType[]; | ||
edges: StoreEdgeItemType[]; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,12 @@ | ||
import type { NextApiResponse, NextApiHandler, NextApiRequest } from 'next'; | ||
import type { NextApiResponse, NextApiRequest } from 'next'; | ||
import NextCors from 'nextjs-cors'; | ||
|
||
export function withNextCors(handler: NextApiHandler): NextApiHandler { | ||
return async function nextApiHandlerWrappedWithNextCors( | ||
req: NextApiRequest, | ||
res: NextApiResponse | ||
) { | ||
const methods = ['GET', 'eHEAD', 'PUT', 'PATCH', 'POST', 'DELETE']; | ||
const origin = req.headers.origin; | ||
await NextCors(req, res, { | ||
methods, | ||
origin: origin, | ||
optionsSuccessStatus: 200 | ||
}); | ||
|
||
return handler(req, res); | ||
}; | ||
export async function withNextCors(req: NextApiRequest, res: NextApiResponse) { | ||
const methods = ['GET', 'eHEAD', 'PUT', 'PATCH', 'POST', 'DELETE']; | ||
const origin = req.headers.origin; | ||
await NextCors(req, res, { | ||
methods, | ||
origin: origin, | ||
optionsSuccessStatus: 200 | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import { AppSchema } from '@fastgpt/global/core/app/type'; | ||
import { NodeInputKeyEnum } from '@fastgpt/global/core/workflow/constants'; | ||
import { FlowNodeTypeEnum } from '@fastgpt/global/core/workflow/node/constant'; | ||
import { getLLMModel } from '../ai/model'; | ||
import { MongoAppVersion } from './versionSchema'; | ||
|
||
export const beforeUpdateAppFormat = <T extends AppSchema['modules'] | undefined>({ | ||
nodes | ||
}: { | ||
nodes: T; | ||
}) => { | ||
if (nodes) { | ||
let maxTokens = 3000; | ||
|
||
nodes.forEach((item) => { | ||
if ( | ||
item.flowNodeType === FlowNodeTypeEnum.chatNode || | ||
item.flowNodeType === FlowNodeTypeEnum.tools | ||
) { | ||
const model = | ||
item.inputs.find((item) => item.key === NodeInputKeyEnum.aiModel)?.value || ''; | ||
const chatModel = getLLMModel(model); | ||
const quoteMaxToken = chatModel.quoteMaxToken || 3000; | ||
|
||
maxTokens = Math.max(maxTokens, quoteMaxToken); | ||
} | ||
}); | ||
|
||
nodes.forEach((item) => { | ||
if (item.flowNodeType === FlowNodeTypeEnum.datasetSearchNode) { | ||
item.inputs.forEach((input) => { | ||
if (input.key === NodeInputKeyEnum.datasetMaxTokens) { | ||
const val = input.value as number; | ||
if (val > maxTokens) { | ||
input.value = maxTokens; | ||
} | ||
} | ||
}); | ||
} | ||
}); | ||
} | ||
|
||
return { | ||
nodes | ||
}; | ||
}; | ||
|
||
export const getAppLatestVersion = async (appId: string, app?: AppSchema) => { | ||
const version = await MongoAppVersion.findOne({ | ||
appId | ||
}).sort({ | ||
time: -1 | ||
}); | ||
|
||
if (version) { | ||
return { | ||
nodes: version.nodes, | ||
edges: version.edges | ||
}; | ||
} | ||
return { | ||
nodes: app?.modules || [], | ||
edges: app?.edges || [] | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { connectionMongo, type Model } from '../../common/mongo'; | ||
const { Schema, model, models } = connectionMongo; | ||
import { AppVersionSchemaType } from '@fastgpt/global/core/app/version'; | ||
|
||
export const AppVersionCollectionName = 'app.versions'; | ||
|
||
const AppVersionSchema = new Schema({ | ||
appId: { | ||
type: Schema.Types.ObjectId, | ||
ref: AppVersionCollectionName, | ||
required: true | ||
}, | ||
time: { | ||
type: Date, | ||
default: () => new Date() | ||
}, | ||
nodes: { | ||
type: Array, | ||
default: [] | ||
}, | ||
edges: { | ||
type: Array, | ||
default: [] | ||
} | ||
}); | ||
|
||
try { | ||
AppVersionSchema.index({ appId: 1, time: -1 }); | ||
} catch (error) { | ||
console.log(error); | ||
} | ||
|
||
export const MongoAppVersion: Model<AppVersionSchemaType> = | ||
models[AppVersionCollectionName] || model(AppVersionCollectionName, AppVersionSchema); | ||
|
||
MongoAppVersion.syncIndexes(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.