symposium 0.12.5 → 0.12.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/Agent.js CHANGED
@@ -115,13 +115,16 @@ export default class Agent {
115
115
  if (!this.utility.function || !this.utility.function.name || !this.utility.function.parameters)
116
116
  throw new Error('Bad function definition');
117
117
 
118
- if (model.supports_structured_output) {
119
- // TODO: se ci sono più di 100 parametri, OpenAI non supporta gli structured output
118
+ let response_format = null;
119
+ if (model.supports_structured_output)
120
+ response_format = this.convertFunctionToResponseFormat(this.utility.function.parameters);
121
+
122
+ if (response_format && response_format.count <= 100) { // Se ci sono più di 100 parametri, OpenAI non supporta gli structured output
120
123
  completion_options.response_format = {
121
124
  type: 'json_schema',
122
125
  json_schema: {
123
126
  name: this.utility.function.name,
124
- schema: this.utility.function.parameters,
127
+ schema: response_format.obj,
125
128
  strict: true,
126
129
  },
127
130
  };
@@ -161,6 +164,40 @@ export default class Agent {
161
164
  }
162
165
  }
163
166
 
167
+ convertFunctionToResponseFormat(obj) {
168
+ if (obj.type !== 'object')
169
+ return {obj, count: 0};
170
+
171
+ let properties_count = 0, required = [];
172
+
173
+ for (let [key, property] of Object.entries(obj.properties || {})) {
174
+ properties_count++;
175
+ required.push(key);
176
+
177
+ if (property.type === 'object') {
178
+ const {obj: subobj, count} = this.convertFunctionToResponseFormat(property);
179
+ obj.properties[key] = subobj;
180
+ properties_count += count;
181
+ } else if (property.type === 'array' && property.items.type === 'object') {
182
+ const {obj: subobj, count} = this.convertFunctionToResponseFormat(property.items);
183
+ obj.properties[key] = {
184
+ type: 'array',
185
+ items: subobj,
186
+ };
187
+ properties_count += count;
188
+ }
189
+ }
190
+
191
+ return {
192
+ obj: {
193
+ ...obj,
194
+ additionalProperties: false,
195
+ required,
196
+ },
197
+ count: properties_count,
198
+ };
199
+ }
200
+
164
201
  async afterExecute(thread, completion) {
165
202
  return thread;
166
203
  }
@@ -62,6 +62,9 @@ export default class OpenAIModel extends Model {
62
62
  };
63
63
  }
64
64
 
65
+ if (options.response_format)
66
+ completion_payload.response_format = options.response_format;
67
+
65
68
  if (!completion_payload.tools.length)
66
69
  delete completion_payload.tools;
67
70
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "type": "module",
3
3
  "name": "symposium",
4
- "version": "0.12.5",
4
+ "version": "0.12.6",
5
5
  "description": "Agents",
6
6
  "main": "index.js",
7
7
  "author": "Domenico Giambra",