This commit is contained in:
Lukian LEIZOUR 2022-12-05 22:54:16 +01:00
parent ba0ebec07d
commit a5a86747ad
3 changed files with 32 additions and 3 deletions

6
app.js
View file

@ -7,7 +7,7 @@ const { getJoke } = require('./libs/dadJokes');
const { rtag, r34 } = require('./libs/rule34');
const { addToLogs, isTrue, image_search, getHelp } = require('./libs/botTools');
const { rockPaperScissorsAgainstBot } = require('./libs/games');
const { generateImage } = require('./libs/openAi');
const { generateImage, answerQuestion } = require('./libs/openAi');
//bot initialization
const bot = new Telegraf(process.env.TELEGRAM);
@ -88,5 +88,9 @@ bot.command('g', ctx => {
generateImage(ctx.message.text.slice(+3), ctx, bot)
})
bot.command('q', ctx => {
answerQuestion(ctx.message.text.slice(+3), ctx, bot)
})
//bot launch
bot.launch();

View file

@ -33,4 +33,28 @@ function generateImage(query, ctx, bot) {
})
}
module.exports = { generateImage };
function answerQuestion(query, ctx, bot) {
response = openai.createCompletion({
model: "text-davinci-003",
prompt: query,
max_tokens: 500,
temperature: 0.9,
}).catch((err) => {
console.log(err);
})
console.log("--> answering the question " + query);
addToLogs("--> answering the question " + query)
bot.telegram.sendMessage(ctx.chat.id, "Generating the answer.", {});
response.then((res) => {
const text = res.data.choices[0].text.slice(+2);
bot.telegram.sendMessage(ctx.chat.id, text, {}).catch((err) => {
bot.telegram.sendMessage(ctx.chat.id, "Something went wrong.", {});
console.log("--> error while sending the answer : " + err);
})
})
}
module.exports = { generateImage, answerQuestion };

View file

@ -3,3 +3,4 @@ This is the opanAI help message :
list of opanAI commands :
-`/g <query>` (generate an image with DALL-E with your query)
-`/q <query>` (generate an answer for your question)