genkitx-anthropic
Version:
Firebase Genkit AI framework plugin for Anthropic APIs.
138 lines • 5.04 kB
JavaScript
;
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 __async = (__this, __arguments, generator) => {
return new Promise((resolve, reject) => {
var fulfilled = (value) => {
try {
step(generator.next(value));
} catch (e) {
reject(e);
}
};
var rejected = (value) => {
try {
step(generator.throw(value));
} catch (e) {
reject(e);
}
};
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
step((generator = generator.apply(__this, __arguments)).next());
});
};
var src_exports = {};
__export(src_exports, {
anthropic: () => anthropic,
claude35Haiku: () => import_claude.claude35Haiku,
claude35Sonnet: () => import_claude.claude35Sonnet,
claude37Sonnet: () => import_claude.claude37Sonnet,
claude3Haiku: () => import_claude.claude3Haiku,
claude3Opus: () => import_claude.claude3Opus,
claude3Sonnet: () => import_claude.claude3Sonnet,
claude45Haiku: () => import_claude.claude45Haiku,
claude45Opus: () => import_claude.claude45Opus,
claude45Sonnet: () => import_claude.claude45Sonnet,
claude4Opus: () => import_claude.claude4Opus,
claude4Sonnet: () => import_claude.claude4Sonnet,
default: () => src_default
});
module.exports = __toCommonJS(src_exports);
var import_plugin = require("genkit/plugin");
var import_sdk = __toESM(require("@anthropic-ai/sdk"));
var import_claude = require("./claude.js");
function list(client) {
return __async(this, null, function* () {
const clientModels = (yield client.models.list()).data;
return clientModels.map((modelInfo) => {
const normalizedId = modelInfo.id.replace(/-\d{8}$/, "");
const ref = import_claude.SUPPORTED_CLAUDE_MODELS[normalizedId];
return ref ? (0, import_plugin.modelActionMetadata)({
name: ref.name,
info: ref.info,
configSchema: ref.configSchema
}) : void 0;
}).filter((metadata) => metadata !== void 0);
});
}
const anthropic = (options) => {
let apiKey = (options == null ? void 0 : 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"
);
}
let defaultHeaders = {};
if ((options == null ? void 0 : options.cacheSystemPrompt) == true) {
defaultHeaders["anthropic-beta"] = "prompt-caching-2024-07-31";
}
const client = new import_sdk.default({ apiKey, defaultHeaders });
let listActionsCache = null;
return (0, import_plugin.genkitPluginV2)({
name: "anthropic",
init: () => __async(void 0, null, function* () {
const actions = [];
for (const name of Object.keys(import_claude.SUPPORTED_CLAUDE_MODELS)) {
const action = (0, import_claude.claudeModel)(name, client, options == null ? void 0 : options.cacheSystemPrompt);
actions.push(action);
}
return actions;
}),
resolve: (actionType, name) => {
if (actionType === "model") {
return (0, import_claude.claudeModel)(
name,
client
);
}
return void 0;
},
list: () => __async(void 0, null, function* () {
if (listActionsCache) return listActionsCache;
listActionsCache = yield list(client);
return listActionsCache;
})
});
};
var src_default = anthropic;
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
anthropic,
claude35Haiku,
claude35Sonnet,
claude37Sonnet,
claude3Haiku,
claude3Opus,
claude3Sonnet,
claude45Haiku,
claude45Opus,
claude45Sonnet,
claude4Opus,
claude4Sonnet
});
//# sourceMappingURL=index.js.map