File tree Expand file tree Collapse file tree 1 file changed +30
-1
lines changed
src/backend/src/modules/puterai/lib Expand file tree Collapse file tree 1 file changed +30
-1
lines changed Original file line number Diff line number Diff line change @@ -20,14 +20,18 @@ module.exports = class FunctionCalling {
2020
2121 const normalize_function = fn => {
2222 const normal_fn = { } ;
23- const parameters =
23+ let parameters =
2424 fn . parameters ||
2525 fn . input_schema ;
2626
2727 normal_fn . parameters = parameters ?? {
2828 type : 'object' ,
2929 } ;
3030
31+ if ( parameters . properties ) {
32+ parameters = this . normalize_json_schema ( parameters ) ;
33+ }
34+
3135 if ( fn . name ) {
3236 normal_fn . name = fn . name ;
3337 }
@@ -61,6 +65,31 @@ module.exports = class FunctionCalling {
6165 return tools ;
6266 }
6367
68+ static normalize_json_schema ( schema ) {
69+ if ( ! schema ) return schema ;
70+
71+ if ( schema . type === 'object' ) {
72+ if ( ! schema . properties ) {
73+ return schema ;
74+ }
75+
76+ const keys = Object . keys ( schema . properties ) ;
77+ for ( const key of keys ) {
78+ schema . properties [ key ] = this . normalize_json_schema ( schema . properties [ key ] ) ;
79+ }
80+ }
81+
82+ if ( schema . type === 'array' ) {
83+ if ( ! schema . items ) {
84+ schema . items = { } ;
85+ } else {
86+ schema . items = this . normalize_json_schema ( schema . items ) ;
87+ }
88+ }
89+
90+ return schema ;
91+ }
92+
6493 /**
6594 * This function will convert a normalized tools object to the
6695 * format expected by OpenAI.
You can’t perform that action at this time.
0 commit comments