mirror of
https://github.com/Mintplex-Labs/anything-llm.git
synced 2024-11-11 01:10:11 +01:00
Validate max_tokens is number (#1445)
This commit is contained in:
parent
1a5aacb001
commit
9ace0e67e6
@ -2,6 +2,7 @@ const { NativeEmbedder } = require("../../EmbeddingEngines/native");
|
|||||||
const {
|
const {
|
||||||
handleDefaultStreamResponseV2,
|
handleDefaultStreamResponseV2,
|
||||||
} = require("../../helpers/chat/responses");
|
} = require("../../helpers/chat/responses");
|
||||||
|
const { toValidNumber } = require("../../http");
|
||||||
|
|
||||||
class GenericOpenAiLLM {
|
class GenericOpenAiLLM {
|
||||||
constructor(embedder = null, modelPreference = null) {
|
constructor(embedder = null, modelPreference = null) {
|
||||||
@ -18,7 +19,9 @@ class GenericOpenAiLLM {
|
|||||||
});
|
});
|
||||||
this.model =
|
this.model =
|
||||||
modelPreference ?? process.env.GENERIC_OPEN_AI_MODEL_PREF ?? null;
|
modelPreference ?? process.env.GENERIC_OPEN_AI_MODEL_PREF ?? null;
|
||||||
this.maxTokens = process.env.GENERIC_OPEN_AI_MAX_TOKENS ?? 1024;
|
this.maxTokens = process.env.GENERIC_OPEN_AI_MAX_TOKENS
|
||||||
|
? toValidNumber(process.env.GENERIC_OPEN_AI_MAX_TOKENS, 1024)
|
||||||
|
: 1024;
|
||||||
if (!this.model)
|
if (!this.model)
|
||||||
throw new Error("GenericOpenAI must have a valid model set.");
|
throw new Error("GenericOpenAI must have a valid model set.");
|
||||||
this.limits = {
|
this.limits = {
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
const { Document } = require("../../../../models/documents");
|
const { Document } = require("../../../../models/documents");
|
||||||
const { safeJsonParse } = require("../../../http");
|
const { safeJsonParse } = require("../../../http");
|
||||||
const { validate } = require("uuid");
|
|
||||||
const { summarizeContent } = require("../utils/summarize");
|
const { summarizeContent } = require("../utils/summarize");
|
||||||
const Provider = require("../providers/ai-provider");
|
const Provider = require("../providers/ai-provider");
|
||||||
|
|
||||||
|
@ -2,6 +2,7 @@ const OpenAI = require("openai");
|
|||||||
const Provider = require("./ai-provider.js");
|
const Provider = require("./ai-provider.js");
|
||||||
const InheritMultiple = require("./helpers/classes.js");
|
const InheritMultiple = require("./helpers/classes.js");
|
||||||
const UnTooled = require("./helpers/untooled.js");
|
const UnTooled = require("./helpers/untooled.js");
|
||||||
|
const { toValidNumber } = require("../../../http/index.js");
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The agent provider for the Generic OpenAI provider.
|
* The agent provider for the Generic OpenAI provider.
|
||||||
@ -24,7 +25,9 @@ class GenericOpenAiProvider extends InheritMultiple([Provider, UnTooled]) {
|
|||||||
this._client = client;
|
this._client = client;
|
||||||
this.model = model;
|
this.model = model;
|
||||||
this.verbose = true;
|
this.verbose = true;
|
||||||
this.maxTokens = process.env.GENERIC_OPEN_AI_MAX_TOKENS ?? 1024;
|
this.maxTokens = process.env.GENERIC_OPEN_AI_MAX_TOKENS
|
||||||
|
? toValidNumber(process.env.GENERIC_OPEN_AI_MAX_TOKENS, 1024)
|
||||||
|
: 1024;
|
||||||
}
|
}
|
||||||
|
|
||||||
get client() {
|
get client() {
|
||||||
|
@ -91,6 +91,11 @@ function isValidUrl(urlString = "") {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function toValidNumber(number = null, fallback = null) {
|
||||||
|
if (isNaN(Number(number))) return fallback;
|
||||||
|
return Number(number);
|
||||||
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
reqBody,
|
reqBody,
|
||||||
multiUserMode,
|
multiUserMode,
|
||||||
@ -101,4 +106,5 @@ module.exports = {
|
|||||||
parseAuthHeader,
|
parseAuthHeader,
|
||||||
safeJsonParse,
|
safeJsonParse,
|
||||||
isValidUrl,
|
isValidUrl,
|
||||||
|
toValidNumber,
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user