@genkit-ai/ai
Version:
Genkit AI framework generative AI APIs.
114 lines • 3.77 kB
JavaScript
;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var genkit_ai_exports = {};
__export(genkit_ai_exports, {
GenkitAI: () => GenkitAI
});
module.exports = __toCommonJS(genkit_ai_exports);
var import_core = require("@genkit-ai/core");
var import_cancel_operation = require("./cancel-operation.js");
var import_check_operation = require("./check-operation.js");
var import_embedder = require("./embedder.js");
var import_generate = require("./generate.js");
class GenkitAI {
registry;
constructor(registry) {
this.registry = registry;
}
/**
* Embeds the given `content` using the specified `embedder`.
*/
embed(params) {
return (0, import_embedder.embed)(this.registry, params);
}
/**
* A veneer for interacting with embedder models in bulk.
*/
embedMany(params) {
return (0, import_embedder.embedMany)(this.registry, params);
}
async generate(options) {
let resolvedOptions;
if (options instanceof Promise) {
resolvedOptions = await options;
} else if (typeof options === "string" || Array.isArray(options)) {
resolvedOptions = {
prompt: options
};
} else {
resolvedOptions = options;
}
return (0, import_generate.generate)(this.registry, resolvedOptions);
}
generateStream(options) {
if (typeof options === "string" || Array.isArray(options)) {
options = { prompt: options };
}
return (0, import_generate.generateStream)(this.registry, options);
}
/**
* Checks the status of of a given operation. Returns a new operation which will contain the updated status.
*
* ```ts
* let operation = await ai.generateOperation({
* model: googleAI.model('veo-2.0-generate-001'),
* prompt: 'A banana riding a bicycle.',
* });
*
* while (!operation.done) {
* operation = await ai.checkOperation(operation!);
* await new Promise((resolve) => setTimeout(resolve, 5000));
* }
* ```
*
* @param operation
* @returns
*/
checkOperation(operation) {
return (0, import_check_operation.checkOperation)(this.registry, operation);
}
/**
* Cancels a given operation. Returns a new operation which will contain the updated status.
*
* @param operation
* @returns
*/
cancelOperation(operation) {
return (0, import_cancel_operation.cancelOperation)(this.registry, operation);
}
run(name, funcOrInput, maybeFunc) {
if (maybeFunc) {
return (0, import_core.run)(name, funcOrInput, maybeFunc, this.registry);
}
return (0, import_core.run)(name, funcOrInput, this.registry);
}
/**
* Returns current action (or flow) invocation context. Can be used to access things like auth
* data set by HTTP server frameworks. If invoked outside of an action (e.g. flow or tool) will
* return `undefined`.
*/
currentContext() {
return (0, import_core.getContext)();
}
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
GenkitAI
});
//# sourceMappingURL=genkit-ai.js.map