UNPKG

@genkit-ai/anthropic

Version:

Genkit AI framework plugin for Anthropic APIs.

103 lines 3.72 kB
"use strict"; var __create = Object.create; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __getProtoOf = Object.getPrototypeOf; 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 __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( // If the importer is in node compatibility mode or this is not an ESM // file that has been converted to a CommonJS file using a Babel- // compatible transform (i.e. "__esModule" has not been set), then set // "default" to the CommonJS "module.exports" for node compatibility. isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod )); var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); var index_exports = {}; __export(index_exports, { anthropic: () => anthropic, anthropicDocument: () => anthropicDocument, cacheControl: () => import_utils.cacheControl, default: () => index_default }); module.exports = __toCommonJS(index_exports); var import_sdk = __toESM(require("@anthropic-ai/sdk")); var import_plugin = require("genkit/plugin"); var import_list = require("./list.js"); var import_models = require("./models.js"); var import_types = require("./types.js"); var import_utils = require("./utils.js"); function getAnthropicClient(options) { const internalOptions = options; if (internalOptions?.[import_types.__testClient]) { return internalOptions[import_types.__testClient]; } const apiKey = options?.apiKey || process.env.ANTHROPIC_API_KEY; if (!apiKey) { throw new Error( "Please pass in the API key or set the ANTHROPIC_API_KEY environment variable" ); } return new import_sdk.default({ apiKey }); } function anthropicPlugin(options) { const client = getAnthropicClient(options); const defaultApiVersion = options?.apiVersion; let listActionsCache = null; return (0, import_plugin.genkitPluginV2)({ name: "anthropic", init: async () => { const actions = []; actions.push(...(0, import_models.listKnownModels)(client, defaultApiVersion)); return actions; }, resolve: (actionType, name) => { if (actionType === "model") { const modelName = name.startsWith("anthropic/") ? name.slice(10) : name; return (0, import_models.claudeModel)({ name: modelName, client, defaultApiVersion }); } return void 0; }, list: async () => { if (listActionsCache) return listActionsCache; listActionsCache = await (0, import_list.listActions)(client); return listActionsCache; } }); } const anthropic = anthropicPlugin; anthropic.model = (name, config) => { return (0, import_models.claudeModelReference)(name, config); }; function anthropicDocument(options) { return { custom: { anthropicDocument: options } }; } var index_default = anthropic; // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { anthropic, anthropicDocument, cacheControl }); //# sourceMappingURL=index.js.map