CognxSafeTrack
chore: execute Sprint 38 technical debt resolution (Type Safety, Zod validation, Vitest, Mock LLM extracted)
d9879cf | import { LLMProvider, OnePagerSchema, PitchDeckSchema, PersonalizedLessonSchema, FeedbackSchema } from './types'; | |
| import { | |
| MOCK_ONE_PAGER_CEREAL, MOCK_ONE_PAGER_FISH, MOCK_ONE_PAGER_COUTURE, | |
| MOCK_DECK_CEREAL, MOCK_DECK_FISH, MOCK_DECK_COUTURE, | |
| MOCK_FEEDBACK | |
| } from './__fixtures__/mock-data'; | |
| /** | |
| * A Provider for local development that doesn't require an API Key. | |
| * It ignores the prompt and returns dummy data matching the requested schema. | |
| */ | |
| export class MockLLMProvider implements LLMProvider { | |
| async generateStructuredData<T>(prompt: string, schema: any): Promise<T> { | |
| console.log('[MOCK LLM] Prompt received:', prompt.substring(0, 100) + '...'); | |
| const isFish = prompt.includes('Kayar') || prompt.includes('Poisson') || prompt.includes('transformation'); | |
| const isCereal = prompt.includes('Kaolack') || prompt.includes('Céréales') || prompt.includes('mils'); | |
| if (schema === OnePagerSchema) { | |
| if (isCereal) return schema.parse(MOCK_ONE_PAGER_CEREAL) as any; | |
| if (isFish) return schema.parse(MOCK_ONE_PAGER_FISH) as any; | |
| return schema.parse(MOCK_ONE_PAGER_COUTURE) as any; | |
| } | |
| if (schema === PitchDeckSchema) { | |
| if (isCereal) return schema.parse(MOCK_DECK_CEREAL) as any; | |
| if (isFish) return schema.parse(MOCK_DECK_FISH) as any; | |
| return schema.parse(MOCK_DECK_COUTURE) as any; | |
| } | |
| if (schema === PersonalizedLessonSchema) { | |
| return schema.parse({ | |
| lessonText: `Voici une leçon adaptée à votre secteur (${isFish ? 'Poisson' : isCereal ? 'Céréales' : 'Mode'}): Pensez à votre entreprise comme un moteur de valeur locale...` | |
| }) as any; | |
| } | |
| if (schema === FeedbackSchema) { | |
| return schema.parse(MOCK_FEEDBACK) as any; | |
| } | |
| throw new Error("MockLLMProvider does not support this schema."); | |
| } | |
| async transcribeAudio(_audioBuffer: Buffer, filename: string): Promise<{ text: string, confidence: number }> { | |
| console.log(`[MOCK LLM] Transcribing audio from ${filename}...`); | |
| return { text: "INSCRIPTION", confidence: 100 }; | |
| } | |
| async generateSpeech(text: string): Promise<Buffer> { | |
| console.log(`[MOCK LLM] Generating speech for text: ${text.substring(0, 30)}...`); | |
| return Buffer.from("mock_audio_data"); | |
| } | |
| async generateImage(prompt: string): Promise<string> { | |
| console.log(`[MOCK LLM] Generating image for prompt: ${prompt.substring(0, 30)}...`); | |
| return "https://via.placeholder.com/1024x1024.png?text=Mock+AI+Image"; | |
| } | |
| } | |