symposium 0.5.4 → 0.5.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/Agent.js +1 -1
- package/Symposium.js +1 -1
- package/models/OpenAIModel.js +11 -13
- package/package.json +1 -1
package/Agent.js
CHANGED
|
@@ -179,7 +179,7 @@ export default class Agent {
|
|
|
179
179
|
let call_function = null;
|
|
180
180
|
for (let message of completion) {
|
|
181
181
|
thread.addDirectMessage(message);
|
|
182
|
-
await this.log('ai_message', message);
|
|
182
|
+
await this.log('ai_message', message.content);
|
|
183
183
|
|
|
184
184
|
for (let m of message.content) {
|
|
185
185
|
switch (m.type) {
|
package/Symposium.js
CHANGED
|
@@ -41,7 +41,7 @@ export default class Symposium {
|
|
|
41
41
|
for (let message of messages) {
|
|
42
42
|
const functionResponse = message.content.filter(c => c.type === 'function');
|
|
43
43
|
if (functionResponse.length)
|
|
44
|
-
return functionResponse[0].arguments;
|
|
44
|
+
return functionResponse[0].content.arguments;
|
|
45
45
|
}
|
|
46
46
|
|
|
47
47
|
return null;
|
package/models/OpenAIModel.js
CHANGED
|
@@ -8,12 +8,6 @@ export default class OpenAIModel extends Model {
|
|
|
8
8
|
name_for_tiktoken;
|
|
9
9
|
supports_functions = true;
|
|
10
10
|
|
|
11
|
-
constructor() {
|
|
12
|
-
super();
|
|
13
|
-
if (!this.name_for_tiktoken)
|
|
14
|
-
this.name_for_tiktoken = this.name;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
11
|
getOpenAi() {
|
|
18
12
|
if (!this.openai)
|
|
19
13
|
this.openai = new OpenAI({apiKey: process.env.OPENAI_API_KEY});
|
|
@@ -26,7 +20,7 @@ export default class OpenAIModel extends Model {
|
|
|
26
20
|
|
|
27
21
|
if (functions.length && !this.supports_functions) {
|
|
28
22
|
// Se il modello non supporta nativamente le funzioni, inserisco il prompt ad hoc come ultimo messaggio di sistema
|
|
29
|
-
const functions_prompt = this.promptFromFunctions(functions);
|
|
23
|
+
const functions_prompt = this.promptFromFunctions(payload, functions);
|
|
30
24
|
let system_messages = [], other_messages = [], first_found = false;
|
|
31
25
|
for (let message of messages) {
|
|
32
26
|
if (!first_found && message.role !== 'system')
|
|
@@ -83,12 +77,16 @@ export default class OpenAIModel extends Model {
|
|
|
83
77
|
}
|
|
84
78
|
|
|
85
79
|
async countTokens(thread) {
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
80
|
+
try {
|
|
81
|
+
const encoder = encoding_for_model(this.name_for_tiktoken || this.name);
|
|
82
|
+
|
|
83
|
+
const texts = [];
|
|
84
|
+
for (let message of thread.messages)
|
|
85
|
+
texts.push(message.content.map(m => typeof m.content === 'string' ? m.content : JSON.stringify(m.content)).join(''));
|
|
86
|
+
return encoder.encode(texts.join('')).length;
|
|
87
|
+
} catch (e) {
|
|
88
|
+
throw new Error('Error while counting tokens');
|
|
89
|
+
}
|
|
92
90
|
}
|
|
93
91
|
|
|
94
92
|
convertMessage(message) {
|