symposium 0.5.3 → 0.5.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
@@ -179,7 +179,7 @@ export default class Agent {
179
179
  let call_function = null;
180
180
  for (let message of completion) {
181
181
  thread.addDirectMessage(message);
182
- await this.log('ai_message', message);
182
+ await this.log('ai_message', message.content);
183
183
 
184
184
  for (let m of message.content) {
185
185
  switch (m.type) {
package/Summarizer.js CHANGED
@@ -78,11 +78,11 @@ export default class Summarizer extends MemoryHandler {
78
78
  if (message.role === 'system' && !message.tags.includes('summary')) {
79
79
  summarizedThread.messages.push(message);
80
80
  } else {
81
- const functionResponse = summary.content.filter(c => c.type === 'function');
82
- if (!functionResponse.length)
81
+ const functionResponse = Symposium.extractFunctionFromResponse(summary);
82
+ if (functionResponse)
83
83
  throw new Error('Errore durante la generazione di un riassunto interno');
84
84
 
85
- summarizedThread.addMessage('system', "This is what happened until now:\n" + functionResponse[0].arguments.summary, undefined, ['summary']);
85
+ summarizedThread.addMessage('system', "This is what happened until now:\n" + functionResponse.summary, undefined, ['summary']);
86
86
  break;
87
87
  }
88
88
  }
package/Symposium.js CHANGED
@@ -36,4 +36,14 @@ export default class Symposium {
36
36
  static getModelByLabel(label) {
37
37
  return Array.from(this.models.values()).find(model => model.label === label);
38
38
  }
39
+
40
+ static extractFunctionFromResponse(messages) {
41
+ for (let message of messages) {
42
+ const functionResponse = message.content.filter(c => c.type === 'function');
43
+ if (functionResponse.length)
44
+ return functionResponse[0].content.arguments;
45
+ }
46
+
47
+ return null;
48
+ }
39
49
  }
@@ -8,12 +8,6 @@ export default class OpenAIModel extends Model {
8
8
  name_for_tiktoken;
9
9
  supports_functions = true;
10
10
 
11
- constructor() {
12
- super();
13
- if (!this.name_for_tiktoken)
14
- this.name_for_tiktoken = this.name;
15
- }
16
-
17
11
  getOpenAi() {
18
12
  if (!this.openai)
19
13
  this.openai = new OpenAI({apiKey: process.env.OPENAI_API_KEY});
@@ -83,12 +77,16 @@ export default class OpenAIModel extends Model {
83
77
  }
84
78
 
85
79
  async countTokens(thread) {
86
- const encoder = encoding_for_model(this.name_for_tiktoken);
87
-
88
- const texts = [];
89
- for (let message of thread.messages)
90
- texts.push(message.content.map(m => typeof m.content === 'string' ? m.content : JSON.stringify(m.content)).join(''));
91
- return encoder.encode(texts.join('')).length;
80
+ try {
81
+ const encoder = encoding_for_model(this.name_for_tiktoken || this.name);
82
+
83
+ const texts = [];
84
+ for (let message of thread.messages)
85
+ texts.push(message.content.map(m => typeof m.content === 'string' ? m.content : JSON.stringify(m.content)).join(''));
86
+ return encoder.encode(texts.join('')).length;
87
+ } catch (e) {
88
+ throw new Error('Error while counting tokens');
89
+ }
92
90
  }
93
91
 
94
92
  convertMessage(message) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "type": "module",
3
3
  "name": "symposium",
4
- "version": "0.5.3",
4
+ "version": "0.5.5",
5
5
  "description": "Agents",
6
6
  "main": "index.js",
7
7
  "author": "Domenico Giambra",