symposium 0.7.2 → 0.7.4

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
@@ -195,7 +195,7 @@ export default class Agent {
195
195
  }
196
196
 
197
197
  if (functions.length) {
198
- for(let f of functions) {
198
+ for (let f of functions) {
199
199
  const response = await this.callFunction(thread, f);
200
200
 
201
201
  thread.addMessage('tool', [
@@ -209,7 +209,7 @@ export default class Agent {
209
209
  }
210
210
 
211
211
  await this.execute(thread);
212
- }else {
212
+ } else {
213
213
  await thread.storeState();
214
214
  }
215
215
  }
@@ -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,81 @@ 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
+ break;
152
+
153
+ default:
154
+ throw new Error('Message type "' + c.type + '" unsupported by this model');
155
+ }
156
+ }
157
+
92
158
  const parsedMessage = {
93
159
  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
- }),
160
+ content,
139
161
  };
140
162
 
141
163
  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.2",
4
+ "version": "0.7.4",
5
5
  "description": "Agents",
6
6
  "main": "index.js",
7
7
  "author": "Domenico Giambra",