mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-24 04:10:15 +01:00
titles conversations based on first two messages
This commit is contained in:
parent
511c8c9599
commit
4e6b6be15c
6 changed files with 132 additions and 13 deletions
|
|
@ -1,5 +1,6 @@
|
|||
require('dotenv').config();
|
||||
const Keyv = require('keyv');
|
||||
const { Configuration, OpenAIApi } = require('openai');
|
||||
const messageStore = new Keyv(process.env.MONGODB_URI, { namespace: 'chatgpt' });
|
||||
|
||||
const ask = async (question, progressCallback, convo) => {
|
||||
|
|
@ -21,4 +22,17 @@ const ask = async (question, progressCallback, convo) => {
|
|||
return res;
|
||||
};
|
||||
|
||||
module.exports = { ask };
|
||||
const titleConversation = async (message, response) => {
|
||||
const configuration = new Configuration({
|
||||
apiKey: process.env.OPENAI_KEY
|
||||
});
|
||||
const openai = new OpenAIApi(configuration);
|
||||
const completion = await openai.createCompletion({
|
||||
model: 'text-davinci-002',
|
||||
prompt: `Make a short title (goal: 5 words or less) in title case summarizing this conversation:\nuser:"${message}"\nGPT:"${response}"\nTitle: `
|
||||
});
|
||||
console.log(completion.data.choices[0].text);
|
||||
return completion.data.choices[0].text.replace(/\n/g, '');
|
||||
};
|
||||
|
||||
module.exports = { ask, titleConversation };
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue