symposium 0.9.4 → 0.9.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 +26 -6
- package/package.json +1 -1
package/Agent.js
CHANGED
|
@@ -8,7 +8,8 @@ export default class Agent {
|
|
|
8
8
|
threads;
|
|
9
9
|
functions = null;
|
|
10
10
|
tools = new Map();
|
|
11
|
-
default_model = 'gpt-
|
|
11
|
+
default_model = 'gpt-4o';
|
|
12
|
+
max_retries = 5;
|
|
12
13
|
|
|
13
14
|
constructor(options) {
|
|
14
15
|
this.options = {
|
|
@@ -88,26 +89,45 @@ export default class Agent {
|
|
|
88
89
|
await this.execute(thread);
|
|
89
90
|
}
|
|
90
91
|
|
|
91
|
-
async
|
|
92
|
+
async beforeExecute(thread) {
|
|
92
93
|
if (this.options.memory_handler)
|
|
93
94
|
thread = await this.options.memory_handler.handle(thread);
|
|
95
|
+
return thread;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
async execute(thread, counter = 0) {
|
|
99
|
+
if (counter === 0)
|
|
100
|
+
thread = await this.beforeExecute(thread);
|
|
94
101
|
|
|
95
102
|
const completion = await this.generateCompletion(thread);
|
|
96
|
-
if (completion)
|
|
97
|
-
|
|
103
|
+
if (completion) {
|
|
104
|
+
try {
|
|
105
|
+
thread = await this.afterExecute(thread, completion);
|
|
106
|
+
await this.handleCompletion(thread, completion);
|
|
107
|
+
} catch (e) {
|
|
108
|
+
console.error(e);
|
|
109
|
+
|
|
110
|
+
if (counter < this.max_retries)
|
|
111
|
+
await this.execute(thread, counter + 1);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
async afterExecute(thread, completion) {
|
|
117
|
+
return thread;
|
|
98
118
|
}
|
|
99
119
|
|
|
100
120
|
async generateCompletion(thread, options = {}, retry_counter = 1) {
|
|
101
121
|
try {
|
|
102
122
|
const model = Symposium.getModelByName(thread.state.model);
|
|
103
123
|
const messages = await model.generate(thread, await this.getFunctions(), options);
|
|
104
|
-
return
|
|
124
|
+
return model.supports_functions ? messages : messages.map(m => this.parseFunctions(m));
|
|
105
125
|
} catch (error) {
|
|
106
126
|
if (error.response) {
|
|
107
127
|
console.error(error.response.status);
|
|
108
128
|
console.error(error.response.data);
|
|
109
129
|
|
|
110
|
-
if (error.response.status >= 500 && retry_counter <=
|
|
130
|
+
if (error.response.status >= 500 && retry_counter <= this.max_retries) {
|
|
111
131
|
await new Promise(resolve => {
|
|
112
132
|
setTimeout(resolve, 1000);
|
|
113
133
|
});
|