fix: bad ai calls (#2144)

This commit is contained in:
Daniel Salazar
2025-12-11 17:13:25 -08:00
committed by GitHub
parent 83eab0d6ac
commit 9e2ae1c004

View File

@@ -1,3 +1,29 @@
export const 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] = normalize_json_schema(schema.properties[key]);
}
}
if ( schema.type === 'array' ) {
if ( ! schema.items ) {
schema.items = {};
} else {
schema.items = normalize_json_schema(schema.items);
}
}
return schema;
};
/**
* Normalizes the 'tools' object in-place.
*
@@ -28,7 +54,7 @@ export const normalize_tools_object = (tools) => {
};
if ( parameters.properties ) {
parameters = this.normalize_json_schema(parameters);
parameters = normalize_json_schema(parameters);
}
if ( fn.name ) {
@@ -64,31 +90,6 @@ export const normalize_tools_object = (tools) => {
return tools;
};
export const 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
* format expected by OpenAI.