diff --git a/packages/data-provider/src/actions.ts b/packages/data-provider/src/actions.ts index 386ca34e74f..54fe2327a5e 100644 --- a/packages/data-provider/src/actions.ts +++ b/packages/data-provider/src/actions.ts @@ -11,6 +11,7 @@ export type ParametersSchema = { type: string; properties: Record; required: string[]; + additionalProperties?: boolean; }; export type OpenAPISchema = OpenAPIV3.SchemaObject & @@ -122,24 +123,33 @@ export class FunctionSignature { name: string; description: string; parameters: ParametersSchema; + strict: boolean; - constructor(name: string, description: string, parameters: ParametersSchema) { + constructor(name: string, description: string, parameters: ParametersSchema, strict?: boolean) { this.name = name; this.description = description; this.parameters = parameters; + this.strict = strict ?? false; } toObjectTool(): FunctionTool { + const parameters = { + ...this.parameters, + additionalProperties: this.strict ? false : undefined, + }; + return { type: Tools.function, function: { name: this.name, description: this.description, - parameters: this.parameters, + parameters, + strict: this.strict, }, }; } } + class RequestConfig { constructor( readonly domain: string, @@ -366,12 +376,15 @@ export function openapiToFunction( for (const [method, operation] of Object.entries(methods as OpenAPIV3.PathsObject)) { const operationObj = operation as OpenAPIV3.OperationObject & { 'x-openai-isConsequential'?: boolean; + } & { + 'x-strict'?: boolean }; // Operation ID is used as the function name const defaultOperationId = `${method}_${path}`; const operationId = operationObj.operationId || sanitizeOperationId(defaultOperationId); const description = operationObj.summary || operationObj.description || ''; + const isStrict = operationObj['x-strict'] ?? false; const parametersSchema: OpenAPISchema = { type: 'object', @@ -411,7 +424,7 @@ export function openapiToFunction( } } - const functionSignature = new FunctionSignature(operationId, description, parametersSchema); + const functionSignature = new FunctionSignature(operationId, description, parametersSchema, isStrict); functionSignatures.push(functionSignature); const actionRequest = new ActionRequest( diff --git a/packages/data-provider/src/types/assistants.ts b/packages/data-provider/src/types/assistants.ts index 6e21c0b5b27..8110665a2ff 100644 --- a/packages/data-provider/src/types/assistants.ts +++ b/packages/data-provider/src/types/assistants.ts @@ -38,6 +38,8 @@ export type FunctionTool = { description: string; name: string; parameters: Record; + strict?: boolean; + additionalProperties?: boolean; // must be false if strict is true https://platform.openai.com/docs/guides/structured-outputs/some-type-specific-keywords-are-not-yet-supported }; };