symposium 0.14.5 → 0.14.7
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 +28 -7
- package/Thread.js +5 -0
- 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
|
-
//
|
|
418
|
-
const thread = new Thread('temp',
|
|
419
|
-
|
|
420
|
-
|
|
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
|
+
let system_message = '', conversation = [];
|
|
425
|
+
for (let message of thread.messages) {
|
|
426
|
+
if (message.role === 'system')
|
|
427
|
+
system_message += message.content.map(c => c.content).join("\n") + "\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.trim();
|
|
433
|
+
if (conversation.length)
|
|
434
|
+
instructions += '\n\nPrevious conversation:\n-------------------\n' + conversation.join('\n\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
|
-
|
|
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