fix: Avoid Throwing Errors for Unsupported Token Count Endpoints 🪙 (#1356)
This commit is contained in:
@@ -1,8 +1,9 @@
|
||||
const crypto = require('crypto');
|
||||
const TextStream = require('./TextStream');
|
||||
const { supportsBalanceCheck } = require('librechat-data-provider');
|
||||
const { getConvo, getMessages, saveMessage, updateMessage, saveConvo } = require('~/models');
|
||||
const { addSpaceIfNeeded, isEnabled } = require('~/server/utils');
|
||||
const checkBalance = require('~/models/checkBalance');
|
||||
const TextStream = require('./TextStream');
|
||||
const { logger } = require('~/config');
|
||||
|
||||
class BaseClient {
|
||||
@@ -424,7 +425,7 @@ class BaseClient {
|
||||
await this.saveMessageToDatabase(userMessage, saveOptions, user);
|
||||
}
|
||||
|
||||
if (isEnabled(process.env.CHECK_BALANCE)) {
|
||||
if (isEnabled(process.env.CHECK_BALANCE) && supportsBalanceCheck[this.options.endpoint]) {
|
||||
await checkBalance({
|
||||
req: this.options.req,
|
||||
res: this.options.res,
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
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 checkBalance = require('~/models/checkBalance');
|
||||
const { isEnabled } = require('~/server/utils');
|
||||
@@ -49,7 +49,8 @@ const createStartHandler = ({
|
||||
prelimPromptTokens += tokenBuffer;
|
||||
|
||||
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 =
|
||||
initialMessageCount && messages.length > initialMessageCount
|
||||
? messages.slice(initialMessageCount)
|
||||
|
||||
@@ -138,6 +138,12 @@ export const supportsFiles = {
|
||||
[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 eModelEndpointSchema = z.nativeEnum(EModelEndpoint);
|
||||
|
||||
Reference in New Issue
Block a user