import { ConfigService } from '@nestjs/config'; import { anthropic } from '@ai-sdk/anthropic'; import { openai } from '@ai-sdk/openai'; import type { LanguageModel } from 'ai'; export function createAiModel(config: ConfigService): LanguageModel | null { const provider = config.get('ai.provider') ?? 'openai'; const model = config.get('ai.model') ?? 'gpt-4o-mini'; if (provider === 'anthropic') { const apiKey = config.get('ai.anthropicApiKey'); if (!apiKey) return null; return anthropic(model); } // Default to openai const apiKey = config.get('ai.openaiApiKey'); if (!apiKey) return null; return openai(model); } export function isAiConfigured(config: ConfigService): boolean { const provider = config.get('ai.provider') ?? 'openai'; if (provider === 'anthropic') return !!config.get('ai.anthropicApiKey'); return !!config.get('ai.openaiApiKey'); }