|
@@ -20,7 +20,7 @@ module.exports = class FunctionCalling {
|
|
|
|
|
|
const normalize_function = fn => {
|
|
const normalize_function = fn => {
|
|
const normal_fn = {};
|
|
const normal_fn = {};
|
|
- const parameters =
|
|
|
|
|
|
+ let parameters =
|
|
fn.parameters ||
|
|
fn.parameters ||
|
|
fn.input_schema;
|
|
fn.input_schema;
|
|
|
|
|
|
@@ -28,6 +28,10 @@ module.exports = class FunctionCalling {
|
|
type: 'object',
|
|
type: 'object',
|
|
};
|
|
};
|
|
|
|
|
|
|
|
+ if ( parameters.properties ) {
|
|
|
|
+ parameters = this.normalize_json_schema(parameters);
|
|
|
|
+ }
|
|
|
|
+
|
|
if ( fn.name ) {
|
|
if ( fn.name ) {
|
|
normal_fn.name = fn.name;
|
|
normal_fn.name = fn.name;
|
|
}
|
|
}
|
|
@@ -61,6 +65,31 @@ module.exports = class FunctionCalling {
|
|
return tools;
|
|
return tools;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ static normalize_json_schema (schema) {
|
|
|
|
+ if ( ! schema ) return schema;
|
|
|
|
+
|
|
|
|
+ if ( schema.type === 'object' ) {
|
|
|
|
+ if ( ! schema.properties ) {
|
|
|
|
+ return schema;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ const keys = Object.keys(schema.properties);
|
|
|
|
+ for ( const key of keys ) {
|
|
|
|
+ schema.properties[key] = this.normalize_json_schema(schema.properties[key]);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if ( schema.type === 'array' ) {
|
|
|
|
+ if ( ! schema.items ) {
|
|
|
|
+ schema.items = {};
|
|
|
|
+ } else {
|
|
|
|
+ schema.items = this.normalize_json_schema(schema.items);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return schema;
|
|
|
|
+ }
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* This function will convert a normalized tools object to the
|
|
* This function will convert a normalized tools object to the
|
|
* format expected by OpenAI.
|
|
* format expected by OpenAI.
|