symposium 0.5.7 → 0.6.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
@@ -121,10 +121,10 @@ export default class Agent {
121
121
  }
122
122
  }
123
123
 
124
- async generateCompletion(thread, payload = {}, retry_counter = 1) {
124
+ async generateCompletion(thread, options = {}, retry_counter = 1) {
125
125
  try {
126
126
  const model = Symposium.getModelByName(thread.state.model);
127
- const messages = await model.generate(thread, payload, await this.getFunctions());
127
+ const messages = await model.generate(thread, await this.getFunctions(), options);
128
128
  return messages.map(m => model.supports_functions ? m : this.parseFunctions(m));
129
129
  } catch (error) {
130
130
  if (error.response) {
@@ -136,7 +136,7 @@ export default class Agent {
136
136
  setTimeout(resolve, 1000);
137
137
  });
138
138
 
139
- return this.generateCompletion(thread, payload, retry_counter + 1);
139
+ return this.generateCompletion(thread, options, retry_counter + 1);
140
140
  }
141
141
 
142
142
  await thread.reply('# Errore ' + error.response.status + ': ' + JSON.stringify(error.response.data));
package/Model.js CHANGED
@@ -10,7 +10,7 @@ export default class Model {
10
10
  this.label = this.name;
11
11
  }
12
12
 
13
- async generate(thread, payload = {}, functions = []) {
13
+ async generate(thread, functions = [], options = {}) {
14
14
  return null;
15
15
  }
16
16
 
@@ -18,19 +18,19 @@ export default class Model {
18
18
  throw new Error('countTokens not implemented in this model');
19
19
  }
20
20
 
21
- promptFromFunctions(payload, functions) {
22
- if (payload.function_call)
23
- functions = functions.filter(f => f.name !== payload.function_call);
21
+ promptFromFunctions(options, functions) {
22
+ if (options.force_function)
23
+ functions = functions.filter(f => f.name !== options.force_function);
24
24
 
25
25
  if (!functions.length)
26
26
  return '';
27
27
 
28
28
  let message;
29
- if (payload.function_call) {
29
+ if (options.force_function) {
30
30
  message = "Nella prossima risposta, rispondi UNICAMENTE seguendo le seguenti istruzioni:\n";
31
31
  message += functions[0].description + "\n";
32
32
  delete functions[0].description;
33
- message += "Rispondi con un messaggio che inizia con le parole:\nCALL " + payload.function_call + "\nE poi a capo un oggetto JSON che segue queste direttive OpenAPI:\n";
33
+ message += "Rispondi con un messaggio che inizia con le parole:\nCALL " + options.force_function + "\nE poi a capo un oggetto JSON che segue queste direttive OpenAPI:\n";
34
34
  } else {
35
35
  message = "Hai a disposizione alcune funzioni che puoi chiamare per ottenere risposte o compiere azioni. Ricorda che devi attendere la risposta dalla funzione per sapere se ha avuto successo. Per chiamare una funzione scrivi un messaggio che inizia con CALL nome_funzione e a capo inserisci il JSON con gli argomenti; delimitando il tutto da 3 caratteri ``` - ad esempio:\n" +
36
36
  "```\n" +
@@ -50,7 +50,7 @@ export default class Model {
50
50
  message += '=== ' + f.name + " ===\n" + JSON.stringify(f.parameters.properties) + "\n\n";
51
51
  }
52
52
 
53
- if (payload.function_call)
53
+ if (options.force_function)
54
54
  message += "\nNella risposta non deve esserci NIENTE ALTRO se non queste due cose, non saranno prese in considerazione dal sistema altro genere di risposte.";
55
55
 
56
56
  return message;
package/Summarizer.js CHANGED
@@ -67,7 +67,7 @@ export default class Summarizer extends MemoryHandler {
67
67
  }
68
68
  },
69
69
  ],
70
- function_call: {name: 'summarize'},
70
+ force_function: 'summarize',
71
71
  });
72
72
 
73
73
  if (!summary)
@@ -13,12 +13,21 @@ export default class AnthropicModel extends Model {
13
13
  return this.anthropic;
14
14
  }
15
15
 
16
- async generate(thread, payload = {}, functions = []) {
16
+ async generate(thread, functions = [], options = {}) {
17
+ options = {
18
+ functions: null,
19
+ force_function: null,
20
+ ...options,
21
+ };
22
+
23
+ if (options.functions !== null)
24
+ functions = options.functions;
25
+
17
26
  let [system, messages] = this.convertMessages(thread);
18
27
 
19
28
  if (functions.length && !this.supports_functions) {
20
29
  // Se il modello non supporta nativamente le funzioni, aggiungo il prompt al messaggio di sistema
21
- const functions_prompt = this.promptFromFunctions(payload, functions);
30
+ const functions_prompt = this.promptFromFunctions(options, functions);
22
31
  system += "\n\n" + functions_prompt;
23
32
  functions = [];
24
33
  }
@@ -34,9 +43,17 @@ export default class AnthropicModel extends Model {
34
43
  input_schema: f.parameters,
35
44
  required: f.required || undefined,
36
45
  })),
37
- ...payload,
38
46
  };
39
47
 
48
+ if (options.force_function && completion_payload.functions.length) {
49
+ completion_payload.messages.push({
50
+ role: 'user',
51
+ content: [
52
+ {type: 'text', text: 'Use the ' + options.force_function + ' tool in your response.'},
53
+ ],
54
+ });
55
+ }
56
+
40
57
  const message = await this.getAnthropic().messages.create(completion_payload);
41
58
 
42
59
  const message_content = [];
@@ -15,12 +15,21 @@ export default class OpenAIModel extends Model {
15
15
  return this.openai;
16
16
  }
17
17
 
18
- async generate(thread, payload = {}, functions = []) {
18
+ async generate(thread, functions = [], options = {}) {
19
+ options = {
20
+ functions: null,
21
+ force_function: null,
22
+ ...options,
23
+ };
24
+
25
+ if (options.functions !== null)
26
+ functions = options.functions;
27
+
19
28
  let messages = thread.messages;
20
29
 
21
30
  if (functions.length && !this.supports_functions) {
22
31
  // Se il modello non supporta nativamente le funzioni, inserisco il prompt ad hoc come ultimo messaggio di sistema
23
- const functions_prompt = this.promptFromFunctions(payload, functions);
32
+ const functions_prompt = this.promptFromFunctions(options, functions);
24
33
  let system_messages = [], other_messages = [], first_found = false;
25
34
  for (let message of messages) {
26
35
  if (!first_found && message.role !== 'system')
@@ -46,14 +55,12 @@ export default class OpenAIModel extends Model {
46
55
  model: this.name,
47
56
  messages: convertedMessages,
48
57
  functions,
49
- ...payload,
50
58
  };
51
59
 
52
- if (!completion_payload.functions?.length) {
60
+ if (options.force_function && completion_payload.functions.length)
61
+ completion_payload.function_call = {name: options.force_function};
62
+ if (!completion_payload.functions.length)
53
63
  delete completion_payload.functions;
54
- if (completion_payload.hasOwnProperty('function_call'))
55
- delete completion_payload.function_call;
56
- }
57
64
 
58
65
  const chatCompletion = await this.getOpenAi().chat.completions.create(completion_payload);
59
66
  const completion = chatCompletion.choices[0].message;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "type": "module",
3
3
  "name": "symposium",
4
- "version": "0.5.7",
4
+ "version": "0.6.0",
5
5
  "description": "Agents",
6
6
  "main": "index.js",
7
7
  "author": "Domenico Giambra",