symposium 0.3.4 → 0.3.5

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
@@ -119,10 +119,10 @@ export default class Agent {
119
119
  }
120
120
  }
121
121
 
122
- async generateCompletion(thread, retry_counter = 1) {
122
+ async generateCompletion(thread, payload = {}, retry_counter = 1) {
123
123
  try {
124
124
  const model = Symposium.getModelByName(thread.state.model);
125
- return model.generate(thread, await this.getFunctions())
125
+ return model.generate(thread, payload, await this.getFunctions())
126
126
  } catch (error) {
127
127
  if (error.response) {
128
128
  console.error(error.response.status);
@@ -133,7 +133,7 @@ export default class Agent {
133
133
  setTimeout(resolve, 1000);
134
134
  });
135
135
 
136
- return this.generateCompletion(thread, retry_counter + 1);
136
+ return this.generateCompletion(thread, payload, retry_counter + 1);
137
137
  }
138
138
 
139
139
  await thread.reply('# Errore ' + error.response.status + ': ' + JSON.stringify(error.response.data));
@@ -206,6 +206,14 @@ export default class Agent {
206
206
  await this.execute(thread);
207
207
  }
208
208
 
209
+ async setModel(thread, label) {
210
+ const model_to_switch = Symposium.getModelByLabel(label);
211
+ if (model_to_switch && model_to_switch.type === 'llm')
212
+ await thread.setState({model: model_to_switch.name});
213
+ else
214
+ throw new Error("Versione modello non riconosciuta!\nModelli disponibili:\n" + Array.from(Symposium.models.values()).filter(m => m.type === 'llm').map(m => m.label).join("\n"));
215
+ }
216
+
209
217
  async log(type, payload) {
210
218
  if (this.options.logger)
211
219
  return this.options.logger.log(this.name, type, payload);
package/Model.js CHANGED
@@ -1,5 +1,6 @@
1
1
  export default class Model {
2
2
  vendor;
3
+ type = 'llm';
3
4
  name;
4
5
  name_for_tiktoken;
5
6
  label;
package/Symposium.js CHANGED
@@ -1,9 +1,9 @@
1
1
  import Redis from "@travio/redis";
2
- import OpenAI from "openai";
3
2
  import Gpt35 from "./models/Gpt35.js";
4
3
  import Gpt4 from "./models/Gpt4.js";
5
4
  import Gpt4Turbo from "./models/Gpt4Turbo.js";
6
5
  import Gpt4Vision from "./models/Gpt4Vision.js";
6
+ import Whisper from "./models/Whisper.js";
7
7
 
8
8
  export default class Symposium {
9
9
  static models = new Map();
@@ -13,6 +13,7 @@ export default class Symposium {
13
13
  this.loadModel(new Gpt4());
14
14
  this.loadModel(new Gpt4Turbo());
15
15
  this.loadModel(new Gpt4Vision());
16
+ this.loadModel(new Whisper());
16
17
 
17
18
  return Redis.init();
18
19
  }
@@ -22,21 +23,10 @@ export default class Symposium {
22
23
  }
23
24
 
24
25
  static getModelByName(name) {
25
- return this.models.find(model => model.name === name);
26
+ return this.models.get(name);
26
27
  }
27
28
 
28
29
  static getModelByLabel(label) {
29
- return this.models.find(model => model.label === label);
30
+ return Array.from(this.models.values()).find(model => model.label === label);
30
31
  }
31
-
32
- /*static async transcribe(agent, file, thread) {
33
- const words = await agent.getPromptWordsForTranscription(thread);
34
-
35
- const response = await this.getOpenAi().then(openai => openai.audio.transcriptions.create({
36
- file,
37
- model: 'whisper-1',
38
- prompt: words.join(', '),
39
- }));
40
- return response.text;
41
- }*/
42
32
  }
@@ -13,11 +13,12 @@ export default class OpenAIModel extends Model {
13
13
  return this.openai;
14
14
  }
15
15
 
16
- async generate(thread, functions = []) {
16
+ async generate(thread, payload = {}, functions = []) {
17
17
  const completion_payload = {
18
18
  model: this.name,
19
19
  messages: thread.getMessagesJson(),
20
20
  functions,
21
+ ...payload,
21
22
  };
22
23
 
23
24
  if (!completion_payload.functions?.length) {
@@ -0,0 +1,16 @@
1
+ import OpenAIModel from "./OpenAIModel.js";
2
+
3
+ export default class Whisper extends OpenAIModel {
4
+ type = 'stt';
5
+
6
+ async transcribe(agent, thread, file) {
7
+ const words = await agent.getPromptWordsForTranscription(thread);
8
+
9
+ const response = await this.getOpenAi().then(openai => openai.audio.transcriptions.create({
10
+ file,
11
+ model: 'whisper-1',
12
+ prompt: words.join(', '),
13
+ }));
14
+ return response.text;
15
+ }
16
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "type": "module",
3
3
  "name": "symposium",
4
- "version": "0.3.4",
4
+ "version": "0.3.5",
5
5
  "description": "Agents",
6
6
  "main": "index.js",
7
7
  "author": "Domenico Giambra",