symposium 0.6.6 → 0.6.7

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
@@ -227,7 +227,7 @@ export default class Agent {
227
227
  }
228
228
 
229
229
  async callFunction(thread, function_call) {
230
- let functions = await this.getFunctions(false);
230
+ const functions = await this.getFunctions(false);
231
231
  if (!functions.has(function_call.name))
232
232
  throw new Error('Unrecognized function ' + function_call.name);
233
233
 
@@ -235,7 +235,7 @@ export default class Agent {
235
235
 
236
236
  try {
237
237
  const response = await functions.get(function_call.name).tool.callFunction(thread, function_call.name, function_call.arguments);
238
- thread.addMessage('function', [
238
+ thread.addMessage('tool', [
239
239
  {
240
240
  type: 'function_response',
241
241
  content: {response, id: function_call.id || undefined},
@@ -88,7 +88,7 @@ export default class AnthropicModel extends Model {
88
88
  system.push(message.content.map(c => c.content).join("\n"));
89
89
  } else {
90
90
  const parsedMessage = {
91
- role: message.role === 'function' ? 'user' : message.role,
91
+ role: ['function', 'tool'].includes(message.role) ? 'user' : message.role,
92
92
  content: message.content.map(c => {
93
93
  switch (c.type) {
94
94
  case 'text':
@@ -49,11 +49,19 @@ 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.function_call = {name: options.force_function};
58
+ if (options.force_function) {
59
+ completion_payload.tool_choice = {
60
+ type: 'function',
61
+ function: {name: options.force_function},
62
+ };
63
+ }
64
+
57
65
  if (!completion_payload.functions.length)
58
66
  delete completion_payload.functions;
59
67
 
@@ -63,14 +71,21 @@ 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
- if (completion.function_call) {
67
- message_content.push({
68
- type: 'function',
69
- content: {
70
- name: completion.function_call.name,
71
- arguments: completion.function_call.arguments ? JSON.parse(completion.function_call.arguments) : {},
72
- },
73
- });
74
+
75
+ if (completion.tool_calls) {
76
+ for (let tool_call of completion.tool_calls) {
77
+ if (tool_call.type !== 'function')
78
+ throw new Error('Unsupported tool type ' + tool_call.type);
79
+
80
+ message_content.push({
81
+ type: 'function',
82
+ content: {
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
+ });
88
+ }
74
89
  }
75
90
 
76
91
  return [
@@ -108,10 +123,16 @@ export default class OpenAIModel extends Model {
108
123
  messages.push({
109
124
  role: message.role,
110
125
  name: message.name,
111
- function_call: {
112
- name: c.content.name,
113
- arguments: c.content.arguments ? JSON.stringify(c.content.arguments) : '{}',
114
- },
126
+ tool_calls: [
127
+ {
128
+ id: c.content.id,
129
+ type: 'function',
130
+ function: {
131
+ name: c.content.name,
132
+ arguments: c.content.arguments ? JSON.stringify(c.content.arguments) : '{}',
133
+ },
134
+ },
135
+ ],
115
136
  });
116
137
  } else {
117
138
  messages.push({
@@ -126,6 +147,8 @@ export default class OpenAIModel extends Model {
126
147
  if (this.supports_functions) {
127
148
  messages.push({
128
149
  role: message.role,
150
+ type: 'tool_result',
151
+ tool_call_id: c.content.id,
129
152
  content: JSON.stringify(c.content.response),
130
153
  name: message.name,
131
154
  });
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "type": "module",
3
3
  "name": "symposium",
4
- "version": "0.6.6",
4
+ "version": "0.6.7",
5
5
  "description": "Agents",
6
6
  "main": "index.js",
7
7
  "author": "Domenico Giambra",
@@ -1,9 +0,0 @@
1
- import OpenAIModel from "./OpenAIModel.js";
2
-
3
- export default class Gpt4Vision extends OpenAIModel {
4
- name = 'gpt-4-vision-preview';
5
- label = 'gpt-4-vision';
6
- name_for_tiktoken = 'gpt-4';
7
- tokens = 128000;
8
- supports_functions = false;
9
- }