mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-17 08:50:15 +01:00
fix: Avoid Throwing Errors for Unsupported Token Count Endpoints 🪙 (#1356)
This commit is contained in:
parent
561ce8e86a
commit
ff59a2e41d
3 changed files with 12 additions and 4 deletions
|
|
@ -1,8 +1,9 @@
|
||||||
const crypto = require('crypto');
|
const crypto = require('crypto');
|
||||||
const TextStream = require('./TextStream');
|
const { supportsBalanceCheck } = require('librechat-data-provider');
|
||||||
const { getConvo, getMessages, saveMessage, updateMessage, saveConvo } = require('~/models');
|
const { getConvo, getMessages, saveMessage, updateMessage, saveConvo } = require('~/models');
|
||||||
const { addSpaceIfNeeded, isEnabled } = require('~/server/utils');
|
const { addSpaceIfNeeded, isEnabled } = require('~/server/utils');
|
||||||
const checkBalance = require('~/models/checkBalance');
|
const checkBalance = require('~/models/checkBalance');
|
||||||
|
const TextStream = require('./TextStream');
|
||||||
const { logger } = require('~/config');
|
const { logger } = require('~/config');
|
||||||
|
|
||||||
class BaseClient {
|
class BaseClient {
|
||||||
|
|
@ -424,7 +425,7 @@ class BaseClient {
|
||||||
await this.saveMessageToDatabase(userMessage, saveOptions, user);
|
await this.saveMessageToDatabase(userMessage, saveOptions, user);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isEnabled(process.env.CHECK_BALANCE)) {
|
if (isEnabled(process.env.CHECK_BALANCE) && supportsBalanceCheck[this.options.endpoint]) {
|
||||||
await checkBalance({
|
await checkBalance({
|
||||||
req: this.options.req,
|
req: this.options.req,
|
||||||
res: this.options.res,
|
res: this.options.res,
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
const { promptTokensEstimate } = require('openai-chat-tokens');
|
const { promptTokensEstimate } = require('openai-chat-tokens');
|
||||||
const { EModelEndpoint } = require('librechat-data-provider');
|
const { EModelEndpoint, supportsBalanceCheck } = require('librechat-data-provider');
|
||||||
const { formatFromLangChain } = require('~/app/clients/prompts');
|
const { formatFromLangChain } = require('~/app/clients/prompts');
|
||||||
const checkBalance = require('~/models/checkBalance');
|
const checkBalance = require('~/models/checkBalance');
|
||||||
const { isEnabled } = require('~/server/utils');
|
const { isEnabled } = require('~/server/utils');
|
||||||
|
|
@ -49,7 +49,8 @@ const createStartHandler = ({
|
||||||
prelimPromptTokens += tokenBuffer;
|
prelimPromptTokens += tokenBuffer;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (isEnabled(process.env.CHECK_BALANCE)) {
|
// TODO: if plugins extends to non-OpenAI models, this will need to be updated
|
||||||
|
if (isEnabled(process.env.CHECK_BALANCE) && supportsBalanceCheck[EModelEndpoint.openAI]) {
|
||||||
const generations =
|
const generations =
|
||||||
initialMessageCount && messages.length > initialMessageCount
|
initialMessageCount && messages.length > initialMessageCount
|
||||||
? messages.slice(initialMessageCount)
|
? messages.slice(initialMessageCount)
|
||||||
|
|
|
||||||
|
|
@ -138,6 +138,12 @@ export const supportsFiles = {
|
||||||
[EModelEndpoint.assistant]: true,
|
[EModelEndpoint.assistant]: true,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const supportsBalanceCheck = {
|
||||||
|
[EModelEndpoint.openAI]: true,
|
||||||
|
[EModelEndpoint.azureOpenAI]: true,
|
||||||
|
[EModelEndpoint.gptPlugins]: true,
|
||||||
|
};
|
||||||
|
|
||||||
export const visionModels = ['gpt-4-vision', 'llava-13b'];
|
export const visionModels = ['gpt-4-vision', 'llava-13b'];
|
||||||
|
|
||||||
export const eModelEndpointSchema = z.nativeEnum(EModelEndpoint);
|
export const eModelEndpointSchema = z.nativeEnum(EModelEndpoint);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue