mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-17 17:00:15 +01:00
* WIP: gemini-1.5 support * feat: extended vertex ai support * fix: handle possibly undefined modelName * fix: gpt-4-turbo-preview invalid vision model * feat: specify `fileConfig.imageOutputType` and make PNG default image conversion type * feat: better truncation for errors including base64 strings * fix: gemini inlineData formatting * feat: RAG augmented prompt for gemini-1.5 * feat: gemini-1.5 rates and token window * chore: adjust tokens, update docs, update vision Models * chore: add back `ChatGoogleVertexAI` for chat models via vertex ai * refactor: ask/edit controllers to not use `unfinished` field for google endpoint * chore: remove comment * chore(ci): fix AppService test * chore: remove comment * refactor(GoogleSearch): use `GOOGLE_SEARCH_API_KEY` instead, issue warning for old variable * chore: bump data-provider to 0.5.4 * chore: update docs * fix: condition for gemini-1.5 using generative ai lib * chore: update docs * ci: add additional AppService test for `imageOutputType` * refactor: optimize new config value `imageOutputType` * chore: bump CONFIG_VERSION * fix(assistants): avatar upload
101 lines
3.6 KiB
JavaScript
101 lines
3.6 KiB
JavaScript
const { FileSources } = require('librechat-data-provider');
|
|
const { getStrategyFunctions } = require('~/server/services/Files/strategies');
|
|
const { resizeAvatar } = require('~/server/services/Files/images/avatar');
|
|
const User = require('~/models/User');
|
|
|
|
/**
|
|
* Updates the avatar URL of an existing user. If the user's avatar URL does not include the query parameter
|
|
* '?manual=true', it updates the user's avatar with the provided URL. For local file storage, it directly updates
|
|
* the avatar URL, while for other storage types, it processes the avatar URL using the specified file strategy.
|
|
*
|
|
* @param {User} oldUser - The existing user object that needs to be updated.
|
|
* @param {string} avatarUrl - The new avatar URL to be set for the user.
|
|
*
|
|
* @returns {Promise<void>}
|
|
* The function updates the user's avatar and saves the user object. It does not return any value.
|
|
*
|
|
* @throws {Error} Throws an error if there's an issue saving the updated user object.
|
|
*/
|
|
const handleExistingUser = async (oldUser, avatarUrl) => {
|
|
const fileStrategy = process.env.CDN_PROVIDER;
|
|
const isLocal = fileStrategy === FileSources.local;
|
|
|
|
if (isLocal && (oldUser.avatar === null || !oldUser.avatar.includes('?manual=true'))) {
|
|
oldUser.avatar = avatarUrl;
|
|
await oldUser.save();
|
|
} else if (!isLocal && (oldUser.avatar === null || !oldUser.avatar.includes('?manual=true'))) {
|
|
const userId = oldUser._id;
|
|
const resizedBuffer = await resizeAvatar({
|
|
userId,
|
|
input: avatarUrl,
|
|
});
|
|
const { processAvatar } = getStrategyFunctions(fileStrategy);
|
|
oldUser.avatar = await processAvatar({ buffer: resizedBuffer, userId });
|
|
await oldUser.save();
|
|
}
|
|
};
|
|
|
|
/**
|
|
* Creates a new user with the provided user details. If the file strategy is not local, the avatar URL is
|
|
* processed using the specified file strategy. The new user is saved to the database with the processed or
|
|
* original avatar URL.
|
|
*
|
|
* @param {Object} params - The parameters object for user creation.
|
|
* @param {string} params.email - The email of the new user.
|
|
* @param {string} params.avatarUrl - The avatar URL of the new user.
|
|
* @param {string} params.provider - The provider of the user's account.
|
|
* @param {string} params.providerKey - The key to identify the provider in the user model.
|
|
* @param {string} params.providerId - The provider-specific ID of the user.
|
|
* @param {string} params.username - The username of the new user.
|
|
* @param {string} params.name - The name of the new user.
|
|
* @param {boolean} [params.emailVerified=false] - Optional. Indicates whether the user's email is verified. Defaults to false.
|
|
*
|
|
* @returns {Promise<User>}
|
|
* A promise that resolves to the newly created user object.
|
|
*
|
|
* @throws {Error} Throws an error if there's an issue creating or saving the new user object.
|
|
*/
|
|
const createNewUser = async ({
|
|
email,
|
|
avatarUrl,
|
|
provider,
|
|
providerKey,
|
|
providerId,
|
|
username,
|
|
name,
|
|
emailVerified,
|
|
}) => {
|
|
const update = {
|
|
email,
|
|
avatar: avatarUrl,
|
|
provider,
|
|
[providerKey]: providerId,
|
|
username,
|
|
name,
|
|
emailVerified,
|
|
};
|
|
|
|
// TODO: remove direct access of User model
|
|
const newUser = await new User(update).save();
|
|
|
|
const fileStrategy = process.env.CDN_PROVIDER;
|
|
const isLocal = fileStrategy === FileSources.local;
|
|
|
|
if (!isLocal) {
|
|
const userId = newUser._id;
|
|
const resizedBuffer = await resizeAvatar({
|
|
userId,
|
|
input: avatarUrl,
|
|
});
|
|
const { processAvatar } = getStrategyFunctions(fileStrategy);
|
|
newUser.avatar = await processAvatar({ buffer: resizedBuffer, userId });
|
|
await newUser.save();
|
|
}
|
|
|
|
return newUser;
|
|
};
|
|
|
|
module.exports = {
|
|
handleExistingUser,
|
|
createNewUser,
|
|
};
|