@greeneyesai/toolkit
v1.1.0
Published
Helper classes for GreenEyes.AI REST API.
Maintainers
Readme
GreenEyes.AI API Toolkit
Helper classes for GreenEyes.AI REST API.
Usage
import * as events from "events";
import {
APIClient,
QueuedExecutor,
QueuedExecutorDelegate,
QueuedExecutorEvents
} from "@greeneyesai/toolkit"
...
const client = new APIClient(appId, appSecret);
const { maxConcurrency } = await client.authenticate();
...
type ArgsType = [string, { internalId: string; }];
const delegate: QueuedExecutorDelegate<ArgsType> = {
exec: async (...args: ArgsType): Promise<void> => {
try {
const { object } = await client.storeObject({
src: args[0],
meta: args[1];
});
// process object.id
// ...
} catch (e) {
console.error(e);
// ...
}
}
};
const executor = new QueuedExecutor<ArgsType>(
maxConcurrency,
100, // request throtling in ms
delegate
);
...
executor.push(src, meta);
...
executor.inputStreamClosed();
...
await events.once(executor, QueuedExecutorEvents.Finished);
// Import finishedNote: feel free to use any form of pagination when pushing to the executor, the executor emits QueuedExecutorEvents.BufferEmpty event when the page is processed and if the inputStreamClosed has not been called prior.
License
GNU Lesser General Public License v3.0
© GreenEyes Artificial Intelligence Services, LLC.
