UNPKG

@waldzellai/adk-typescript

Version:

TypeScript SDK for Google Agent Development Kit (ADK) - A comprehensive framework for building AI agents

72 lines (71 loc) 2.56 kB
"use strict"; // Model registry module for the Google Agent Development Kit (ADK) in TypeScript // Mirrors the registry functionality from the Python SDK Object.defineProperty(exports, "__esModule", { value: true }); exports.LlmRegistry = void 0; const gemini_llm_1 = require("./gemini_llm"); const openai_llm_1 = require("./openai_llm"); /** * Registry for LLM implementations. * Maps model name patterns to LLM implementations. */ class LlmRegistry { /** * Registers a model pattern with an LLM implementation. * * @param pattern Regex pattern for model names * @param llmClass LLM class constructor */ static register(pattern, llmClass) { const regex = new RegExp(`^${pattern}$`); LlmRegistry.registry.set(regex, llmClass); } /** * Resolves a model name to an LLM implementation. * * @param model Model name * @param options Additional options for the LLM constructor * @returns An instance of the appropriate LLM implementation * @throws Error if no implementation is found for the model */ static resolve(model, options) { for (const [pattern, LlmClass] of LlmRegistry.registry.entries()) { if (pattern.test(model)) { // Provide default for contents if options or options.contents is undefined const constructorOptions = { ...options, model, contents: options?.contents ?? [], }; return new LlmClass(constructorOptions); } } throw new Error(`No LLM implementation found for model: ${model}`); } /** * Creates a new LLM instance for the given model. * * @param model Model name * @param options Additional options for the LLM constructor * @returns An instance of the appropriate LLM implementation */ static createLlm(model, options) { return LlmRegistry.resolve(model, options); } } exports.LlmRegistry = LlmRegistry; // Registry mapping regex patterns to LLM class constructors LlmRegistry.registry = new Map(); /** * Initializes the registry with default implementations. */ (() => { // Register Gemini models for (const pattern of gemini_llm_1.GeminiLlm.supportedModels()) { LlmRegistry.register(pattern, gemini_llm_1.GeminiLlm); } // Register OpenAI models for (const pattern of openai_llm_1.OpenAiLlm.supportedModels()) { LlmRegistry.register(pattern, openai_llm_1.OpenAiLlm); } })();