chatgpt now titles conversations

This commit is contained in:
Danny Avila 2023-03-02 13:52:41 -05:00
parent 897c384ac9
commit c4d0787b49
4 changed files with 31 additions and 8 deletions

View file

@ -1,4 +1,4 @@
const { titleConvo } = require('./chatgpt');
const titleConvo = require('./titleConvo');
const { askClient } = require('./chatgpt-client');
const { browserClient } = require('./chatgpt-browser');
const { askBing } = require('./bingai');

23
app/titleConvo.js Normal file
View file

@ -0,0 +1,23 @@
const { Configuration, OpenAIApi } = require('openai');
const titleConvo = async ({ message, response, model }) => {
const configuration = new Configuration({
apiKey: process.env.OPENAI_KEY
});
const openai = new OpenAIApi(configuration);
const completion = await openai.createChatCompletion({
model: 'gpt-3.5-turbo',
messages: [
{
role: 'system',
content:
'You are a helpful title-generator with one job: titling in title case the conversation provided by a user. You do not reply with anything but a succinct title that summarizes the conversation in title case, ideally around 5 words or less. You do not refer to the participants of the conversation by name. Do not include punctuation or quotation marks.'
},
{ role: 'user', content: `Please title this conversation: User:"${message}" ${model}:"${response}"` },
]
});
return completion.data.choices[0].message.content;
};
module.exports = titleConvo;