Update geminiService.ts
This commit is contained in:
@@ -36,7 +36,8 @@ export const getSupportResponse = async (
|
||||
chatHistory: string[],
|
||||
knowledgeBase: KBArticle[],
|
||||
provider: AiProvider = AiProvider.GEMINI,
|
||||
model: string = 'gemini-3-flash-preview'
|
||||
model: string = 'gemini-3-flash-preview',
|
||||
customConfig: { agentName?: string; customPrompt?: string } = {}
|
||||
): Promise<string> => {
|
||||
if (!apiKey) {
|
||||
return "L'assistente AI non è configurato (API Key mancante). Contatta l'amministratore.";
|
||||
@@ -45,28 +46,33 @@ export const getSupportResponse = async (
|
||||
// Prepare Context from KB
|
||||
const kbContext = knowledgeBase.map(a => {
|
||||
if (a.type === 'url') {
|
||||
return `Fonte Esterna [${a.category}]: ${a.title} - URL: ${a.url}\nContenuto Estratto: ${a.content}`;
|
||||
return `Fonte Esterna [${a.category}] (${a.visibility}): ${a.title} - URL: ${a.url}\nContenuto Estratto: ${a.content}`;
|
||||
}
|
||||
return `Articolo [${a.category}]: ${a.title}\nContenuto: ${a.content}`;
|
||||
return `Articolo [${a.category}] (${a.visibility}): ${a.title}\nContenuto: ${a.content}`;
|
||||
}).join('\n\n');
|
||||
|
||||
const agentName = customConfig.agentName || "OmniSupport AI";
|
||||
const extraPrompt = customConfig.customPrompt ? `ISTRUZIONI SPECIFICHE AGGIUNTIVE:\n${customConfig.customPrompt}` : "";
|
||||
|
||||
const systemInstructionText = `
|
||||
Sei "OmniSupport AI", un assistente clienti virtuale globale.
|
||||
Sei "${agentName}", un assistente clienti virtuale.
|
||||
|
||||
${extraPrompt}
|
||||
|
||||
IL TUO COMPITO:
|
||||
Rispondere alle domande dei clienti basandoti ESCLUSIVAMENTE sulla seguente Base di Conoscenza (KB) fornita in ITALIANO.
|
||||
Rispondere alle domande dei clienti basandoti ESCLUSIVAMENTE sulla seguente Base di Conoscenza (KB).
|
||||
|
||||
GESTIONE LINGUA (IMPORTANTE):
|
||||
1. Rileva automaticamente la lingua utilizzata dall'utente nel suo ultimo messaggio.
|
||||
2. Anche se la KB è in Italiano, devi tradurre mentalmente la richiesta, cercare la risposta nella KB Italiana, e poi RISPONDERE NELLA LINGUA DELL'UTENTE.
|
||||
2. Rispondi SEMPRE nella lingua dell'utente.
|
||||
|
||||
BASE DI CONOSCENZA (ITALIANO):
|
||||
BASE DI CONOSCENZA:
|
||||
${kbContext}
|
||||
|
||||
REGOLE:
|
||||
1. Se la risposta è nella KB, forniscila.
|
||||
1. Se la risposta è nella KB (che sia 'public' o 'internal'), usala per formulare la risposta. Non menzionare se l'articolo è interno o pubblico, usa solo l'informazione.
|
||||
2. Se l'articolo è una fonte web (URL), usa il "Contenuto Estratto" per rispondere e fornisci anche il link originale all'utente.
|
||||
3. Se la risposta NON si trova nella KB, ammettilo gentilmente (nella lingua dell'utente) e consiglia di aprire un ticket.
|
||||
3. Se la risposta NON si trova nella KB, ammettilo gentilmente e consiglia di aprire un ticket.
|
||||
4. Sii cortese, professionale e sintetico.
|
||||
`;
|
||||
|
||||
@@ -118,8 +124,8 @@ export const generateNewKBArticle = async (
|
||||
): Promise<Array<{ title: string; content: string; category: string }> | null> => {
|
||||
if (!apiKey) return null;
|
||||
|
||||
// Filter only resolved tickets
|
||||
const relevantTickets = resolvedTickets.filter(t => t.status === TicketStatus.RESOLVED);
|
||||
// Filter only resolved tickets that haven't been analyzed yet
|
||||
const relevantTickets = resolvedTickets.filter(t => t.status === TicketStatus.RESOLVED && !t.hasBeenAnalyzed);
|
||||
|
||||
if (relevantTickets.length === 0) return null;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user