mirror of
https://github.com/labring/FastGPT.git
synced 2025-07-22 12:20:34 +00:00
4.8.3 (#1654)
* Milvus (#1644) * feat: support regx * 4.8.3 test and fix (#1648) * perf: version tip * feat: sandbox support log * fix: debug component render * fix: share page header * fix: input guide auth * fix: iso viewport * remove file * fix: route url * feat: add debug timout * perf: reference select support trigger * perf: session code * perf: theme * perf: load milvus
This commit is contained in:
@@ -85,7 +85,7 @@ export async function searchDatasetData(props: SearchDatasetDataProps) {
|
||||
const { results } = await recallFromVectorStore({
|
||||
teamId,
|
||||
datasetIds,
|
||||
vectors,
|
||||
vector: vectors[0],
|
||||
limit
|
||||
});
|
||||
|
||||
@@ -94,7 +94,7 @@ export async function searchDatasetData(props: SearchDatasetDataProps) {
|
||||
{
|
||||
teamId,
|
||||
datasetId: { $in: datasetIds },
|
||||
collectionId: { $in: results.map((item) => item.collectionId) },
|
||||
collectionId: { $in: Array.from(new Set(results.map((item) => item.collectionId))) },
|
||||
'indexes.dataId': { $in: results.map((item) => item.id?.trim()) }
|
||||
},
|
||||
'datasetId collectionId q a chunkIndex indexes'
|
||||
@@ -118,26 +118,24 @@ export async function searchDatasetData(props: SearchDatasetDataProps) {
|
||||
|
||||
concatResults.sort((a, b) => b.score - a.score);
|
||||
|
||||
const formatResult = concatResults
|
||||
.map((data, index) => {
|
||||
if (!data.collectionId) {
|
||||
console.log('Collection is not found', data);
|
||||
}
|
||||
const formatResult = concatResults.map((data, index) => {
|
||||
if (!data.collectionId) {
|
||||
console.log('Collection is not found', data);
|
||||
}
|
||||
|
||||
const result: SearchDataResponseItemType = {
|
||||
id: String(data._id),
|
||||
q: data.q,
|
||||
a: data.a,
|
||||
chunkIndex: data.chunkIndex,
|
||||
datasetId: String(data.datasetId),
|
||||
collectionId: String(data.collectionId?._id),
|
||||
...getCollectionSourceData(data.collectionId),
|
||||
score: [{ type: SearchScoreTypeEnum.embedding, value: data.score, index }]
|
||||
};
|
||||
const result: SearchDataResponseItemType = {
|
||||
id: String(data._id),
|
||||
q: data.q,
|
||||
a: data.a,
|
||||
chunkIndex: data.chunkIndex,
|
||||
datasetId: String(data.datasetId),
|
||||
collectionId: String(data.collectionId?._id),
|
||||
...getCollectionSourceData(data.collectionId),
|
||||
score: [{ type: SearchScoreTypeEnum.embedding, value: data.score, index }]
|
||||
};
|
||||
|
||||
return result;
|
||||
})
|
||||
.filter((item) => item !== null) as SearchDataResponseItemType[];
|
||||
return result;
|
||||
});
|
||||
|
||||
return {
|
||||
embeddingRecallResults: formatResult,
|
||||
|
@@ -45,6 +45,7 @@ import { DispatchNodeResponseKeyEnum } from '@fastgpt/global/core/workflow/runti
|
||||
import { getHistories } from '../utils';
|
||||
import { filterSearchResultsByMaxChars } from '../../utils';
|
||||
import { getHistoryPreview } from '@fastgpt/global/core/chat/utils';
|
||||
import { addLog } from '../../../../common/system/log';
|
||||
|
||||
export type ChatProps = ModuleDispatchProps<
|
||||
AIChatNodeProps & {
|
||||
@@ -167,21 +168,19 @@ export const dispatchChatCompletion = async (props: ChatProps): Promise<ChatResp
|
||||
})
|
||||
);
|
||||
|
||||
const response = await ai.chat.completions.create(
|
||||
{
|
||||
...modelConstantsData?.defaultConfig,
|
||||
model: modelConstantsData.model,
|
||||
temperature,
|
||||
max_tokens,
|
||||
stream,
|
||||
messages: loadMessages
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
Accept: 'application/json, text/plain, */*'
|
||||
}
|
||||
const requestBody = {
|
||||
...modelConstantsData?.defaultConfig,
|
||||
model: modelConstantsData.model,
|
||||
temperature,
|
||||
max_tokens,
|
||||
stream,
|
||||
messages: loadMessages
|
||||
};
|
||||
const response = await ai.chat.completions.create(requestBody, {
|
||||
headers: {
|
||||
Accept: 'application/json, text/plain, */*'
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
const { answerText } = await (async () => {
|
||||
if (res && stream) {
|
||||
@@ -189,7 +188,8 @@ export const dispatchChatCompletion = async (props: ChatProps): Promise<ChatResp
|
||||
const { answer } = await streamResponse({
|
||||
res,
|
||||
detail,
|
||||
stream: response
|
||||
stream: response,
|
||||
requestBody
|
||||
});
|
||||
|
||||
return {
|
||||
@@ -349,11 +349,13 @@ async function getMaxTokens({
|
||||
async function streamResponse({
|
||||
res,
|
||||
detail,
|
||||
stream
|
||||
stream,
|
||||
requestBody
|
||||
}: {
|
||||
res: NextApiResponse;
|
||||
detail: boolean;
|
||||
stream: StreamChatType;
|
||||
requestBody: Record<string, any>;
|
||||
}) {
|
||||
const write = responseWriteController({
|
||||
res,
|
||||
@@ -378,6 +380,7 @@ async function streamResponse({
|
||||
}
|
||||
|
||||
if (!answer) {
|
||||
addLog.info(`LLM model response empty`, requestBody);
|
||||
return Promise.reject('core.chat.Chat API is error or undefined');
|
||||
}
|
||||
|
||||
|
@@ -25,7 +25,10 @@ export const dispatchRunCode = async (props: RunCodeType): Promise<RunCodeRespon
|
||||
try {
|
||||
const { data: runResult } = await axios.post<{
|
||||
success: boolean;
|
||||
data: Record<string, any>;
|
||||
data: {
|
||||
codeReturn: Record<string, any>;
|
||||
log: string;
|
||||
};
|
||||
}>(sandBoxRequestUrl, {
|
||||
code,
|
||||
variables: customVariables
|
||||
@@ -33,10 +36,11 @@ export const dispatchRunCode = async (props: RunCodeType): Promise<RunCodeRespon
|
||||
|
||||
if (runResult.success) {
|
||||
return {
|
||||
[NodeOutputKeyEnum.rawResponse]: runResult.data,
|
||||
[NodeOutputKeyEnum.rawResponse]: runResult.data.codeReturn,
|
||||
[DispatchNodeResponseKeyEnum.nodeResponse]: {
|
||||
customInputs: customVariables,
|
||||
customOutputs: runResult.data
|
||||
customOutputs: runResult.data.codeReturn,
|
||||
codeLog: runResult.data.log
|
||||
},
|
||||
...runResult.data
|
||||
};
|
||||
|
@@ -13,6 +13,7 @@ import {
|
||||
import { ModuleDispatchProps } from '@fastgpt/global/core/workflow/type';
|
||||
import { getElseIFLabel, getHandleId } from '@fastgpt/global/core/workflow/utils';
|
||||
import { getReferenceVariableValue } from '@fastgpt/global/core/workflow/runtime/utils';
|
||||
import { replaceRegChars } from '@fastgpt/global/common/string/tools';
|
||||
|
||||
type Props = ModuleDispatchProps<{
|
||||
[NodeInputKeyEnum.condition]: IfElseConditionType;
|
||||
@@ -48,39 +49,52 @@ function isInclude(value: any, target: any) {
|
||||
}
|
||||
}
|
||||
|
||||
function checkCondition(condition: VariableConditionEnum, variableValue: any, value: string) {
|
||||
const operations = {
|
||||
[VariableConditionEnum.isEmpty]: () => isEmpty(variableValue),
|
||||
[VariableConditionEnum.isNotEmpty]: () => !isEmpty(variableValue),
|
||||
function checkCondition(condition: VariableConditionEnum, inputValue: any, value: string) {
|
||||
const operations: Record<VariableConditionEnum, () => boolean> = {
|
||||
[VariableConditionEnum.isEmpty]: () => isEmpty(inputValue),
|
||||
[VariableConditionEnum.isNotEmpty]: () => !isEmpty(inputValue),
|
||||
|
||||
[VariableConditionEnum.equalTo]: () => String(variableValue) === value,
|
||||
[VariableConditionEnum.notEqual]: () => String(variableValue) !== value,
|
||||
[VariableConditionEnum.equalTo]: () => String(inputValue) === value,
|
||||
[VariableConditionEnum.notEqual]: () => String(inputValue) !== value,
|
||||
|
||||
// number
|
||||
[VariableConditionEnum.greaterThan]: () => Number(variableValue) > Number(value),
|
||||
[VariableConditionEnum.lessThan]: () => Number(variableValue) < Number(value),
|
||||
[VariableConditionEnum.greaterThanOrEqualTo]: () => Number(variableValue) >= Number(value),
|
||||
[VariableConditionEnum.lessThanOrEqualTo]: () => Number(variableValue) <= Number(value),
|
||||
[VariableConditionEnum.greaterThan]: () => Number(inputValue) > Number(value),
|
||||
[VariableConditionEnum.lessThan]: () => Number(inputValue) < Number(value),
|
||||
[VariableConditionEnum.greaterThanOrEqualTo]: () => Number(inputValue) >= Number(value),
|
||||
[VariableConditionEnum.lessThanOrEqualTo]: () => Number(inputValue) <= Number(value),
|
||||
|
||||
// array or string
|
||||
[VariableConditionEnum.include]: () => isInclude(variableValue, value),
|
||||
[VariableConditionEnum.notInclude]: () => !isInclude(variableValue, value),
|
||||
[VariableConditionEnum.include]: () => isInclude(inputValue, value),
|
||||
[VariableConditionEnum.notInclude]: () => !isInclude(inputValue, value),
|
||||
|
||||
// string
|
||||
[VariableConditionEnum.startWith]: () => variableValue?.startsWith(value),
|
||||
[VariableConditionEnum.endWith]: () => variableValue?.endsWith(value),
|
||||
[VariableConditionEnum.startWith]: () => inputValue?.startsWith(value),
|
||||
[VariableConditionEnum.endWith]: () => inputValue?.endsWith(value),
|
||||
[VariableConditionEnum.reg]: () => {
|
||||
if (typeof inputValue !== 'string' || !value) return false;
|
||||
if (value.startsWith('/')) {
|
||||
value = value.slice(1);
|
||||
}
|
||||
if (value.endsWith('/')) {
|
||||
value = value.slice(0, -1);
|
||||
}
|
||||
|
||||
const reg = new RegExp(value, 'g');
|
||||
const result = reg.test(inputValue);
|
||||
|
||||
return result;
|
||||
},
|
||||
|
||||
// array
|
||||
[VariableConditionEnum.lengthEqualTo]: () => variableValue?.length === Number(value),
|
||||
[VariableConditionEnum.lengthNotEqualTo]: () => variableValue?.length !== Number(value),
|
||||
[VariableConditionEnum.lengthGreaterThan]: () => variableValue?.length > Number(value),
|
||||
[VariableConditionEnum.lengthGreaterThanOrEqualTo]: () =>
|
||||
variableValue?.length >= Number(value),
|
||||
[VariableConditionEnum.lengthLessThan]: () => variableValue?.length < Number(value),
|
||||
[VariableConditionEnum.lengthLessThanOrEqualTo]: () => variableValue?.length <= Number(value)
|
||||
[VariableConditionEnum.lengthEqualTo]: () => inputValue?.length === Number(value),
|
||||
[VariableConditionEnum.lengthNotEqualTo]: () => inputValue?.length !== Number(value),
|
||||
[VariableConditionEnum.lengthGreaterThan]: () => inputValue?.length > Number(value),
|
||||
[VariableConditionEnum.lengthGreaterThanOrEqualTo]: () => inputValue?.length >= Number(value),
|
||||
[VariableConditionEnum.lengthLessThan]: () => inputValue?.length < Number(value),
|
||||
[VariableConditionEnum.lengthLessThanOrEqualTo]: () => inputValue?.length <= Number(value)
|
||||
};
|
||||
|
||||
return (operations[condition] || (() => false))();
|
||||
return operations[condition]?.() ?? false;
|
||||
}
|
||||
|
||||
function getResult(
|
||||
@@ -92,13 +106,13 @@ function getResult(
|
||||
const listResult = list.map((item) => {
|
||||
const { variable, condition: variableCondition, value } = item;
|
||||
|
||||
const variableValue = getReferenceVariableValue({
|
||||
const inputValue = getReferenceVariableValue({
|
||||
value: variable,
|
||||
variables,
|
||||
nodes: runtimeNodes
|
||||
});
|
||||
|
||||
return checkCondition(variableCondition as VariableConditionEnum, variableValue, value || '');
|
||||
return checkCondition(variableCondition as VariableConditionEnum, inputValue, value || '');
|
||||
});
|
||||
|
||||
return condition === 'AND' ? listResult.every(Boolean) : listResult.some(Boolean);
|
||||
|
@@ -16,7 +16,7 @@ type Props = ModuleDispatchProps<{
|
||||
type Response = DispatchNodeResultType<{}>;
|
||||
|
||||
export const dispatchUpdateVariable = async (props: Props): Promise<Response> => {
|
||||
const { res, detail, params, variables, runtimeNodes } = props;
|
||||
const { res, detail, stream, params, variables, runtimeNodes } = props;
|
||||
|
||||
const { updateList } = params;
|
||||
updateList.forEach((item) => {
|
||||
@@ -54,7 +54,7 @@ export const dispatchUpdateVariable = async (props: Props): Promise<Response> =>
|
||||
}
|
||||
});
|
||||
|
||||
if (detail) {
|
||||
if (detail && stream) {
|
||||
responseWrite({
|
||||
res,
|
||||
event: SseResponseEventEnum.updateVariables,
|
||||
|
@@ -1,3 +1,5 @@
|
||||
import { getErrText } from '@fastgpt/global/common/error/utils';
|
||||
import { replaceSensitiveText } from '@fastgpt/global/common/string/tools';
|
||||
import type { ChatItemType } from '@fastgpt/global/core/chat/type.d';
|
||||
import {
|
||||
WorkflowIOValueTypeEnum,
|
||||
@@ -89,11 +91,10 @@ export const removeSystemVariable = (variables: Record<string, any>) => {
|
||||
|
||||
export const formatHttpError = (error: any) => {
|
||||
return {
|
||||
message: error?.message,
|
||||
message: getErrText(error),
|
||||
data: error?.response?.data,
|
||||
name: error?.name,
|
||||
method: error?.config?.method,
|
||||
baseURL: error?.config?.baseURL,
|
||||
url: error?.config?.url,
|
||||
code: error?.code,
|
||||
status: error?.status
|
||||
};
|
||||
|
Reference in New Issue
Block a user