mirror of
https://github.com/labring/FastGPT.git
synced 2025-12-25 20:02:47 +00:00
fix: value type (#6076)
Some checks failed
Build FastGPT images in Personal warehouse / get-vars (push) Has been cancelled
Build FastGPT images in Personal warehouse / build-fastgpt-images (map[arch:amd64 runs-on:ubuntu-24.04]) (push) Has been cancelled
Build FastGPT images in Personal warehouse / build-fastgpt-images (map[arch:arm64 runs-on:ubuntu-24.04-arm]) (push) Has been cancelled
Build FastGPT images in Personal warehouse / release-fastgpt-images (push) Has been cancelled
Some checks failed
Build FastGPT images in Personal warehouse / get-vars (push) Has been cancelled
Build FastGPT images in Personal warehouse / build-fastgpt-images (map[arch:amd64 runs-on:ubuntu-24.04]) (push) Has been cancelled
Build FastGPT images in Personal warehouse / build-fastgpt-images (map[arch:arm64 runs-on:ubuntu-24.04-arm]) (push) Has been cancelled
Build FastGPT images in Personal warehouse / release-fastgpt-images (push) Has been cancelled
* fix: value type * perf: empty val check
This commit is contained in:
parent
2da73a6555
commit
eaeabf825a
|
|
@ -67,25 +67,8 @@ export const valueTypeFormat = (value: any, valueType?: WorkflowIOValueTypeEnum)
|
||||||
};
|
};
|
||||||
|
|
||||||
// Handle null/undefined, return default value by type
|
// Handle null/undefined, return default value by type
|
||||||
if (value === undefined || value === null) {
|
if (value === undefined || value === null) return value;
|
||||||
if (!valueType || valueType === WorkflowIOValueTypeEnum.any) return value;
|
if (!valueType || valueType === WorkflowIOValueTypeEnum.any) return value;
|
||||||
|
|
||||||
// Default value map (use function to ensure new reference each time)
|
|
||||||
const defaultValueMap: Partial<Record<WorkflowIOValueTypeEnum, () => any>> = {
|
|
||||||
[WorkflowIOValueTypeEnum.string]: () => '',
|
|
||||||
[WorkflowIOValueTypeEnum.number]: () => 0,
|
|
||||||
[WorkflowIOValueTypeEnum.boolean]: () => false,
|
|
||||||
[WorkflowIOValueTypeEnum.arrayString]: () => [],
|
|
||||||
[WorkflowIOValueTypeEnum.arrayNumber]: () => [],
|
|
||||||
[WorkflowIOValueTypeEnum.arrayBoolean]: () => [],
|
|
||||||
[WorkflowIOValueTypeEnum.arrayObject]: () => [],
|
|
||||||
[WorkflowIOValueTypeEnum.arrayAny]: () => [],
|
|
||||||
[WorkflowIOValueTypeEnum.object]: () => ({})
|
|
||||||
};
|
|
||||||
|
|
||||||
const getDefaultValue = defaultValueMap[valueType];
|
|
||||||
return getDefaultValue ? getDefaultValue() : value;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Password check
|
// Password check
|
||||||
if (valueType === WorkflowIOValueTypeEnum.string && isSecretValue(value)) return value;
|
if (valueType === WorkflowIOValueTypeEnum.string && isSecretValue(value)) return value;
|
||||||
|
|
|
||||||
|
|
@ -537,7 +537,7 @@ const llmCompletionsBodyFormat = async <T extends CompletionsBodyType>({
|
||||||
: undefined,
|
: undefined,
|
||||||
...modelData?.defaultConfig,
|
...modelData?.defaultConfig,
|
||||||
response_format,
|
response_format,
|
||||||
stop: stop?.split('|'),
|
stop: stop?.split('|').filter((item) => !!item.trim()),
|
||||||
...(toolCallMode === 'toolChoice' && {
|
...(toolCallMode === 'toolChoice' && {
|
||||||
tools,
|
tools,
|
||||||
tool_choice,
|
tool_choice,
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@ export const computedMaxToken = ({
|
||||||
if (maxToken === undefined) return;
|
if (maxToken === undefined) return;
|
||||||
|
|
||||||
maxToken = Math.min(maxToken, model.maxResponse);
|
maxToken = Math.min(maxToken, model.maxResponse);
|
||||||
return Math.max(maxToken, min || 0);
|
return Math.max(maxToken, min || 1);
|
||||||
};
|
};
|
||||||
|
|
||||||
// FastGPT temperature range: [0,10], ai temperature:[0,2],{0,1]……
|
// FastGPT temperature range: [0,10], ai temperature:[0,2],{0,1]……
|
||||||
|
|
|
||||||
|
|
@ -62,14 +62,13 @@ const UNDEFINED_SIGN = 'UNDEFINED_SIGN';
|
||||||
|
|
||||||
export const dispatchHttp468Request = async (props: HttpRequestProps): Promise<HttpResponse> => {
|
export const dispatchHttp468Request = async (props: HttpRequestProps): Promise<HttpResponse> => {
|
||||||
let {
|
let {
|
||||||
runningAppInfo: { id: appId, teamId, tmbId },
|
runningAppInfo: { id: appId },
|
||||||
chatId,
|
chatId,
|
||||||
responseChatItemId,
|
responseChatItemId,
|
||||||
variables,
|
variables,
|
||||||
node,
|
node,
|
||||||
runtimeNodes,
|
runtimeNodes,
|
||||||
histories,
|
histories,
|
||||||
workflowStreamResponse,
|
|
||||||
params: {
|
params: {
|
||||||
system_httpMethod: httpMethod = 'POST',
|
system_httpMethod: httpMethod = 'POST',
|
||||||
system_httpReqUrl: httpReqUrl,
|
system_httpReqUrl: httpReqUrl,
|
||||||
|
|
@ -332,8 +331,10 @@ export const replaceJsonBodyString = (
|
||||||
};
|
};
|
||||||
|
|
||||||
const valToStr = (val: any, isQuoted = false) => {
|
const valToStr = (val: any, isQuoted = false) => {
|
||||||
if (val === undefined) return 'null';
|
if (val === undefined || val === null) {
|
||||||
if (val === null) return 'null';
|
if (isQuoted) return '';
|
||||||
|
return 'null';
|
||||||
|
}
|
||||||
|
|
||||||
if (typeof val === 'object') {
|
if (typeof val === 'object') {
|
||||||
const jsonStr = JSON.stringify(val);
|
const jsonStr = JSON.stringify(val);
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,8 @@ describe('replaceJsonBodyString', () => {
|
||||||
] as unknown as RuntimeNodeItemType[];
|
] as unknown as RuntimeNodeItemType[];
|
||||||
|
|
||||||
const mockVariables = {
|
const mockVariables = {
|
||||||
|
undefinedVar: undefined,
|
||||||
|
nullVar: null,
|
||||||
userName: 'John Doe',
|
userName: 'John Doe',
|
||||||
userAge: 30,
|
userAge: 30,
|
||||||
isActive: true,
|
isActive: true,
|
||||||
|
|
@ -43,6 +45,14 @@ describe('replaceJsonBodyString', () => {
|
||||||
};
|
};
|
||||||
|
|
||||||
describe('Basic variable replacement functionality', () => {
|
describe('Basic variable replacement functionality', () => {
|
||||||
|
it('字符串为空', () => {
|
||||||
|
const input = '{"name": "{{undefinedVar}}"}';
|
||||||
|
const expected = '{"name": ""}';
|
||||||
|
|
||||||
|
const result = replaceJsonBodyString({ text: input }, mockProps);
|
||||||
|
expect(result).toBe(expected);
|
||||||
|
});
|
||||||
|
|
||||||
it('should correctly replace string variables', () => {
|
it('should correctly replace string variables', () => {
|
||||||
const input = '{"name": "{{userName}}", "greeting": "Hello {{userName}}"}';
|
const input = '{"name": "{{userName}}", "greeting": "Hello {{userName}}"}';
|
||||||
const expected = '{"name": "John Doe", "greeting": "Hello John Doe"}';
|
const expected = '{"name": "John Doe", "greeting": "Hello John Doe"}';
|
||||||
|
|
@ -241,7 +251,7 @@ describe('replaceJsonBodyString', () => {
|
||||||
|
|
||||||
it('should handle non-existent variables', () => {
|
it('should handle non-existent variables', () => {
|
||||||
const input = '{"missing": "{{nonExistentVar}}", "static": "value"}';
|
const input = '{"missing": "{{nonExistentVar}}", "static": "value"}';
|
||||||
const expected = '{"missing": "null", "static": "value"}';
|
const expected = '{"missing": "", "static": "value"}';
|
||||||
|
|
||||||
const result = replaceJsonBodyString({ text: input }, mockProps);
|
const result = replaceJsonBodyString({ text: input }, mockProps);
|
||||||
expect(result).toBe(expected);
|
expect(result).toBe(expected);
|
||||||
|
|
@ -626,7 +636,7 @@ describe('replaceJsonBodyString', () => {
|
||||||
|
|
||||||
// Verify no code execution occurred (template injection variable was replaced with null because it doesn't exist)
|
// Verify no code execution occurred (template injection variable was replaced with null because it doesn't exist)
|
||||||
expect(typeof parsed.templateTests.inject).toBe('string');
|
expect(typeof parsed.templateTests.inject).toBe('string');
|
||||||
expect(parsed.templateTests.inject).toBe('null'); // Non-existent variables become "null"
|
expect(parsed.templateTests.inject).toBe(''); // Non-existent variables become "null"
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -311,109 +311,3 @@ describe('valueTypeFormat', () => {
|
||||||
// });
|
// });
|
||||||
// });
|
// });
|
||||||
});
|
});
|
||||||
|
|
||||||
import { getHistories } from '@fastgpt/service/core/workflow/dispatch/utils';
|
|
||||||
import { ChatItemValueTypeEnum, ChatRoleEnum } from '@fastgpt/global/core/chat/constants';
|
|
||||||
import type { ChatItemType } from '@fastgpt/global/core/chat/type';
|
|
||||||
|
|
||||||
describe('getHistories test', async () => {
|
|
||||||
const MockHistories: ChatItemType[] = [
|
|
||||||
{
|
|
||||||
obj: ChatRoleEnum.System,
|
|
||||||
value: [
|
|
||||||
{
|
|
||||||
type: ChatItemValueTypeEnum.text,
|
|
||||||
text: {
|
|
||||||
content: '你好'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
obj: ChatRoleEnum.Human,
|
|
||||||
value: [
|
|
||||||
{
|
|
||||||
type: ChatItemValueTypeEnum.text,
|
|
||||||
text: {
|
|
||||||
content: '你好'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
obj: ChatRoleEnum.AI,
|
|
||||||
value: [
|
|
||||||
{
|
|
||||||
type: ChatItemValueTypeEnum.text,
|
|
||||||
text: {
|
|
||||||
content: '你好2'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
obj: ChatRoleEnum.Human,
|
|
||||||
value: [
|
|
||||||
{
|
|
||||||
type: ChatItemValueTypeEnum.text,
|
|
||||||
text: {
|
|
||||||
content: '你好3'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
obj: ChatRoleEnum.AI,
|
|
||||||
value: [
|
|
||||||
{
|
|
||||||
type: ChatItemValueTypeEnum.text,
|
|
||||||
text: {
|
|
||||||
content: '你好4'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
];
|
|
||||||
|
|
||||||
it('getHistories', async () => {
|
|
||||||
// Number
|
|
||||||
expect(getHistories(1, MockHistories)).toEqual([
|
|
||||||
...MockHistories.slice(0, 1),
|
|
||||||
...MockHistories.slice(-2)
|
|
||||||
]);
|
|
||||||
expect(getHistories(2, MockHistories)).toEqual([...MockHistories.slice(0)]);
|
|
||||||
expect(getHistories(4, MockHistories)).toEqual([...MockHistories.slice(0)]);
|
|
||||||
|
|
||||||
// Array
|
|
||||||
expect(
|
|
||||||
getHistories(
|
|
||||||
[
|
|
||||||
{
|
|
||||||
obj: ChatRoleEnum.Human,
|
|
||||||
value: [
|
|
||||||
{
|
|
||||||
type: ChatItemValueTypeEnum.text,
|
|
||||||
text: {
|
|
||||||
content: '你好'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
],
|
|
||||||
MockHistories
|
|
||||||
)
|
|
||||||
).toEqual([
|
|
||||||
{
|
|
||||||
obj: ChatRoleEnum.Human,
|
|
||||||
value: [
|
|
||||||
{
|
|
||||||
type: ChatItemValueTypeEnum.text,
|
|
||||||
text: {
|
|
||||||
content: '你好'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
]);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue