genkitx-anthropic
Version:
Firebase Genkit AI framework plugin for Anthropic APIs.
90 lines • 2.48 kB
JavaScript
import {
__async
} from "./chunk-MLCSNVBT.mjs";
import { genkitPluginV2, modelActionMetadata } from "genkit/plugin";
import Anthropic from "@anthropic-ai/sdk";
import {
claude4Sonnet,
claude4Opus,
claude37Sonnet,
claude35Sonnet,
claude3Opus,
claude3Sonnet,
claude3Haiku,
claude35Haiku,
claude45Sonnet,
claude45Haiku,
claude45Opus,
claudeModel,
SUPPORTED_CLAUDE_MODELS
} from "./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 = SUPPORTED_CLAUDE_MODELS[normalizedId];
return ref ? 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 Anthropic({ apiKey, defaultHeaders });
let listActionsCache = null;
return genkitPluginV2({
name: "anthropic",
init: () => __async(void 0, null, function* () {
const actions = [];
for (const name of Object.keys(SUPPORTED_CLAUDE_MODELS)) {
const action = claudeModel(name, client, options == null ? void 0 : options.cacheSystemPrompt);
actions.push(action);
}
return actions;
}),
resolve: (actionType, name) => {
if (actionType === "model") {
return 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;
export {
anthropic,
claude35Haiku,
claude35Sonnet,
claude37Sonnet,
claude3Haiku,
claude3Opus,
claude3Sonnet,
claude45Haiku,
claude45Opus,
claude45Sonnet,
claude4Opus,
claude4Sonnet,
src_default as default
};
//# sourceMappingURL=index.mjs.map