symposium 0.6.1 → 0.6.2
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/Model.js +1 -1
- package/models/AnthropicModel.js +30 -15
- package/package.json +1 -1
package/Model.js
CHANGED
|
@@ -31,7 +31,7 @@ export default class Model {
|
|
|
31
31
|
if (options.force_function && !functions.find(f => f.name === options.force_function))
|
|
32
32
|
throw new Error('Function ' + options.force_function + ' not found.');
|
|
33
33
|
|
|
34
|
-
return
|
|
34
|
+
return {options, functions};
|
|
35
35
|
}
|
|
36
36
|
|
|
37
37
|
promptFromFunctions(options, functions) {
|
package/models/AnthropicModel.js
CHANGED
|
@@ -41,15 +41,15 @@ export default class AnthropicModel extends Model {
|
|
|
41
41
|
};
|
|
42
42
|
|
|
43
43
|
if (options.force_function) {
|
|
44
|
-
completion_payload.messages.push({
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
{type: 'text', text: 'Use the ' + options.force_function + ' tool in your response.'},
|
|
48
|
-
],
|
|
44
|
+
completion_payload.messages[completion_payload.messages.length - 1].content.push({
|
|
45
|
+
type: 'text',
|
|
46
|
+
text: 'Usa il tool "' + options.force_function + '" nella tua prossima risposta!',
|
|
49
47
|
});
|
|
50
48
|
}
|
|
51
49
|
|
|
52
|
-
const message =
|
|
50
|
+
const message = completion_payload.tools.length ?
|
|
51
|
+
await this.getAnthropic().beta.tools.messages.create(completion_payload)
|
|
52
|
+
: await this.getAnthropic().messages.create(completion_payload);
|
|
53
53
|
|
|
54
54
|
const message_content = [];
|
|
55
55
|
if (message.content) {
|
|
@@ -81,32 +81,47 @@ export default class AnthropicModel extends Model {
|
|
|
81
81
|
}
|
|
82
82
|
|
|
83
83
|
convertMessages(thread) {
|
|
84
|
-
let system = [], messages = [];
|
|
84
|
+
let system = [], messages = [], lastMessage = null;
|
|
85
85
|
for (let message of thread.messages) {
|
|
86
86
|
if (message.role === 'system') {
|
|
87
87
|
system.push(message.content.map(c => c.content).join("\n"));
|
|
88
88
|
} else {
|
|
89
|
-
|
|
89
|
+
const parsedMessage = {
|
|
90
90
|
role: message.role === 'function' ? 'user' : message.role,
|
|
91
91
|
content: message.content.map(c => {
|
|
92
92
|
switch (c.type) {
|
|
93
93
|
case 'text':
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
94
|
+
if (message.role === 'function') {
|
|
95
|
+
return {
|
|
96
|
+
type: 'text',
|
|
97
|
+
content: c.content,
|
|
98
|
+
};
|
|
99
|
+
} else {
|
|
100
|
+
return {
|
|
101
|
+
type: 'text',
|
|
102
|
+
text: c.content.trim(),
|
|
103
|
+
};
|
|
104
|
+
}
|
|
98
105
|
|
|
99
106
|
case 'function':
|
|
100
107
|
return {
|
|
101
|
-
type: '
|
|
102
|
-
|
|
108
|
+
type: 'tool_use',
|
|
109
|
+
name: c.content.name,
|
|
110
|
+
input: c.content.arguments,
|
|
103
111
|
};
|
|
104
112
|
|
|
105
113
|
default:
|
|
106
114
|
throw new Error('Message type "' + c.type + '" unsupported by this model');
|
|
107
115
|
}
|
|
108
116
|
}),
|
|
109
|
-
}
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
if (lastMessage && lastMessage.role === parsedMessage.role) {
|
|
120
|
+
lastMessage.content = lastMessage.content.concat(message.content);
|
|
121
|
+
} else {
|
|
122
|
+
messages.push(parsedMessage);
|
|
123
|
+
lastMessage = parsedMessage;
|
|
124
|
+
}
|
|
110
125
|
}
|
|
111
126
|
}
|
|
112
127
|
|