- Added multi-provider AI infrastructure (OpenAI/Ollama) - Implemented real-time tag suggestions with debounced analysis - Created AI diagnostics and database maintenance tools in Settings - Added automated garbage collection for orphan labels - Refined UX with deterministic color hashing and interactive ghost tags
47 lines
1.3 KiB
TypeScript
47 lines
1.3 KiB
TypeScript
import { openai } from '@ai-sdk/openai';
|
|
import { generateObject, embed } from 'ai';
|
|
import { z } from 'zod';
|
|
import { AIProvider, TagSuggestion } from '../types';
|
|
|
|
export class OpenAIProvider implements AIProvider {
|
|
private model: any;
|
|
|
|
constructor(apiKey: string, modelName: string = 'gpt-4o-mini') {
|
|
this.model = openai(modelName);
|
|
}
|
|
|
|
async generateTags(content: string): Promise<TagSuggestion[]> {
|
|
try {
|
|
const { object } = await generateObject({
|
|
model: this.model,
|
|
schema: z.object({
|
|
tags: z.array(z.object({
|
|
tag: z.string().describe('Le nom du tag, court et en minuscules'),
|
|
confidence: z.number().min(0).max(1).describe('Le niveau de confiance entre 0 et 1')
|
|
}))
|
|
}),
|
|
prompt: `Analyse la note suivante et suggère entre 1 et 5 tags pertinents.
|
|
Contenu de la note: "${content}"`,
|
|
});
|
|
|
|
return object.tags;
|
|
} catch (e) {
|
|
console.error('Erreur génération tags OpenAI:', e);
|
|
return [];
|
|
}
|
|
}
|
|
|
|
async getEmbeddings(text: string): Promise<number[]> {
|
|
try {
|
|
const { embedding } = await embed({
|
|
model: openai.embedding('text-embedding-3-small'),
|
|
value: text,
|
|
});
|
|
return embedding;
|
|
} catch (e) {
|
|
console.error('Erreur embeddings OpenAI:', e);
|
|
return [];
|
|
}
|
|
}
|
|
}
|