symposium 0.6.6 → 0.6.8
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 +24 -28
- package/Symposium.js +0 -2
- package/models/AnthropicModel.js +11 -9
- package/models/OpenAIModel.js +35 -15
- package/package.json +1 -1
- package/models/Gpt4Vision.js +0 -9
package/Agent.js
CHANGED
|
@@ -162,7 +162,7 @@ export default class Agent {
|
|
|
162
162
|
|
|
163
163
|
const match = text.match(/^CALL ([A-Za-z0-9_]+)\n([\s\S]*)$/);
|
|
164
164
|
if (match)
|
|
165
|
-
newContent.push({type: 'function', content: {name: match[1], arguments: JSON.parse(match[2] || '{}')}});
|
|
165
|
+
newContent.push({type: 'function', content: [{name: match[1], arguments: JSON.parse(match[2] || '{}')}]});
|
|
166
166
|
else
|
|
167
167
|
newContent.push({type: 'text', content: text});
|
|
168
168
|
}
|
|
@@ -176,7 +176,7 @@ export default class Agent {
|
|
|
176
176
|
}
|
|
177
177
|
|
|
178
178
|
async handleCompletion(thread, completion) {
|
|
179
|
-
|
|
179
|
+
const functions = [];
|
|
180
180
|
for (let message of completion) {
|
|
181
181
|
thread.addDirectMessage(message);
|
|
182
182
|
await this.log('ai_message', message.content);
|
|
@@ -188,19 +188,30 @@ export default class Agent {
|
|
|
188
188
|
break;
|
|
189
189
|
|
|
190
190
|
case 'function':
|
|
191
|
-
|
|
192
|
-
throw new Error('The model replied with more than one function');
|
|
193
|
-
else
|
|
194
|
-
call_function = m.content;
|
|
191
|
+
functions.push(m.content);
|
|
195
192
|
break;
|
|
196
193
|
}
|
|
197
194
|
}
|
|
198
195
|
}
|
|
199
196
|
|
|
200
|
-
if (
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
197
|
+
if (functions.length) {
|
|
198
|
+
for(let f of functions) {
|
|
199
|
+
const response = await this.callFunction(thread, f);
|
|
200
|
+
|
|
201
|
+
thread.addMessage('tool', [
|
|
202
|
+
{
|
|
203
|
+
type: 'function_response',
|
|
204
|
+
content: {name: f.name, response, id: f.id || undefined},
|
|
205
|
+
},
|
|
206
|
+
], f.name);
|
|
207
|
+
|
|
208
|
+
await this.log('function_response', response);
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
await this.execute(thread);
|
|
212
|
+
}else {
|
|
213
|
+
await thread.storeState();
|
|
214
|
+
}
|
|
204
215
|
}
|
|
205
216
|
|
|
206
217
|
async getFunctions(parsed = true) {
|
|
@@ -227,32 +238,17 @@ export default class Agent {
|
|
|
227
238
|
}
|
|
228
239
|
|
|
229
240
|
async callFunction(thread, function_call) {
|
|
230
|
-
|
|
241
|
+
const functions = await this.getFunctions(false);
|
|
231
242
|
if (!functions.has(function_call.name))
|
|
232
243
|
throw new Error('Unrecognized function ' + function_call.name);
|
|
233
244
|
|
|
234
245
|
await this.log('function_call', function_call);
|
|
235
246
|
|
|
236
247
|
try {
|
|
237
|
-
|
|
238
|
-
thread.addMessage('function', [
|
|
239
|
-
{
|
|
240
|
-
type: 'function_response',
|
|
241
|
-
content: {response, id: function_call.id || undefined},
|
|
242
|
-
},
|
|
243
|
-
], function_call.name);
|
|
244
|
-
await this.log('function_response', response);
|
|
248
|
+
return await functions.get(function_call.name).tool.callFunction(thread, function_call.name, function_call.arguments);
|
|
245
249
|
} catch (error) {
|
|
246
|
-
|
|
247
|
-
{
|
|
248
|
-
type: 'function_response',
|
|
249
|
-
content: {response: {error}},
|
|
250
|
-
},
|
|
251
|
-
], function_call.name);
|
|
252
|
-
await this.log('function_response', {error});
|
|
250
|
+
return {error};
|
|
253
251
|
}
|
|
254
|
-
|
|
255
|
-
await this.execute(thread);
|
|
256
252
|
}
|
|
257
253
|
|
|
258
254
|
async setModel(thread, label) {
|
package/Symposium.js
CHANGED
|
@@ -2,7 +2,6 @@ import Redis from "@travio/redis";
|
|
|
2
2
|
import Gpt35 from "./models/Gpt35.js";
|
|
3
3
|
import Gpt4 from "./models/Gpt4.js";
|
|
4
4
|
import Gpt4Turbo from "./models/Gpt4Turbo.js";
|
|
5
|
-
import Gpt4Vision from "./models/Gpt4Vision.js";
|
|
6
5
|
import Whisper from "./models/Whisper.js";
|
|
7
6
|
import Claude3Haiku from "./models/Claude3Haiku.js";
|
|
8
7
|
import Claude3Sonnet from "./models/Claude3Sonnet.js";
|
|
@@ -15,7 +14,6 @@ export default class Symposium {
|
|
|
15
14
|
this.loadModel(new Gpt35());
|
|
16
15
|
this.loadModel(new Gpt4());
|
|
17
16
|
this.loadModel(new Gpt4Turbo());
|
|
18
|
-
this.loadModel(new Gpt4Vision());
|
|
19
17
|
this.loadModel(new Whisper());
|
|
20
18
|
|
|
21
19
|
this.loadModel(new Claude3Haiku());
|
package/models/AnthropicModel.js
CHANGED
|
@@ -62,11 +62,13 @@ export default class AnthropicModel extends Model {
|
|
|
62
62
|
case 'tool_use':
|
|
63
63
|
message_content.push({
|
|
64
64
|
type: 'function',
|
|
65
|
-
content:
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
65
|
+
content: [
|
|
66
|
+
{
|
|
67
|
+
id: m.id,
|
|
68
|
+
name: m.name,
|
|
69
|
+
arguments: m.input,
|
|
70
|
+
},
|
|
71
|
+
],
|
|
70
72
|
});
|
|
71
73
|
break;
|
|
72
74
|
|
|
@@ -88,7 +90,7 @@ export default class AnthropicModel extends Model {
|
|
|
88
90
|
system.push(message.content.map(c => c.content).join("\n"));
|
|
89
91
|
} else {
|
|
90
92
|
const parsedMessage = {
|
|
91
|
-
role: message.role
|
|
93
|
+
role: ['function', 'tool'].includes(message.role) ? 'user' : message.role,
|
|
92
94
|
content: message.content.map(c => {
|
|
93
95
|
switch (c.type) {
|
|
94
96
|
case 'text':
|
|
@@ -100,9 +102,9 @@ export default class AnthropicModel extends Model {
|
|
|
100
102
|
case 'function':
|
|
101
103
|
return {
|
|
102
104
|
type: 'tool_use',
|
|
103
|
-
name: c.content.name,
|
|
104
|
-
input: c.content.arguments,
|
|
105
|
-
id: c.content.id,
|
|
105
|
+
name: c.content[0].name,
|
|
106
|
+
input: c.content[0].arguments,
|
|
107
|
+
id: c.content[0].id,
|
|
106
108
|
};
|
|
107
109
|
|
|
108
110
|
case 'function_response':
|
package/models/OpenAIModel.js
CHANGED
|
@@ -49,13 +49,21 @@ export default class OpenAIModel extends Model {
|
|
|
49
49
|
const completion_payload = {
|
|
50
50
|
model: this.name,
|
|
51
51
|
messages: convertedMessages,
|
|
52
|
-
functions
|
|
52
|
+
tools: functions.map(f => ({
|
|
53
|
+
type: 'function',
|
|
54
|
+
function: f,
|
|
55
|
+
})),
|
|
53
56
|
};
|
|
54
57
|
|
|
55
|
-
if (options.force_function)
|
|
56
|
-
completion_payload.
|
|
57
|
-
|
|
58
|
-
|
|
58
|
+
if (options.force_function) {
|
|
59
|
+
completion_payload.tool_choice = {
|
|
60
|
+
type: 'function',
|
|
61
|
+
function: {name: options.force_function},
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
if (!completion_payload.tools.length)
|
|
66
|
+
delete completion_payload.tools;
|
|
59
67
|
|
|
60
68
|
const chatCompletion = await this.getOpenAi().chat.completions.create(completion_payload);
|
|
61
69
|
const completion = chatCompletion.choices[0].message;
|
|
@@ -63,13 +71,20 @@ export default class OpenAIModel extends Model {
|
|
|
63
71
|
const message_content = [];
|
|
64
72
|
if (completion.content)
|
|
65
73
|
message_content.push({type: 'text', content: completion.content});
|
|
66
|
-
|
|
74
|
+
|
|
75
|
+
if (completion.tool_calls?.length) {
|
|
67
76
|
message_content.push({
|
|
68
77
|
type: 'function',
|
|
69
|
-
content: {
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
78
|
+
content: completion.tool_calls.map(tool_call => {
|
|
79
|
+
if (tool_call.type !== 'function')
|
|
80
|
+
throw new Error('Unsupported tool type ' + tool_call.type);
|
|
81
|
+
|
|
82
|
+
return {
|
|
83
|
+
id: tool_call.id,
|
|
84
|
+
name: tool_call.function.name,
|
|
85
|
+
arguments: tool_call.function.arguments ? JSON.parse(tool_call.function.arguments) : {},
|
|
86
|
+
};
|
|
87
|
+
}),
|
|
73
88
|
});
|
|
74
89
|
}
|
|
75
90
|
|
|
@@ -108,15 +123,19 @@ export default class OpenAIModel extends Model {
|
|
|
108
123
|
messages.push({
|
|
109
124
|
role: message.role,
|
|
110
125
|
name: message.name,
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
126
|
+
tool_calls: c.content.map(tool_call => ({
|
|
127
|
+
id: tool_call.id,
|
|
128
|
+
type: 'function',
|
|
129
|
+
function: {
|
|
130
|
+
name: tool_call.name,
|
|
131
|
+
arguments: tool_call.arguments ? JSON.stringify(tool_call.arguments) : '{}',
|
|
132
|
+
},
|
|
133
|
+
})),
|
|
115
134
|
});
|
|
116
135
|
} else {
|
|
117
136
|
messages.push({
|
|
118
137
|
role: message.role,
|
|
119
|
-
content: '```CALL \n' +
|
|
138
|
+
content: c.content.map(f => '```CALL \n' + f.name + '\n' + JSON.stringify(f.arguments || {}) + '\n```').join("\n\n"),
|
|
120
139
|
name: message.name,
|
|
121
140
|
});
|
|
122
141
|
}
|
|
@@ -126,6 +145,7 @@ export default class OpenAIModel extends Model {
|
|
|
126
145
|
if (this.supports_functions) {
|
|
127
146
|
messages.push({
|
|
128
147
|
role: message.role,
|
|
148
|
+
tool_call_id: c.content.id,
|
|
129
149
|
content: JSON.stringify(c.content.response),
|
|
130
150
|
name: message.name,
|
|
131
151
|
});
|
package/package.json
CHANGED
package/models/Gpt4Vision.js
DELETED