symposium 0.12.5 → 0.12.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 +40 -3
- package/models/OpenAIModel.js +3 -0
- package/package.json +1 -1
package/Agent.js
CHANGED
|
@@ -115,13 +115,16 @@ export default class Agent {
|
|
|
115
115
|
if (!this.utility.function || !this.utility.function.name || !this.utility.function.parameters)
|
|
116
116
|
throw new Error('Bad function definition');
|
|
117
117
|
|
|
118
|
-
|
|
119
|
-
|
|
118
|
+
let response_format = null;
|
|
119
|
+
if (model.supports_structured_output)
|
|
120
|
+
response_format = this.convertFunctionToResponseFormat(this.utility.function.parameters);
|
|
121
|
+
|
|
122
|
+
if (response_format && response_format.count <= 100) { // Se ci sono più di 100 parametri, OpenAI non supporta gli structured output
|
|
120
123
|
completion_options.response_format = {
|
|
121
124
|
type: 'json_schema',
|
|
122
125
|
json_schema: {
|
|
123
126
|
name: this.utility.function.name,
|
|
124
|
-
schema:
|
|
127
|
+
schema: response_format.obj,
|
|
125
128
|
strict: true,
|
|
126
129
|
},
|
|
127
130
|
};
|
|
@@ -161,6 +164,40 @@ export default class Agent {
|
|
|
161
164
|
}
|
|
162
165
|
}
|
|
163
166
|
|
|
167
|
+
convertFunctionToResponseFormat(obj) {
|
|
168
|
+
if (obj.type !== 'object')
|
|
169
|
+
return {obj, count: 0};
|
|
170
|
+
|
|
171
|
+
let properties_count = 0, required = [];
|
|
172
|
+
|
|
173
|
+
for (let [key, property] of Object.entries(obj.properties || {})) {
|
|
174
|
+
properties_count++;
|
|
175
|
+
required.push(key);
|
|
176
|
+
|
|
177
|
+
if (property.type === 'object') {
|
|
178
|
+
const {obj: subobj, count} = this.convertFunctionToResponseFormat(property);
|
|
179
|
+
obj.properties[key] = subobj;
|
|
180
|
+
properties_count += count;
|
|
181
|
+
} else if (property.type === 'array' && property.items.type === 'object') {
|
|
182
|
+
const {obj: subobj, count} = this.convertFunctionToResponseFormat(property.items);
|
|
183
|
+
obj.properties[key] = {
|
|
184
|
+
type: 'array',
|
|
185
|
+
items: subobj,
|
|
186
|
+
};
|
|
187
|
+
properties_count += count;
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
return {
|
|
192
|
+
obj: {
|
|
193
|
+
...obj,
|
|
194
|
+
additionalProperties: false,
|
|
195
|
+
required,
|
|
196
|
+
},
|
|
197
|
+
count: properties_count,
|
|
198
|
+
};
|
|
199
|
+
}
|
|
200
|
+
|
|
164
201
|
async afterExecute(thread, completion) {
|
|
165
202
|
return thread;
|
|
166
203
|
}
|
package/models/OpenAIModel.js
CHANGED