diff --git a/src/domain/ollama/ollama.service.ts b/src/domain/ollama/ollama.service.ts index b5433f8b53772a8913a7a4b18feb4f44c2dfe59d..6a8b2370f2db6013a444f0715b53408adcc818aa 100644 --- a/src/domain/ollama/ollama.service.ts +++ b/src/domain/ollama/ollama.service.ts @@ -6,9 +6,9 @@ export class OllamaService { async generateTrueAnswer(question: string) { try { - const prompt = 'Give the correct short answer to this question:' + question; + const prompt = 'I am creating a quiz with diverse themes and category. I want the true answer of this question the shortest way possible :' + question; const body = { - "model": "llama3.2:3b", + "model": "llama3.2-vision:11b", "prompt": question, "stream": false, "format": { @@ -23,7 +23,7 @@ export class OllamaService { num_predict: 128, repeat_penalty: 0, } - + const response = await fetch(process.env.OLLAMA_URL + 'api/generate', { method: 'POST', body: JSON.stringify(body) @@ -43,15 +43,33 @@ export class OllamaService { let prompt; switch (mode) { case Mode.HUMOUR: - prompt = 'Give a short, wrong, but funny and absurd answer to this question: ' + question //0 = humoristique; + prompt = ` +You are helping to create a quiz game. +Your task is to provide a FUNNY and WRONG answer to this question: "${question}". +- The answer must be short (maximum 10 words). +- The answer must be obviously incorrect and absurd. +- Example: For "Who won the 1998 World Cup?", reply "A team of penguins in bow ties."`; + break; + case Mode.REALISTIC: - prompt = 'Provide a short, realistic but wrong answer to this question no right answer : ' + question; //1 = réaliste + prompt = ` +You are helping to create a quiz game. +Your task is to provide a REALISTIC but WRONG answer to this question: "${question}". +- The answer must be short (1 to 3 words). +- The answer must be clearly incorrect. +- Do NOT provide anything that could be interpreted as correct. +- Example: For "What is 2+2?", reply "5."`; + break; + + default: + throw new Error('Invalid mode'); } + const body = { - "model": "llama3.2:3b", - "prompt": prompt, - "stream": false, - "format": { + model: "llama3.2-vision:11b", + prompt: prompt, + stream: false, + format: { type: 'object', properties: { answer: { @@ -60,12 +78,13 @@ export class OllamaService { }, required: ['answer'] }, - num_predict: 32, - repeat_penalty: 1.1, - temperature: 0.7, - top_p: 0.9, - } - + num_predict: 6, // Réduit encore plus la longueur maximale + repeat_penalty: 1.25, // Encourage des réponses uniques + temperature: 1.2, // Accentue la créativité pour des réponses absurdes + top_p: 0.8, // Réduit les options les plus probables pour éviter des réponses classiques + }; + + const response = await fetch(process.env.OLLAMA_URL + 'api/generate', { method: 'POST', body: JSON.stringify(body)