symposium 0.7.1 → 0.7.3

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
@@ -1,10 +1,9 @@
1
1
  import Symposium from "./Symposium.js";
2
2
  import Thread from "./Thread.js";
3
- import Message from "./Message.js";
4
3
 
5
4
  export default class Agent {
6
5
  name = 'Agent';
7
- descriptionForFront = '';
6
+ description = null;
8
7
  options = {};
9
8
  threads;
10
9
  functions = null;
@@ -196,7 +195,7 @@ export default class Agent {
196
195
  }
197
196
 
198
197
  if (functions.length) {
199
- for(let f of functions) {
198
+ for (let f of functions) {
200
199
  const response = await this.callFunction(thread, f);
201
200
 
202
201
  thread.addMessage('tool', [
@@ -210,7 +209,7 @@ export default class Agent {
210
209
  }
211
210
 
212
211
  await this.execute(thread);
213
- }else {
212
+ } else {
214
213
  await thread.storeState();
215
214
  }
216
215
  }
package/Thread.js CHANGED
@@ -50,7 +50,7 @@ export default class Thread {
50
50
  await Redis.set('thread-' + this.id, {
51
51
  state: this.state,
52
52
  messages: this.messages,
53
- }, 0);
53
+ }, process.env.THREADS_TTL || 604800);
54
54
  }
55
55
 
56
56
  addDirectMessage(message) {
@@ -18,7 +18,7 @@ export default class AnthropicModel extends Model {
18
18
  options = parsed.options;
19
19
  functions = parsed.functions;
20
20
 
21
- let [system, messages] = this.convertMessages(thread);
21
+ let [system, messages] = await this.convertMessages(thread);
22
22
 
23
23
  if (functions.length && !this.supports_functions) {
24
24
  // Se il modello non supporta nativamente le funzioni, aggiungo il prompt al messaggio di sistema
@@ -83,59 +83,80 @@ export default class AnthropicModel extends Model {
83
83
  ];
84
84
  }
85
85
 
86
- convertMessages(thread) {
86
+ async convertMessages(thread) {
87
87
  let system = [], messages = [], lastMessage = null;
88
88
  for (let message of thread.messages) {
89
89
  if (message.role === 'system') {
90
90
  system.push(message.content.map(c => c.content).join("\n"));
91
91
  } else {
92
+ const content = [];
93
+ for (let c of message.content) {
94
+ switch (c.type) {
95
+ case 'text':
96
+ content.push({
97
+ type: 'text',
98
+ text: c.content.trim(),
99
+ });
100
+ break;
101
+
102
+ case 'function':
103
+ content.push({
104
+ type: 'tool_use',
105
+ name: c.content[0].name,
106
+ input: c.content[0].arguments,
107
+ id: c.content[0].id,
108
+ });
109
+ break;
110
+
111
+ case 'function_response':
112
+ content.push({
113
+ type: 'tool_result',
114
+ content: JSON.stringify(c.content.response),
115
+ tool_use_id: c.content.id,
116
+ });
117
+ break;
118
+
119
+ case 'image':
120
+ switch (c.content.type) {
121
+ case 'base64':
122
+ content.push({
123
+ type: 'image',
124
+ source: {
125
+ type: 'base64',
126
+ media_type: c.content.mime,
127
+ data: c.content.data,
128
+ },
129
+ });
130
+ break;
131
+
132
+ case 'url':
133
+ console.log('Retrieving the image...');
134
+ const image = await fetch(c.content.data).then(r => (r?.ok ? r.arrayBuffer() : null));
135
+ if (!image)
136
+ throw new Error('Error while downloading the image');
137
+
138
+ content.push({
139
+ type: 'image',
140
+ source: {
141
+ type: 'base64',
142
+ media_type: c.content.mime,
143
+ data: Buffer.from(image).toString('base64'),
144
+ },
145
+ });
146
+ break;
147
+
148
+ default:
149
+ throw new Error('Image source not supported');
150
+ }
151
+
152
+ default:
153
+ throw new Error('Message type "' + c.type + '" unsupported by this model');
154
+ }
155
+ }
156
+
92
157
  const parsedMessage = {
93
158
  role: ['function', 'tool'].includes(message.role) ? 'user' : message.role,
94
- content: message.content.map(c => {
95
- switch (c.type) {
96
- case 'text':
97
- return {
98
- type: 'text',
99
- text: c.content.trim(),
100
- };
101
-
102
- case 'function':
103
- return {
104
- type: 'tool_use',
105
- name: c.content[0].name,
106
- input: c.content[0].arguments,
107
- id: c.content[0].id,
108
- };
109
-
110
- case 'function_response':
111
- return {
112
- type: 'tool_result',
113
- content: JSON.stringify(c.content.response),
114
- tool_use_id: c.content.id,
115
- };
116
-
117
- case 'image':
118
- switch (c.content.type) {
119
- case 'base64':
120
- return {
121
- type: 'image',
122
- source: {
123
- type: 'base64',
124
- media_type: c.content.mime,
125
- data: c.content.data,
126
- },
127
- };
128
-
129
- // TODO: url
130
-
131
- default:
132
- throw new Error('Image source not supported');
133
- }
134
-
135
- default:
136
- throw new Error('Message type "' + c.type + '" unsupported by this model');
137
- }
138
- }),
159
+ content,
139
160
  };
140
161
 
141
162
  if (lastMessage && lastMessage.role === parsedMessage.role) {
@@ -126,6 +126,7 @@ export default class OpenAIModel extends Model {
126
126
  type: 'image_url',
127
127
  image_url: {
128
128
  url: c.content.type === 'base64' ? 'data:' + c.content.mime + ';base64,' + c.content.data : c.content.data,
129
+ detail: c.content.detail || 'auto',
129
130
  },
130
131
  },
131
132
  ],
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "type": "module",
3
3
  "name": "symposium",
4
- "version": "0.7.1",
4
+ "version": "0.7.3",
5
5
  "description": "Agents",
6
6
  "main": "index.js",
7
7
  "author": "Domenico Giambra",