symposium 1.3.4 → 1.4.0

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.
@@ -1,6 +1,6 @@
1
1
  import AnthropicModel from "./AnthropicModel.js";
2
2
 
3
- export default class Claude35Sonnet extends AnthropicModel {
3
+ export default class Claude37Sonnet extends AnthropicModel {
4
4
  name = 'claude-3-7-sonnet-latest';
5
5
  label = 'claude-3.7-sonnet';
6
6
  tokens = 200000;
@@ -0,0 +1,7 @@
1
+ import AnthropicModel from "./AnthropicModel.js";
2
+
3
+ export default class Claude45Haiku extends AnthropicModel {
4
+ name = 'claude-haiku-4-5-20251001';
5
+ label = 'claude-4.5-haiku';
6
+ tokens = 200000;
7
+ }
@@ -0,0 +1,148 @@
1
+ import ollama from "ollama";
2
+ import Model from "../Model.js";
3
+ import Message from "../Message.js";
4
+
5
+ export default class OllamaModel extends Model {
6
+ supports_functions = true;
7
+
8
+ async generate(thread, functions = [], options = {}) {
9
+ const parsed = this.parseOptions(options, functions);
10
+ options = parsed.options;
11
+ functions = parsed.functions;
12
+
13
+ let messages = thread.messages;
14
+
15
+ if (functions.length && !this.supports_functions) {
16
+ // Se il modello non supporta nativamente le funzioni, inserisco il prompt ad hoc come ultimo messaggio di sistema
17
+ const functions_prompt = this.promptFromFunctions(options, functions);
18
+ let system_messages = [], other_messages = [], first_found = false;
19
+ for (let message of messages) {
20
+ if (!first_found && message.role !== 'system')
21
+ first_found = true;
22
+
23
+ if (!first_found)
24
+ system_messages.push(message);
25
+ else
26
+ other_messages.push(message);
27
+ }
28
+
29
+ system_messages.push(new Message('system', functions_prompt));
30
+
31
+ messages = [...system_messages, ...other_messages];
32
+ functions = [];
33
+ }
34
+
35
+ const convertedMessages = [];
36
+ for (let m of messages)
37
+ convertedMessages.push(...this.convertMessage(m));
38
+
39
+ const completion_payload = {
40
+ model: this.name,
41
+ messages: convertedMessages,
42
+ tools: functions.map(f => ({
43
+ type: 'function',
44
+ function: f,
45
+ })),
46
+ };
47
+
48
+ if (options.force_function) {
49
+ completion_payload.tool_choice = {
50
+ type: 'function',
51
+ function: {name: options.force_function},
52
+ };
53
+ }
54
+
55
+ if (options.response_format)
56
+ completion_payload.response_format = options.response_format;
57
+
58
+ if (!completion_payload.tools.length)
59
+ delete completion_payload.tools;
60
+
61
+ const chatCompletion = await ollama.chat(completion_payload);
62
+ const completion = chatCompletion.message;
63
+
64
+ const message_content = [];
65
+ if (completion.content)
66
+ message_content.push({type: 'text', content: completion.content});
67
+
68
+ if (completion.tool_calls?.length) {
69
+ message_content.push({
70
+ type: 'function',
71
+ content: completion.tool_calls.map(tool_call => {
72
+ if (tool_call.function)
73
+ throw new Error('Unsupported tool type');
74
+
75
+ return {
76
+ name: tool_call.function.name,
77
+ arguments: tool_call.function.arguments ? JSON.parse(tool_call.function.arguments) : {},
78
+ };
79
+ }),
80
+ });
81
+ }
82
+
83
+ return [
84
+ new Message('assistant', message_content),
85
+ ];
86
+ }
87
+
88
+ convertMessage(message) {
89
+ const messages = [],
90
+ role = message.role === 'system' ? this.system_role_name : message.role;
91
+
92
+ for (let c of message.content) {
93
+ switch (c.type) {
94
+ case 'text':
95
+ messages.push({
96
+ role,
97
+ content: c.content,
98
+ name: message.name,
99
+ });
100
+ break;
101
+
102
+ case 'function':
103
+ if (this.supports_functions) {
104
+ messages.push({
105
+ role,
106
+ name: message.name,
107
+ tool_calls: c.content.map(tool_call => ({
108
+ id: tool_call.id,
109
+ type: 'function',
110
+ function: {
111
+ name: tool_call.name,
112
+ arguments: tool_call.arguments ? JSON.stringify(tool_call.arguments) : '{}',
113
+ },
114
+ })),
115
+ });
116
+ } else {
117
+ messages.push({
118
+ role,
119
+ content: c.content.map(f => '```CALL \n' + f.name + '\n' + JSON.stringify(f.arguments || {}) + '\n```').join("\n\n"),
120
+ name: message.name,
121
+ });
122
+ }
123
+ break;
124
+
125
+ case 'function_response':
126
+ if (this.supports_functions) {
127
+ messages.push({
128
+ role: 'tool',
129
+ content: JSON.stringify(c.content.response),
130
+ tool_name: message.name,
131
+ });
132
+ } else {
133
+ messages.push({
134
+ role: 'user',
135
+ content: 'FUNCTION RESPONSE:\n' + JSON.stringify(c.content.response),
136
+ name: message.name,
137
+ });
138
+ }
139
+ break;
140
+
141
+ default:
142
+ throw new Error('Message type unsupported by this model');
143
+ }
144
+ }
145
+
146
+ return messages;
147
+ }
148
+ }
package/package.json CHANGED
@@ -1,14 +1,15 @@
1
1
  {
2
2
  "type": "module",
3
3
  "name": "symposium",
4
- "version": "1.3.4",
4
+ "version": "1.4.0",
5
5
  "description": "Agents",
6
6
  "main": "index.js",
7
7
  "author": "Domenico Giambra",
8
8
  "license": "ISC",
9
9
  "dependencies": {
10
- "@anthropic-ai/sdk": "^0.65.0",
10
+ "@anthropic-ai/sdk": "^0.67.0",
11
11
  "groq-sdk": "^0.33.0",
12
+ "ollama": "^0.6.0",
12
13
  "openai": "^6.0.0",
13
14
  "tiktoken": "^1.0.10",
14
15
  "uuid": "^13.0.0"