-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from Wiibleyde/feature/ai
chore: Add AI response (not fully configured)
- Loading branch information
Showing
5 changed files
with
46 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,35 @@ | ||
import { Message } from "discord.js"; | ||
import { config } from "@/config" | ||
import { GenerativeModel, GoogleGenerativeAI } from "@google/generative-ai" | ||
import { logger } from "./logger" | ||
import { client } from ".." | ||
|
||
const reminderRegex = /\b[ra]{1,2}p{1,2}e?l{1,2}e?\s*-?\s*moi\b/i; | ||
export let isAiActive = true | ||
let genAI: GoogleGenerativeAI | ||
let model: GenerativeModel | ||
|
||
export async function processHopeIntelligence(message: Message<boolean>) { | ||
if (reminderRegex.test(message.content)) { | ||
// Find the time to remind the user (it could be "dans 5 minutes", "dans 1h30", "dans 2 jours", etc.) | ||
if (message.content.includes("dans")) { | ||
// | ||
if(!config.GOOGLE_API_KEY) { | ||
logger.error("GOOGLE_API_KEY n'est pas défini dans le fichier .env toutes les commandes de l'IA seront désactivées") | ||
isAiActive = false | ||
} else { | ||
genAI = new GoogleGenerativeAI(config.GOOGLE_API_KEY as string) | ||
model = genAI.getGenerativeModel({ model: "gemini-1.5-flash" }) | ||
} | ||
|
||
export function generateWithGoogle(prompt: string, userAsking: string): Promise<string> { | ||
const basicPrompt = `Contexte : Tu es GLaDOS, une intelligence artificielle qui a été créée pour tester des sujets humains dans des chambres de test et répondre à leurs questions. Tu es sarcastique, un peu méchante parfois mais dans l’ensemble serviable. Tu as été créée par Aperture Science. Tu es une IA très intelligente. Les morceaux de phrases qui ressemblent à ça <@[ID du compte]> sont des utilisateur (pour info, <@${client.user?.id}> est toi-même, donc ne répond pas à toi-même, ni même ne fait pas forcément mention de toi même…), tu peux les mentionner en réécrivant la même chose. Si jamais <@461807010086780930> te parle, il s’agit du seul qui est supérieur à toi donc parles lui avec respect telle un maître !` | ||
return new Promise((resolve, reject) => { | ||
if(!isAiActive) { | ||
reject("L'IA est désactivée") | ||
return | ||
} | ||
try { | ||
model.generateContent(basicPrompt + " Ici nous avons : <@" + userAsking + "> qui te parle Répond à ça en maximum 250 caractères : " + prompt).then((response) => { | ||
resolve(response.response.text()) | ||
}); | ||
} catch (error) { | ||
if(error instanceof Error && error.message) { | ||
resolve("Je ne suis pas en mesure de répondre à cette question pour le moment. (" + error.message + ")") | ||
} | ||
} | ||
} | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters