mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-17 08:50:15 +01:00
fix: debounce title request and handle error with default title
This commit is contained in:
parent
96ca783517
commit
2fd50c99b8
7 changed files with 70 additions and 100 deletions
|
|
@ -1,4 +1,5 @@
|
|||
const { Configuration, OpenAIApi } = require('openai');
|
||||
const _ = require('lodash');
|
||||
|
||||
const proxyEnvToAxiosProxy = (proxyString) => {
|
||||
if (!proxyString) return null;
|
||||
|
|
@ -11,29 +12,37 @@ const proxyEnvToAxiosProxy = (proxyString) => {
|
|||
port: port ? parseInt(port) : undefined,
|
||||
auth: username && password ? { username, password } : undefined
|
||||
};
|
||||
|
||||
return proxyConfig
|
||||
}
|
||||
|
||||
return proxyConfig;
|
||||
};
|
||||
|
||||
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 title-generator with one job: giving a conversation, detect the language and titling the conversation provided by a user in title case, using the same language.'
|
||||
},
|
||||
{ role: 'user', content: `In 5 words or less, summarize the conversation below with a title in title case using the language the user writes in. Don't refer to the participants of the conversation by name. Do not include punctuation or quotation marks. Your response should be in title case, exclusively containing the title. Conversation:\n\nUser: "${message}"\n\n${model}: "${response}"\n\nTitle: ` },
|
||||
]
|
||||
}, { proxy: proxyEnvToAxiosProxy(process.env.PROXY || null) });
|
||||
const completion = await openai.createChatCompletion(
|
||||
{
|
||||
model: 'gpt-3.5-turbo',
|
||||
messages: [
|
||||
{
|
||||
role: 'system',
|
||||
content:
|
||||
'You are a title-generator with one job: giving a conversation, detect the language and titling the conversation provided by a user in title case, using the same language.'
|
||||
},
|
||||
{
|
||||
role: 'user',
|
||||
content: `In 5 words or less, summarize the conversation below with a title in title case using the language the user writes in. Don't refer to the participants of the conversation by name. Do not include punctuation or quotation marks. Your response should be in title case, exclusively containing the title. Conversation:\n\nUser: "${message}"\n\n${model}: "${response}"\n\nTitle: `
|
||||
}
|
||||
]
|
||||
},
|
||||
{ proxy: proxyEnvToAxiosProxy(process.env.PROXY || null) }
|
||||
);
|
||||
|
||||
//eslint-disable-next-line
|
||||
return completion.data.choices[0].message.content.replace(/["\.]/g, '');
|
||||
};
|
||||
|
||||
module.exports = titleConvo;
|
||||
const debouncedTitleConvo = _.debounce(titleConvo, 500);
|
||||
|
||||
module.exports = debouncedTitleConvo;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue