symposium 0.13.8 → 0.14.0

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
@@ -88,6 +88,17 @@ export default class Agent {
88
88
  this.callbacks[i + '-' + thread.id].push(callback);
89
89
  }
90
90
 
91
+ const model = Symposium.getModelByName(thread.state.model);
92
+ if (!model.supports_audio) {
93
+ for (let c of content) {
94
+ if (c.type === 'audio' && !c.content?.transcription) {
95
+ const words = await this.getPromptWordsForTranscription(thread);
96
+ const prompt = words.length ? 'Possibili parole usate: ' + words.join(', ') : null;
97
+ c.content.transcription = await Symposium.transcribe(c.content, prompt);
98
+ }
99
+ }
100
+ }
101
+
91
102
  await this.log('user_message', content);
92
103
  thread.addMessage('user', content);
93
104
 
@@ -205,19 +216,6 @@ export default class Agent {
205
216
  async generateCompletion(thread, options = {}, retry_counter = 1) {
206
217
  try {
207
218
  const model = Symposium.getModelByName(thread.state.model);
208
-
209
- for (let message of thread.messages) {
210
- for (let c of message.content) {
211
- if (c.type === 'audio' && !model.supports_audio) {
212
- const words = await this.getPromptWordsForTranscription(thread);
213
- const prompt = words.length ? 'Possibili parole usate: ' + words.join(', ') : null;
214
- const transcribed = await Symposium.transcribe(c.content, prompt);
215
- c.type = 'text';
216
- c.content = '[voice message] ' + transcribed;
217
- }
218
- }
219
- }
220
-
221
219
  const messages = await model.generate(thread, await this.getFunctions(), options);
222
220
  return model.supports_functions ? messages : messages.map(m => this.parseFunctions(m));
223
221
  } catch (error) {
package/Symposium.js CHANGED
@@ -85,17 +85,17 @@ export default class Symposium {
85
85
  let file;
86
86
  switch (audio.type) {
87
87
  case 'url':
88
- if (!audio.url)
88
+ if (!audio.data)
89
89
  throw new Error('Audio URL is required');
90
90
 
91
- if (audio.url.startsWith('/')) { // Local path
91
+ if (audio.data.startsWith('/')) { // Local path
92
92
  // Get with fs
93
- if (!fs.existsSync(audio.url))
94
- throw new Error('Audio file does not exist at the specified path: ' + audio.url);
93
+ if (!fs.existsSync(audio.data))
94
+ throw new Error('Audio file does not exist at the specified path: ' + audio.data);
95
95
 
96
- file = fs.readFileSync(audio.url);
96
+ file = fs.readFileSync(audio.data);
97
97
  } else {
98
- file = await fetch(audio.url).then(res => res.blob());
98
+ file = await fetch(audio.data).then(res => res.blob());
99
99
  }
100
100
 
101
101
  file = new File([file], 'audio.' + this.getExtFromMime(file.type), {type: file.type});
@@ -148,6 +148,17 @@ export default class AnthropicModel extends Model {
148
148
  }
149
149
  break;
150
150
 
151
+ case 'audio':
152
+ if (c.content.transcription) {
153
+ content.push({
154
+ type: 'text',
155
+ text: '[transcribed] ' + c.content.transcription,
156
+ });
157
+ } else {
158
+ throw new Error('Audio content is not supported by this model');
159
+ }
160
+ break;
161
+
151
162
  default:
152
163
  throw new Error('Message type "' + c.type + '" unsupported by this model');
153
164
  }
@@ -158,6 +158,19 @@ export default class GroqModel extends Model {
158
158
  }
159
159
  break;
160
160
 
161
+
162
+ case 'audio':
163
+ if (c.content.transcription) {
164
+ messages.push({
165
+ role: message.role,
166
+ content: '[transcribed] ' + c.content.transcription,
167
+ name: message.name,
168
+ });
169
+ } else {
170
+ throw new Error('Audio content is not supported by this model');
171
+ }
172
+ break;
173
+
161
174
  default:
162
175
  throw new Error('Message type unsupported by this model');
163
176
  }
@@ -140,24 +140,34 @@ export default class OpenAIModel extends Model {
140
140
  break;
141
141
 
142
142
  case 'audio':
143
- if (c.content.type !== 'base64')
144
- throw new Error('Audio content must be base64 encoded for this model');
145
- if (!['audio/mpeg', 'audio/wav'].includes(c.content.mime))
146
- throw new Error('Audio content must have a valid MIME type');
143
+ if (this.supports_audio) {
144
+ if (c.content.type !== 'base64')
145
+ throw new Error('Audio content must be base64 encoded for this model');
146
+ if (!['audio/mpeg', 'audio/wav'].includes(c.content.mime))
147
+ throw new Error('Audio content must have a valid MIME type');
147
148
 
148
- messages.push({
149
- role,
150
- content: [
151
- {
152
- type: 'input_audio',
153
- input_audio: {
154
- data: c.content.data,
155
- format: c.content.mime === 'audio/mpeg' ? 'mp3' : 'wav',
149
+ messages.push({
150
+ role,
151
+ content: [
152
+ {
153
+ type: 'input_audio',
154
+ input_audio: {
155
+ data: c.content.data,
156
+ format: c.content.mime === 'audio/mpeg' ? 'mp3' : 'wav',
157
+ },
156
158
  },
157
- },
158
- ],
159
- name: message.name,
160
- });
159
+ ],
160
+ name: message.name,
161
+ });
162
+ } else if (c.content.transcription) {
163
+ messages.push({
164
+ role,
165
+ content: '[transcribed] ' + c.content.transcription,
166
+ name: message.name,
167
+ });
168
+ } else{
169
+ throw new Error('Audio content is not supported by this model');
170
+ }
161
171
  break;
162
172
 
163
173
  case 'function':
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "type": "module",
3
3
  "name": "symposium",
4
- "version": "0.13.8",
4
+ "version": "0.14.0",
5
5
  "description": "Agents",
6
6
  "main": "index.js",
7
7
  "author": "Domenico Giambra",