mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-09-22 08:12:00 +02:00

* fix: correct preset title for Anthropic endpoint * fix(Settings/Anthropic): show correct default value for LLM temperature * fix(AnthropicClient): use `getModelMaxTokens` to get the correct LLM max context tokens, correctly set default temperature to 1, use only 2 params for class constructor, use `getResponseSender` to add correct sender to response message * refactor(/api/ask|edit/anthropic): save messages to database after the final response is sent to the client, and do not save conversation from route controller * fix(initializeClient/anthropic): correctly pass client options (endpointOption) to class initialization * feat(ModelService/Anthropic): add claude-1.2
37 lines
1,006 B
JavaScript
37 lines
1,006 B
JavaScript
const { AnthropicClient } = require('~/app');
|
|
const { getUserKey, checkUserKeyExpiry } = require('~/server/services/UserService');
|
|
|
|
const initializeClient = async ({ req, res, endpointOption }) => {
|
|
const { ANTHROPIC_API_KEY, ANTHROPIC_REVERSE_PROXY } = process.env;
|
|
const expiresAt = req.body.key;
|
|
const isUserProvided = ANTHROPIC_API_KEY === 'user_provided';
|
|
|
|
const anthropicApiKey = isUserProvided
|
|
? await getAnthropicUserKey(req.user.id)
|
|
: ANTHROPIC_API_KEY;
|
|
|
|
if (expiresAt && isUserProvided) {
|
|
checkUserKeyExpiry(
|
|
expiresAt,
|
|
'Your ANTHROPIC_API_KEY has expired. Please provide your API key again.',
|
|
);
|
|
}
|
|
|
|
const client = new AnthropicClient(anthropicApiKey, {
|
|
req,
|
|
res,
|
|
reverseProxyUrl: ANTHROPIC_REVERSE_PROXY ?? null,
|
|
...endpointOption,
|
|
});
|
|
|
|
return {
|
|
client,
|
|
anthropicApiKey,
|
|
};
|
|
};
|
|
|
|
const getAnthropicUserKey = async (userId) => {
|
|
return await getUserKey({ userId, name: 'anthropic' });
|
|
};
|
|
|
|
module.exports = initializeClient;
|