mirror of
https://dev.azure.com/globalhealthx/EMR/_git/helix-engage-server
synced 2026-04-11 18:08:16 +00:00
- Replace raw @anthropic-ai/sdk with Vercel AI SDK (generateText, tool, generateObject) - Add provider abstraction (ai-provider.ts) — swap OpenAI/Anthropic via env var - AI chat controller: dynamic KB from platform (clinics, packages, insurance), zero hardcoding - AI enrichment service: use generateObject with Zod schema instead of manual JSON parsing - Worklist: resolve agent name from platform currentUser API instead of JWT decode - Worklist: fix GraphQL field names to match platform remapping (source, status, direction, etc.) - Config: add AI_PROVIDER, AI_MODEL, OPENAI_API_KEY env vars Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
27 lines
980 B
TypeScript
27 lines
980 B
TypeScript
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<string>('ai.provider') ?? 'openai';
|
|
const model = config.get<string>('ai.model') ?? 'gpt-4o-mini';
|
|
|
|
if (provider === 'anthropic') {
|
|
const apiKey = config.get<string>('ai.anthropicApiKey');
|
|
if (!apiKey) return null;
|
|
return anthropic(model);
|
|
}
|
|
|
|
// Default to openai
|
|
const apiKey = config.get<string>('ai.openaiApiKey');
|
|
if (!apiKey) return null;
|
|
return openai(model);
|
|
}
|
|
|
|
export function isAiConfigured(config: ConfigService): boolean {
|
|
const provider = config.get<string>('ai.provider') ?? 'openai';
|
|
if (provider === 'anthropic') return !!config.get<string>('ai.anthropicApiKey');
|
|
return !!config.get<string>('ai.openaiApiKey');
|
|
}
|