Feeling Depressed? Don't know who to talk to? Talk to this bot! It will hear what you have to say and would love to help you!
// authenticates you with the API standard library
const lib = require('lib')({token: process.env.STDLIB_SECRET_TOKEN});
let event = context.params.event;
let botMention = event.mentions.find((mention) => mention.bot);
let previous_session = await lib.keyvalue.store['@0.1.16'].get({
key: `session-${event.author.id}`,
defaultValue: [],
});
let message = event.content.replace(/<@(\d+)>/gi, ($0, $1) => {
let mention = event.mentions.find((mention) => mention.id === $1);
if (mention) {
return `<@${mention.username}>`;
} else {
return `<@:unknown>`;
}
});
previous_session.push({
date: `${new Date()}`,
role: 'patient',
message: event.content,
});
let prompt = [
`Your name is ${botMention.username}.`,
`Your Role is psychologist`,
`Inside users messages to you, they'll refer to you by saying <@${botMention.username}> somewhere in the message.`,
`User input may be multi-line, and you can respond with multiple lines as well. Here are some examples:`,
`Provide next replica as a professional psychologist for the conversation in the following JSON format:
{
"date": "2021-05-01, 12:00:00",
"role": "psychologist",
"message": "Hello! It's great to meet you. As a professional psychologist, my goal is to help you improve your mental health and wellbeing.
To start, how are you feeling today? It's important to check in with ourselves and our emotions on a regular basis."
}
ALWAYS include in your message question and engage the conversation continuation. The current conversation presented in JSON format:
${previous_session}
Only provide the YOUR response and nothing else
`,
].join('\n');
try {
let completion = await lib.openai.playground['@0.0.2'].completions.create({
model: `text-davinci-003`,
prompt: [prompt],
max_tokens: 512,
best_of: 1,
});
await lib.discord.channels['@0.3.1'].messages.create({
channel_id: `${context.params.event.channel_id}`,
content: JSON.parse(completion.choices[0].text).message,
message_reference: {
message_id: event.id,
channel_id: event.channel_id,
guild_id: event.guild_id,
},
});
previous_session.push(JSON.parse(completion.choices[0].text));
await lib.keyvalue.store['@0.1.16'].set({
key: `session-${event.author.id}`,
value: previous_session,
});
} catch (e) {
console.log(e);
}