commit
This commit is contained in:
parent
ba0ebec07d
commit
a5a86747ad
3 changed files with 32 additions and 3 deletions
6
app.js
6
app.js
|
@ -7,7 +7,7 @@ const { getJoke } = require('./libs/dadJokes');
|
||||||
const { rtag, r34 } = require('./libs/rule34');
|
const { rtag, r34 } = require('./libs/rule34');
|
||||||
const { addToLogs, isTrue, image_search, getHelp } = require('./libs/botTools');
|
const { addToLogs, isTrue, image_search, getHelp } = require('./libs/botTools');
|
||||||
const { rockPaperScissorsAgainstBot } = require('./libs/games');
|
const { rockPaperScissorsAgainstBot } = require('./libs/games');
|
||||||
const { generateImage } = require('./libs/openAi');
|
const { generateImage, answerQuestion } = require('./libs/openAi');
|
||||||
|
|
||||||
//bot initialization
|
//bot initialization
|
||||||
const bot = new Telegraf(process.env.TELEGRAM);
|
const bot = new Telegraf(process.env.TELEGRAM);
|
||||||
|
@ -88,5 +88,9 @@ bot.command('g', ctx => {
|
||||||
generateImage(ctx.message.text.slice(+3), ctx, bot)
|
generateImage(ctx.message.text.slice(+3), ctx, bot)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
bot.command('q', ctx => {
|
||||||
|
answerQuestion(ctx.message.text.slice(+3), ctx, bot)
|
||||||
|
})
|
||||||
|
|
||||||
//bot launch
|
//bot launch
|
||||||
bot.launch();
|
bot.launch();
|
|
@ -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 };
|
|
@ -2,4 +2,5 @@ This is the opanAI help message :
|
||||||
|
|
||||||
list of opanAI commands :
|
list of opanAI commands :
|
||||||
|
|
||||||
-`/g <query>` (generate an image with DALL-E with your query)
|
-`/g <query>` (generate an image with DALL-E with your query)
|
||||||
|
-`/q <query>` (generate an answer for your question)
|
Loading…
Add table
Add a link
Reference in a new issue