symposium 0.9.4 → 0.9.5

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.
Files changed (2) hide show
  1. package/Agent.js +25 -5
  2. package/package.json +1 -1
package/Agent.js CHANGED
@@ -9,6 +9,7 @@ export default class Agent {
9
9
  functions = null;
10
10
  tools = new Map();
11
11
  default_model = 'gpt-4-turbo';
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 execute(thread) {
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
- await this.handleCompletion(thread, completion);
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 messages.map(m => model.supports_functions ? m : this.parseFunctions(m));
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 <= 5) {
130
+ if (error.response.status >= 500 && retry_counter <= this.max_retries) {
111
131
  await new Promise(resolve => {
112
132
  setTimeout(resolve, 1000);
113
133
  });
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "type": "module",
3
3
  "name": "symposium",
4
- "version": "0.9.4",
4
+ "version": "0.9.5",
5
5
  "description": "Agents",
6
6
  "main": "index.js",
7
7
  "author": "Domenico Giambra",