feat: add tool params node & tool params add array type (#2824)

* add tool params node

* add tool params enum

* node response

* tool add array type params

* fix tool params

* fix

* fix

* fix
This commit is contained in:
heheer
2024-09-28 15:58:55 +08:00
committed by GitHub
parent f2749cbb00
commit 1599d144ce
26 changed files with 438 additions and 28 deletions

View File

@@ -60,12 +60,16 @@ export const runToolWithFunctionCall = async (
type: string;
description: string;
required?: boolean;
enum?: string[];
}
> = {};
item.toolParams.forEach((item) => {
const isArray = item.valueType?.startsWith('array');
properties[item.key] = {
type: item.valueType || 'string',
description: item.toolDescription || ''
type: isArray ? 'array' : item.valueType || 'string',
...(isArray && { items: { type: item.valueType?.slice(5).toLowerCase() || 'string' } }),
description: item.toolDescription || '',
enum: item.enum?.split('\n').filter(Boolean) || []
};
});

View File

@@ -68,12 +68,16 @@ export const runToolWithPromptCall = async (
type: string;
description: string;
required?: boolean;
enum?: string[];
}
> = {};
item.toolParams.forEach((item) => {
const isArray = item.valueType?.startsWith('array');
properties[item.key] = {
type: 'string',
description: item.toolDescription || ''
type: isArray ? 'array' : item.valueType || 'string',
...(isArray && { items: { type: item.valueType?.slice(5).toLowerCase() || 'string' } }),
description: item.toolDescription || '',
enum: item.enum?.split('\n').filter(Boolean) || []
};
});

View File

@@ -70,13 +70,20 @@ export const runToolWithToolChoice = async (
{
type: string;
description: string;
enum?: string[];
required?: boolean;
items?: {
type: string;
};
}
> = {};
item.toolParams.forEach((item) => {
const isArray = item.valueType?.startsWith('array');
properties[item.key] = {
type: item.valueType || 'string',
description: item.toolDescription || ''
type: isArray ? 'array' : item.valueType || 'string',
...(isArray && { items: { type: item.valueType?.slice(5).toLowerCase() || 'string' } }),
description: item.toolDescription || '',
enum: item.enum?.split('\n').filter(Boolean) || []
};
});
@@ -138,7 +145,6 @@ export const runToolWithToolChoice = async (
toolModel
);
// console.log(JSON.stringify(requestBody, null, 2));
/* Run llm */
const ai = getAIApi({
timeout: 480000

View File

@@ -0,0 +1,17 @@
import { DispatchNodeResponseKeyEnum } from '@fastgpt/global/core/workflow/runtime/constants';
import type { ModuleDispatchProps } from '@fastgpt/global/core/workflow/runtime/type';
import { DispatchNodeResultType } from '@fastgpt/global/core/workflow/runtime/type';
export type Props = ModuleDispatchProps<{}>;
export type Response = DispatchNodeResultType<{}>;
export const dispatchToolParams = (props: Props): Response => {
const { params } = props;
return {
...params,
[DispatchNodeResponseKeyEnum.nodeResponse]: {
toolParamsResult: params
}
};
};

View File

@@ -70,6 +70,7 @@ import { dispatchLoop } from './loop/runLoop';
import { dispatchLoopEnd } from './loop/runLoopEnd';
import { dispatchLoopStart } from './loop/runLoopStart';
import { dispatchFormInput } from './interactive/formInput';
import { dispatchToolParams } from './agent/runTool/toolParams';
const callbackMap: Record<FlowNodeTypeEnum, Function> = {
[FlowNodeTypeEnum.workflowStart]: dispatchWorkflowStart,
@@ -87,6 +88,7 @@ const callbackMap: Record<FlowNodeTypeEnum, Function> = {
[FlowNodeTypeEnum.queryExtension]: dispatchQueryExtension,
[FlowNodeTypeEnum.tools]: dispatchRunTools,
[FlowNodeTypeEnum.stopTool]: dispatchStopToolCall,
[FlowNodeTypeEnum.toolParams]: dispatchToolParams,
[FlowNodeTypeEnum.lafModule]: dispatchLafRequest,
[FlowNodeTypeEnum.ifElseNode]: dispatchIfElse,
[FlowNodeTypeEnum.variableUpdate]: dispatchUpdateVariable,