(toolName: ToolName)
| 89 | |
| 90 | // Get model instance |
| 91 | export function getModel(toolName: ToolName) { |
| 92 | const config = getToolConfig(toolName); |
| 93 | const providerConfig = (configJson.providers as Record<string, ProviderConfig | undefined>)[LLM_PROVIDER]; |
| 94 | |
| 95 | if (LLM_PROVIDER === 'openai') { |
| 96 | if (!OPENAI_API_KEY) { |
| 97 | throw new Error('OPENAI_API_KEY not found'); |
| 98 | } |
| 99 | |
| 100 | const opt: OpenAIProviderSettings = { |
| 101 | apiKey: OPENAI_API_KEY, |
| 102 | compatibility: providerConfig?.clientConfig?.compatibility |
| 103 | }; |
| 104 | |
| 105 | if (OPENAI_BASE_URL) { |
| 106 | opt.baseURL = OPENAI_BASE_URL; |
| 107 | } |
| 108 | |
| 109 | return createOpenAI(opt)(config.model); |
| 110 | } |
| 111 | |
| 112 | if (LLM_PROVIDER === 'vertex') { |
| 113 | const createVertex = require('@ai-sdk/google-vertex').createVertex; |
| 114 | if (toolName === 'searchGrounding') { |
| 115 | return createVertex({ project: process.env.GCLOUD_PROJECT, ...providerConfig?.clientConfig })(config.model, { useSearchGrounding: true }); |
| 116 | } |
| 117 | return createVertex({ project: process.env.GCLOUD_PROJECT, ...providerConfig?.clientConfig })(config.model); |
| 118 | } |
| 119 | |
| 120 | if (!GEMINI_API_KEY) { |
| 121 | throw new Error('GEMINI_API_KEY not found'); |
| 122 | } |
| 123 | |
| 124 | if (toolName === 'searchGrounding') { |
| 125 | return createGoogleGenerativeAI({ apiKey: GEMINI_API_KEY })(config.model, { useSearchGrounding: true }); |
| 126 | } |
| 127 | return createGoogleGenerativeAI({ apiKey: GEMINI_API_KEY })(config.model); |
| 128 | } |
| 129 | |
| 130 | // Validate required environment variables |
| 131 | if (LLM_PROVIDER === 'gemini' && !GEMINI_API_KEY) throw new Error("GEMINI_API_KEY not found"); |
no test coverage detected