@composableai/cli
Version:
Code generation for the interaction defined with Composable AI Studio
83 lines • 2.7 kB
JavaScript
export class ExecutionQueue {
constructor(size = 4) {
Object.defineProperty(this, "size", {
enumerable: true,
configurable: true,
writable: true,
value: size
});
Object.defineProperty(this, "requests", {
enumerable: true,
configurable: true,
writable: true,
value: []
});
}
add(request) {
this.requests.push(request);
}
async run(onBatch, onChunk) {
const chunkSize = this.size;
const out = [];
const requests = this.requests;
for (let i = 0; i < requests.length; i += chunkSize) {
const chunk = requests.slice(i, i + chunkSize);
const res = await Promise.all(chunk.map(request => request.run(onChunk)));
out.push(...res);
onBatch(out);
}
return out;
}
}
export class ExecutionRequest {
constructor(client, interactionId, data, options) {
Object.defineProperty(this, "client", {
enumerable: true,
configurable: true,
writable: true,
value: client
});
Object.defineProperty(this, "interactionId", {
enumerable: true,
configurable: true,
writable: true,
value: interactionId
});
Object.defineProperty(this, "data", {
enumerable: true,
configurable: true,
writable: true,
value: data
});
Object.defineProperty(this, "options", {
enumerable: true,
configurable: true,
writable: true,
value: options
});
Object.defineProperty(this, "runNumber", {
enumerable: true,
configurable: true,
writable: true,
value: void 0
});
}
async run(onChunk) {
const options = this.options;
const run = await this.client.interactions.execute(this.interactionId, {
data: this.data,
config: {
environment: typeof options.env === 'string' ? options.env : undefined,
model: typeof options.model === 'string' ? options.model : undefined,
temperature: typeof options.temperature === 'string' ? parseFloat(options.temperature) : undefined,
},
tags: options.tags ? options.tags.trim().split(/\s,*\s*/) : undefined
}, onChunk);
// add count number in the run
if (this.runNumber != null) {
run.runNumber = this.runNumber;
}
return run;
}
}
//# sourceMappingURL=executor.js.map