-
-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🤖 feat: Add titling to Google client (#2983)
* feat: Add titling to Google client * feat: Add titling to Google client * PR feedback changes
- Loading branch information
1 parent
aac01df
commit b5081bf
Showing
5 changed files
with
193 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
const { CacheKeys, Constants } = require('librechat-data-provider'); | ||
const getLogStores = require('~/cache/getLogStores'); | ||
const { isEnabled } = require('~/server/utils'); | ||
const { saveConvo } = require('~/models'); | ||
const { logger } = require('~/config'); | ||
const initializeClient = require('./initializeClient'); | ||
|
||
const addTitle = async (req, { text, response, client }) => { | ||
const { TITLE_CONVO = 'true' } = process.env ?? {}; | ||
if (!isEnabled(TITLE_CONVO)) { | ||
return; | ||
} | ||
|
||
if (client.options.titleConvo === false) { | ||
return; | ||
} | ||
|
||
const DEFAULT_TITLE_MODEL = 'gemini-pro'; | ||
const { GOOGLE_TITLE_MODEL } = process.env ?? {}; | ||
|
||
let model = GOOGLE_TITLE_MODEL ?? DEFAULT_TITLE_MODEL; | ||
|
||
if (GOOGLE_TITLE_MODEL === Constants.CURRENT_MODEL) { | ||
model = client.options?.modelOptions.model; | ||
|
||
if (client.isVisionModel) { | ||
logger.warn( | ||
`current_model was specified for Google title request, but the model ${model} cannot process a text-only conversation. Falling back to ${DEFAULT_TITLE_MODEL}`, | ||
); | ||
|
||
model = DEFAULT_TITLE_MODEL; | ||
} | ||
} | ||
|
||
const titleEndpointOptions = { | ||
...client.options, | ||
modelOptions: { ...client.options?.modelOptions, model: model }, | ||
attachments: undefined, // After a response, this is set to an empty array which results in an error during setOptions | ||
}; | ||
|
||
const { client: titleClient } = await initializeClient({ | ||
req, | ||
res: response, | ||
endpointOption: titleEndpointOptions, | ||
}); | ||
|
||
const titleCache = getLogStores(CacheKeys.GEN_TITLE); | ||
const key = `${req.user.id}-${response.conversationId}`; | ||
|
||
const title = await titleClient.titleConvo({ text, responseText: response?.text }); | ||
await titleCache.set(key, title, 120000); | ||
await saveConvo(req.user.id, { | ||
conversationId: response.conversationId, | ||
title, | ||
}); | ||
}; | ||
|
||
module.exports = addTitle; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,9 @@ | ||
const addTitle = require('./addTitle'); | ||
const buildOptions = require('./buildOptions'); | ||
const initializeClient = require('./initializeClient'); | ||
|
||
module.exports = { | ||
// addTitle, // todo | ||
addTitle, | ||
buildOptions, | ||
initializeClient, | ||
}; |