mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-18 01:10:14 +01:00
24 lines
981 B
JavaScript
24 lines
981 B
JavaScript
|
|
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;
|