symposium 1.0.2 → 1.0.4

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.
Files changed (2) hide show
  1. package/Agent.js +13 -12
  2. package/package.json +1 -1
package/Agent.js CHANGED
@@ -215,16 +215,10 @@ export default class Agent {
215
215
  if (obj.type !== 'object')
216
216
  return {obj, count: 0};
217
217
 
218
- let properties_count = 0, all_required = false, required = [];
219
- if (obj.required)
220
- required = obj.required;
221
- else
222
- all_required = true;
223
-
218
+ let properties_count = 0, required = [];
224
219
  for (let [key, property] of Object.entries(obj.properties || {})) {
225
220
  properties_count++;
226
- if (all_required)
227
- required.push(key);
221
+ required.push(key); // OpenAI requires all properties to be required
228
222
 
229
223
  if (property.type === 'object') {
230
224
  const {obj: subobj, count} = this.convertFunctionToResponseFormat(property);
@@ -365,6 +359,10 @@ export default class Agent {
365
359
  return value;
366
360
  }
367
361
 
362
+ getEmitter() {
363
+ return new BufferedEventEmitter();
364
+ }
365
+
368
366
  async getFunctions(parsed = true) {
369
367
  if (this.functions === null) {
370
368
  this.functions = new Map();
@@ -388,23 +386,26 @@ export default class Agent {
388
386
  return this.functions;
389
387
  }
390
388
 
391
- async callFunction(thread, function_call, emitter) {
389
+ async callFunction(thread, function_call, emitter = null) {
392
390
  const functions = await this.getFunctions(false);
393
391
  if (!functions.has(function_call.name))
394
392
  throw new Error('Unrecognized function ' + function_call.name);
395
393
 
396
394
  const func = functions.get(function_call.name);
397
395
  const partialOutput = func.partialOutput ? ((typeof func.partialOutput) === 'text' ? func.partialOutput : func.partialOutput.call(this, function_call.arguments)) : 'Uso lo strumento ' + function_call.name + '...';
398
- emitter.emit('partial', partialOutput);
396
+ if (emitter)
397
+ emitter.emit('partial', partialOutput);
399
398
 
400
399
  await this.log('function_call', function_call);
401
400
 
402
401
  try {
403
402
  const response = await func.tool.callFunction(thread, function_call.name, function_call.arguments);
404
- emitter.emit('partial', 'Risposta ricevuta da ' + func.tool.name);
403
+ if (emitter)
404
+ emitter.emit('partial', 'Risposta ricevuta da ' + func.tool.name);
405
405
  return response;
406
406
  } catch (error) {
407
- emitter.emit('partial', 'Ricevuto errore da ' + func.tool.name);
407
+ if (emitter)
408
+ emitter.emit('partial', 'Ricevuto errore da ' + func.tool.name);
408
409
  return {error};
409
410
  }
410
411
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "type": "module",
3
3
  "name": "symposium",
4
- "version": "1.0.2",
4
+ "version": "1.0.4",
5
5
  "description": "Agents",
6
6
  "main": "index.js",
7
7
  "author": "Domenico Giambra",