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 +11 -13
- package/Symposium.js +6 -6
- package/models/AnthropicModel.js +11 -0
- package/models/GroqModel.js +13 -0
- package/models/OpenAIModel.js +26 -16
- package/package.json +1 -1
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.
|
|
88
|
+
if (!audio.data)
|
|
89
89
|
throw new Error('Audio URL is required');
|
|
90
90
|
|
|
91
|
-
if (audio.
|
|
91
|
+
if (audio.data.startsWith('/')) { // Local path
|
|
92
92
|
// Get with fs
|
|
93
|
-
if (!fs.existsSync(audio.
|
|
94
|
-
throw new Error('Audio file does not exist at the specified path: ' + audio.
|
|
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.
|
|
96
|
+
file = fs.readFileSync(audio.data);
|
|
97
97
|
} else {
|
|
98
|
-
file = await fetch(audio.
|
|
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});
|
package/models/AnthropicModel.js
CHANGED
|
@@ -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
|
}
|
package/models/GroqModel.js
CHANGED
|
@@ -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
|
}
|
package/models/OpenAIModel.js
CHANGED
|
@@ -140,24 +140,34 @@ export default class OpenAIModel extends Model {
|
|
|
140
140
|
break;
|
|
141
141
|
|
|
142
142
|
case 'audio':
|
|
143
|
-
if (
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
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
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
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
|
-
|
|
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':
|