symposium 0.3.3 → 0.3.4
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 +6 -38
- package/Model.js +9 -5
- package/Symposium.js +14 -19
- package/models/Gpt35.js +8 -0
- package/models/Gpt4.js +7 -0
- package/models/Gpt4Turbo.js +8 -0
- package/models/Gpt4Vision.js +9 -0
- package/models/OpenAIModel.js +37 -0
- package/package.json +1 -1
package/Agent.js
CHANGED
|
@@ -105,13 +105,7 @@ export default class Agent {
|
|
|
105
105
|
}
|
|
106
106
|
}
|
|
107
107
|
|
|
108
|
-
const
|
|
109
|
-
if (this.options.talking_function) {
|
|
110
|
-
completion_payload.functions = [this.options.talking_function];
|
|
111
|
-
completion_payload.function_call = {name: this.options.talking_function.name};
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
const completion = await this.generateCompletion(thread, completion_payload);
|
|
108
|
+
const completion = await this.generateCompletion(thread);
|
|
115
109
|
|
|
116
110
|
await this.handleCompletion(thread, completion);
|
|
117
111
|
|
|
@@ -125,29 +119,10 @@ export default class Agent {
|
|
|
125
119
|
}
|
|
126
120
|
}
|
|
127
121
|
|
|
128
|
-
async generateCompletion(thread,
|
|
122
|
+
async generateCompletion(thread, retry_counter = 1) {
|
|
129
123
|
try {
|
|
130
|
-
const
|
|
131
|
-
|
|
132
|
-
messages: thread.getMessagesJson(),
|
|
133
|
-
functions: await this.getFunctions(),
|
|
134
|
-
...payload,
|
|
135
|
-
};
|
|
136
|
-
|
|
137
|
-
if (!completion_payload.functions?.length) {
|
|
138
|
-
delete completion_payload.functions;
|
|
139
|
-
if (completion_payload.hasOwnProperty('function_call'))
|
|
140
|
-
delete completion_payload.function_call;
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
const openai = await Symposium.getOpenAi();
|
|
144
|
-
const chatCompletion = await openai.chat.completions.create(completion_payload);
|
|
145
|
-
|
|
146
|
-
let completion = chatCompletion.choices[0].message;
|
|
147
|
-
if (completion.function_call && completion.function_call.arguments)
|
|
148
|
-
completion.function_call.arguments = JSON.parse(completion.function_call.arguments);
|
|
149
|
-
|
|
150
|
-
return completion;
|
|
124
|
+
const model = Symposium.getModelByName(thread.state.model);
|
|
125
|
+
return model.generate(thread, await this.getFunctions())
|
|
151
126
|
} catch (error) {
|
|
152
127
|
if (error.response) {
|
|
153
128
|
console.error(error.response.status);
|
|
@@ -158,7 +133,7 @@ export default class Agent {
|
|
|
158
133
|
setTimeout(resolve, 1000);
|
|
159
134
|
});
|
|
160
135
|
|
|
161
|
-
return this.generateCompletion(thread,
|
|
136
|
+
return this.generateCompletion(thread, retry_counter + 1);
|
|
162
137
|
}
|
|
163
138
|
|
|
164
139
|
await thread.reply('# Errore ' + error.response.status + ': ' + JSON.stringify(error.response.data));
|
|
@@ -173,18 +148,11 @@ export default class Agent {
|
|
|
173
148
|
}
|
|
174
149
|
|
|
175
150
|
async handleCompletion(thread, completion) {
|
|
176
|
-
if (this.options.talking_function && completion.function_call) {
|
|
177
|
-
const text = completion.function_call.arguments[Object.keys(this.options.talking_function.parameters.properties)[0]];
|
|
178
|
-
thread.addAssistantMessage(text);
|
|
179
|
-
await this.log('ai_message', text);
|
|
180
|
-
await thread.reply(text);
|
|
181
|
-
return thread.storeState()
|
|
182
|
-
}
|
|
183
|
-
|
|
184
151
|
thread.addAssistantMessage(completion.content, completion.function_call ? {
|
|
185
152
|
...completion.function_call,
|
|
186
153
|
arguments: JSON.stringify(completion.function_call.arguments),
|
|
187
154
|
} : null);
|
|
155
|
+
|
|
188
156
|
if (completion.content) {
|
|
189
157
|
await this.log('ai_message', completion.content);
|
|
190
158
|
await thread.reply(completion.content);
|
package/Model.js
CHANGED
|
@@ -1,13 +1,17 @@
|
|
|
1
1
|
export default class Model {
|
|
2
|
+
vendor;
|
|
2
3
|
name;
|
|
3
4
|
name_for_tiktoken;
|
|
4
5
|
label;
|
|
5
6
|
tokens;
|
|
7
|
+
supports_tools = false;
|
|
6
8
|
|
|
7
|
-
constructor(
|
|
8
|
-
this.
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
constructor() {
|
|
10
|
+
if (!this.name_for_tiktoken)
|
|
11
|
+
this.name_for_tiktoken = this.name;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
async generate(thread) {
|
|
15
|
+
return null;
|
|
12
16
|
}
|
|
13
17
|
}
|
package/Symposium.js
CHANGED
|
@@ -1,40 +1,35 @@
|
|
|
1
1
|
import Redis from "@travio/redis";
|
|
2
2
|
import OpenAI from "openai";
|
|
3
|
-
import
|
|
3
|
+
import Gpt35 from "./models/Gpt35.js";
|
|
4
|
+
import Gpt4 from "./models/Gpt4.js";
|
|
5
|
+
import Gpt4Turbo from "./models/Gpt4Turbo.js";
|
|
6
|
+
import Gpt4Vision from "./models/Gpt4Vision.js";
|
|
4
7
|
|
|
5
8
|
export default class Symposium {
|
|
6
|
-
static
|
|
7
|
-
static models = [];
|
|
9
|
+
static models = new Map();
|
|
8
10
|
|
|
9
11
|
static async init() {
|
|
10
|
-
this.loadModel(new
|
|
11
|
-
this.loadModel(new
|
|
12
|
-
this.loadModel(new
|
|
13
|
-
this.loadModel(new
|
|
12
|
+
this.loadModel(new Gpt35());
|
|
13
|
+
this.loadModel(new Gpt4());
|
|
14
|
+
this.loadModel(new Gpt4Turbo());
|
|
15
|
+
this.loadModel(new Gpt4Vision());
|
|
14
16
|
|
|
15
17
|
return Redis.init();
|
|
16
18
|
}
|
|
17
19
|
|
|
18
20
|
static loadModel(model) {
|
|
19
|
-
this.models.
|
|
21
|
+
this.models.set(model.name, model);
|
|
20
22
|
}
|
|
21
23
|
|
|
22
|
-
static
|
|
23
|
-
|
|
24
|
-
this.openai = new OpenAI({apiKey: process.env.OPENAI_API_KEY});
|
|
25
|
-
|
|
26
|
-
return this.openai;
|
|
24
|
+
static getModelByName(name) {
|
|
25
|
+
return this.models.find(model => model.name === name);
|
|
27
26
|
}
|
|
28
27
|
|
|
29
28
|
static getModelByLabel(label) {
|
|
30
29
|
return this.models.find(model => model.label === label);
|
|
31
30
|
}
|
|
32
31
|
|
|
33
|
-
static
|
|
34
|
-
return this.models.find(model => model.name === name);
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
static async transcribe(agent, file, thread) {
|
|
32
|
+
/*static async transcribe(agent, file, thread) {
|
|
38
33
|
const words = await agent.getPromptWordsForTranscription(thread);
|
|
39
34
|
|
|
40
35
|
const response = await this.getOpenAi().then(openai => openai.audio.transcriptions.create({
|
|
@@ -43,5 +38,5 @@ export default class Symposium {
|
|
|
43
38
|
prompt: words.join(', '),
|
|
44
39
|
}));
|
|
45
40
|
return response.text;
|
|
46
|
-
}
|
|
41
|
+
}*/
|
|
47
42
|
}
|
package/models/Gpt35.js
ADDED
package/models/Gpt4.js
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import Model from "../Model.js";
|
|
2
|
+
import OpenAI from "openai";
|
|
3
|
+
|
|
4
|
+
export default class OpenAIModel extends Model {
|
|
5
|
+
openai;
|
|
6
|
+
vendor = 'openai';
|
|
7
|
+
supports_tools = true;
|
|
8
|
+
|
|
9
|
+
getOpenAi() {
|
|
10
|
+
if (!this.openai)
|
|
11
|
+
this.openai = new OpenAI({apiKey: process.env.OPENAI_API_KEY});
|
|
12
|
+
|
|
13
|
+
return this.openai;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
async generate(thread, functions = []) {
|
|
17
|
+
const completion_payload = {
|
|
18
|
+
model: this.name,
|
|
19
|
+
messages: thread.getMessagesJson(),
|
|
20
|
+
functions,
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
if (!completion_payload.functions?.length) {
|
|
24
|
+
delete completion_payload.functions;
|
|
25
|
+
if (completion_payload.hasOwnProperty('function_call'))
|
|
26
|
+
delete completion_payload.function_call;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const chatCompletion = await this.getOpenAi().chat.completions.create(completion_payload);
|
|
30
|
+
|
|
31
|
+
const completion = chatCompletion.choices[0].message;
|
|
32
|
+
if (completion.function_call && completion.function_call.arguments)
|
|
33
|
+
completion.function_call.arguments = JSON.parse(completion.function_call.arguments);
|
|
34
|
+
|
|
35
|
+
return completion;
|
|
36
|
+
}
|
|
37
|
+
}
|