feat(ai): implement intelligent auto-tagging system
- 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
This commit is contained in:
31
keep-notes/app/api/ai/tags/route.ts
Normal file
31
keep-notes/app/api/ai/tags/route.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
import { NextRequest, NextResponse } from 'next/server';
|
||||
import { getAIProvider } from '@/lib/ai/factory';
|
||||
import { z } from 'zod';
|
||||
|
||||
const requestSchema = z.object({
|
||||
content: z.string().min(1, "Le contenu ne peut pas être vide"),
|
||||
});
|
||||
|
||||
export async function POST(req: NextRequest) {
|
||||
try {
|
||||
const body = await req.json();
|
||||
const { content } = requestSchema.parse(body);
|
||||
|
||||
const provider = getAIProvider();
|
||||
const tags = await provider.generateTags(content);
|
||||
console.log('[API Tags] Generated tags:', tags);
|
||||
|
||||
return NextResponse.json({ tags });
|
||||
} catch (error: any) {
|
||||
console.error('Erreur API tags:', error);
|
||||
|
||||
if (error instanceof z.ZodError) {
|
||||
return NextResponse.json({ error: error.errors }, { status: 400 });
|
||||
}
|
||||
|
||||
return NextResponse.json(
|
||||
{ error: error.message || 'Erreur lors de la génération des tags' },
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
}
|
||||
27
keep-notes/app/api/ai/test/route.ts
Normal file
27
keep-notes/app/api/ai/test/route.ts
Normal file
@@ -0,0 +1,27 @@
|
||||
import { NextResponse } from 'next/server';
|
||||
import { getAIProvider } from '@/lib/ai/factory';
|
||||
|
||||
export async function GET() {
|
||||
try {
|
||||
const provider = getAIProvider();
|
||||
const providerName = process.env.AI_PROVIDER || 'openai';
|
||||
|
||||
// Test simple de génération de tags sur un texte bidon
|
||||
const testContent = "J'adore cuisiner des pâtes le dimanche soir avec ma famille.";
|
||||
const tags = await provider.generateTags(testContent);
|
||||
|
||||
return NextResponse.json({
|
||||
status: 'success',
|
||||
provider: providerName,
|
||||
test_tags: tags,
|
||||
message: 'Infrastructure IA opérationnelle'
|
||||
});
|
||||
} catch (error: any) {
|
||||
console.error('Erreur test IA détaillée:', error);
|
||||
return NextResponse.json({
|
||||
status: 'error',
|
||||
message: error.message,
|
||||
stack: error.stack
|
||||
}, { status: 500 });
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user