symposium 0.14.6 → 0.14.8

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 (3) hide show
  1. package/Agent.js +28 -7
  2. package/Thread.js +5 -0
  3. package/package.json +1 -1
package/Agent.js CHANGED
@@ -413,19 +413,32 @@ export default class Agent {
413
413
  return [this.name];
414
414
  }
415
415
 
416
- async createRealtimeSession() {
417
- // Thread fittizio
418
- const thread = new Thread('temp', 'default', this);
419
- await this.resetState(thread);
420
- await this.initThread(thread);
416
+ async createRealtimeSession(thread_id = null, interface_name = 'default') {
417
+ // Se viene passato un thread esistente, lo si usa, altrimenti si crea un nuovo thread temporaneo
418
+ const thread = new Thread(thread_id || 'temp', interface_name, this);
419
+ if (thread_id === null) {
420
+ await this.resetState(thread);
421
+ await this.initThread(thread);
422
+ }
423
+
424
+ const system_message = [], conversation = [];
425
+ for (let message of thread.messages) {
426
+ if (message.role === 'system')
427
+ system_message.push(message.content.map(c => c.content).join("\n"));
428
+ else
429
+ conversation.push('[' + message.role + '] ' + message.content.map(c => (typeof c.content === 'string' ? c.content : (c.content.transcription || null))).filter(c => !!c).join("\n"));
430
+ }
431
+
432
+ let instructions = system_message.join('\n');
433
+ if (conversation.length)
434
+ instructions += '\n\n# Ecco la tua conversazione fino ad ora: #\n' + conversation.join('\n');
421
435
 
422
- const instructions = thread.messages.filter(m => m.role === 'system').map(m => m.content.map(c => c.content).join("\n")).join("\n");
423
436
  const tools = (await this.getFunctions()).map(t => ({
424
437
  type: 'function',
425
438
  ...t,
426
439
  }));
427
440
 
428
- return fetch('https://api.openai.com/v1/realtime/sessions', {
441
+ const response = await fetch('https://api.openai.com/v1/realtime/sessions', {
429
442
  method: 'POST',
430
443
  headers: {
431
444
  "Authorization": `Bearer ${process.env.OPENAI_API_KEY}`,
@@ -437,5 +450,13 @@ export default class Agent {
437
450
  tools,
438
451
  }),
439
452
  }).then(response => response.json());
453
+
454
+ if (thread_id === null)
455
+ thread.changeId(response.client_secret.value);
456
+
457
+ return {
458
+ response,
459
+ thread,
460
+ };
440
461
  }
441
462
  }
package/Thread.js CHANGED
@@ -25,6 +25,11 @@ export default class Thread {
25
25
  return newThread;
26
26
  }
27
27
 
28
+ changeId(id) {
29
+ this.id = id;
30
+ this.unique = this.agent.name + '-' + this.interface + '-' + id;
31
+ }
32
+
28
33
  async flush() {
29
34
  this.messages = [];
30
35
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "type": "module",
3
3
  "name": "symposium",
4
- "version": "0.14.6",
4
+ "version": "0.14.8",
5
5
  "description": "Agents",
6
6
  "main": "index.js",
7
7
  "author": "Domenico Giambra",