mirror of
https://github.com/HeyPuter/puter.git
synced 2025-12-21 12:59:52 -06:00
fix: bad ai calls (#2144)
This commit is contained in:
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user