UNPKG

@genkit-ai/anthropic

Version:

Genkit AI framework plugin for Anthropic APIs.

136 lines 5.26 kB
"use strict"; 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 types_exports = {}; __export(types_exports, { AnthropicBaseConfigSchema: () => AnthropicBaseConfigSchema, AnthropicConfigSchema: () => AnthropicConfigSchema, AnthropicThinkingConfigSchema: () => AnthropicThinkingConfigSchema, MEDIA_TYPES: () => MEDIA_TYPES, MediaSchema: () => MediaSchema, MediaTypeSchema: () => MediaTypeSchema, ThinkingConfigSchema: () => ThinkingConfigSchema, __testClient: () => __testClient, resolveBetaEnabled: () => resolveBetaEnabled }); module.exports = __toCommonJS(types_exports); var import_genkit = require("genkit"); var import_model = require("genkit/model"); const __testClient = /* @__PURE__ */ Symbol("testClient"); const ThinkingConfigSchema = import_genkit.z.object({ enabled: import_genkit.z.boolean().optional(), budgetTokens: import_genkit.z.number().min(1024).optional(), adaptive: import_genkit.z.boolean().optional(), display: import_genkit.z.enum(["summarized", "omitted"]).optional() }).passthrough().superRefine((value, ctx) => { if (value.enabled && value.adaptive) { ctx.addIssue({ code: import_genkit.z.ZodIssueCode.custom, path: ["adaptive"], message: "Cannot use both enabled and adaptive thinking modes simultaneously" }); } if (value.enabled) { if (value.budgetTokens === void 0) { ctx.addIssue({ code: import_genkit.z.ZodIssueCode.custom, path: ["budgetTokens"], message: "budgetTokens is required when thinking is enabled" }); } else if (!Number.isInteger(value.budgetTokens)) { ctx.addIssue({ code: import_genkit.z.ZodIssueCode.custom, path: ["budgetTokens"], message: "budgetTokens must be an integer" }); } } }); const AnthropicConfigSchema = import_model.GenerationCommonConfigSchema.extend({ tool_choice: import_genkit.z.union([ import_genkit.z.object({ type: import_genkit.z.literal("auto") }).passthrough(), import_genkit.z.object({ type: import_genkit.z.literal("any") }).passthrough(), import_genkit.z.object({ type: import_genkit.z.literal("tool"), name: import_genkit.z.string() }).passthrough() ]).describe( "The tool choice to use for the request. This can be used to specify the tool to use for the request. If not specified, the model will choose the tool to use." ).optional(), metadata: import_genkit.z.object({ user_id: import_genkit.z.string().optional() }).describe("The metadata to include in the request.").passthrough().optional(), /** Optional shorthand to pick API surface for this request. */ apiVersion: import_genkit.z.enum(["stable", "beta"]).optional().describe( "The API version to use for the request. Both stable and beta features are available on the beta API surface." ), thinking: ThinkingConfigSchema.optional().describe( "The thinking configuration to use for the request. Thinking is a feature that allows the model to think about the request and provide a better response." ), output_config: import_genkit.z.object({ effort: import_genkit.z.enum(["low", "medium", "high", "xhigh"]).optional(), task_budget: import_genkit.z.object({ type: import_genkit.z.literal("tokens").default("tokens"), total: import_genkit.z.number().min(2e4) }).optional() }).passthrough().describe( "Configuration for output generation, such as setting the effort parameter and task budgets." ).optional() }).passthrough(); const AnthropicBaseConfigSchema = AnthropicConfigSchema; const AnthropicThinkingConfigSchema = AnthropicConfigSchema; const MediaSchema = import_genkit.z.object({ url: import_genkit.z.string(), contentType: import_genkit.z.string().optional() }); const MediaTypeSchema = import_genkit.z.enum([ "image/jpeg", "image/png", "image/gif", "image/webp" ]); const MEDIA_TYPES = { JPEG: "image/jpeg", PNG: "image/png", GIF: "image/gif", WEBP: "image/webp" }; function resolveBetaEnabled(cfg, pluginDefaultApiVersion) { if (cfg?.apiVersion !== void 0) { return cfg.apiVersion === "beta"; } if (pluginDefaultApiVersion === "beta") return true; return false; } // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { AnthropicBaseConfigSchema, AnthropicConfigSchema, AnthropicThinkingConfigSchema, MEDIA_TYPES, MediaSchema, MediaTypeSchema, ThinkingConfigSchema, __testClient, resolveBetaEnabled }); //# sourceMappingURL=types.js.map