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