mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-19 01:40:15 +01:00
⚙️ feat: Adjust Rate of Stream Progress (#3244)
* chore: bump data-provider and add MESSAGES CacheKey * refactor: avoid saving messages while streaming, save partial text to cache instead * fix(ci): processChunks * chore: logging aborted request to debug * feat: set stream rate for token processing * chore: specify default stream rate * fix(ci): Update AppService.js to use optional chaining for endpointLocals assignment * refactor: abstract the error handler * feat: streamRate for assistants; refactor: update default rate for token * refactor: update error handling in assistants/errors.js * refactor: update error handling in assistants/errors.js
This commit is contained in:
parent
1c282d1517
commit
5d40d0a37a
29 changed files with 661 additions and 309 deletions
|
|
@ -136,71 +136,81 @@ export const defaultAssistantsVersion = {
|
|||
[EModelEndpoint.azureAssistants]: 1,
|
||||
};
|
||||
|
||||
export const assistantEndpointSchema = z.object({
|
||||
/* assistants specific */
|
||||
disableBuilder: z.boolean().optional(),
|
||||
pollIntervalMs: z.number().optional(),
|
||||
timeoutMs: z.number().optional(),
|
||||
version: z.union([z.string(), z.number()]).default(2),
|
||||
supportedIds: z.array(z.string()).min(1).optional(),
|
||||
excludedIds: z.array(z.string()).min(1).optional(),
|
||||
privateAssistants: z.boolean().optional(),
|
||||
retrievalModels: z.array(z.string()).min(1).optional().default(defaultRetrievalModels),
|
||||
capabilities: z
|
||||
.array(z.nativeEnum(Capabilities))
|
||||
.optional()
|
||||
.default([
|
||||
Capabilities.code_interpreter,
|
||||
Capabilities.image_vision,
|
||||
Capabilities.retrieval,
|
||||
Capabilities.actions,
|
||||
Capabilities.tools,
|
||||
]),
|
||||
/* general */
|
||||
apiKey: z.string().optional(),
|
||||
baseURL: z.string().optional(),
|
||||
models: z
|
||||
.object({
|
||||
default: z.array(z.string()).min(1),
|
||||
fetch: z.boolean().optional(),
|
||||
userIdQuery: z.boolean().optional(),
|
||||
})
|
||||
.optional(),
|
||||
titleConvo: z.boolean().optional(),
|
||||
titleMethod: z.union([z.literal('completion'), z.literal('functions')]).optional(),
|
||||
titleModel: z.string().optional(),
|
||||
headers: z.record(z.any()).optional(),
|
||||
export const baseEndpointSchema = z.object({
|
||||
streamRate: z.number().optional(),
|
||||
});
|
||||
|
||||
export type TBaseEndpoint = z.infer<typeof baseEndpointSchema>;
|
||||
|
||||
export const assistantEndpointSchema = baseEndpointSchema.merge(
|
||||
z.object({
|
||||
/* assistants specific */
|
||||
disableBuilder: z.boolean().optional(),
|
||||
pollIntervalMs: z.number().optional(),
|
||||
timeoutMs: z.number().optional(),
|
||||
version: z.union([z.string(), z.number()]).default(2),
|
||||
supportedIds: z.array(z.string()).min(1).optional(),
|
||||
excludedIds: z.array(z.string()).min(1).optional(),
|
||||
privateAssistants: z.boolean().optional(),
|
||||
retrievalModels: z.array(z.string()).min(1).optional().default(defaultRetrievalModels),
|
||||
capabilities: z
|
||||
.array(z.nativeEnum(Capabilities))
|
||||
.optional()
|
||||
.default([
|
||||
Capabilities.code_interpreter,
|
||||
Capabilities.image_vision,
|
||||
Capabilities.retrieval,
|
||||
Capabilities.actions,
|
||||
Capabilities.tools,
|
||||
]),
|
||||
/* general */
|
||||
apiKey: z.string().optional(),
|
||||
baseURL: z.string().optional(),
|
||||
models: z
|
||||
.object({
|
||||
default: z.array(z.string()).min(1),
|
||||
fetch: z.boolean().optional(),
|
||||
userIdQuery: z.boolean().optional(),
|
||||
})
|
||||
.optional(),
|
||||
titleConvo: z.boolean().optional(),
|
||||
titleMethod: z.union([z.literal('completion'), z.literal('functions')]).optional(),
|
||||
titleModel: z.string().optional(),
|
||||
headers: z.record(z.any()).optional(),
|
||||
}),
|
||||
);
|
||||
|
||||
export type TAssistantEndpoint = z.infer<typeof assistantEndpointSchema>;
|
||||
|
||||
export const endpointSchema = z.object({
|
||||
name: z.string().refine((value) => !eModelEndpointSchema.safeParse(value).success, {
|
||||
message: `Value cannot be one of the default endpoint (EModelEndpoint) values: ${Object.values(
|
||||
EModelEndpoint,
|
||||
).join(', ')}`,
|
||||
export const endpointSchema = baseEndpointSchema.merge(
|
||||
z.object({
|
||||
name: z.string().refine((value) => !eModelEndpointSchema.safeParse(value).success, {
|
||||
message: `Value cannot be one of the default endpoint (EModelEndpoint) values: ${Object.values(
|
||||
EModelEndpoint,
|
||||
).join(', ')}`,
|
||||
}),
|
||||
apiKey: z.string(),
|
||||
baseURL: z.string(),
|
||||
models: z.object({
|
||||
default: z.array(z.string()).min(1),
|
||||
fetch: z.boolean().optional(),
|
||||
userIdQuery: z.boolean().optional(),
|
||||
}),
|
||||
titleConvo: z.boolean().optional(),
|
||||
titleMethod: z.union([z.literal('completion'), z.literal('functions')]).optional(),
|
||||
titleModel: z.string().optional(),
|
||||
summarize: z.boolean().optional(),
|
||||
summaryModel: z.string().optional(),
|
||||
forcePrompt: z.boolean().optional(),
|
||||
modelDisplayLabel: z.string().optional(),
|
||||
headers: z.record(z.any()).optional(),
|
||||
addParams: z.record(z.any()).optional(),
|
||||
dropParams: z.array(z.string()).optional(),
|
||||
customOrder: z.number().optional(),
|
||||
directEndpoint: z.boolean().optional(),
|
||||
titleMessageRole: z.string().optional(),
|
||||
}),
|
||||
apiKey: z.string(),
|
||||
baseURL: z.string(),
|
||||
models: z.object({
|
||||
default: z.array(z.string()).min(1),
|
||||
fetch: z.boolean().optional(),
|
||||
userIdQuery: z.boolean().optional(),
|
||||
}),
|
||||
titleConvo: z.boolean().optional(),
|
||||
titleMethod: z.union([z.literal('completion'), z.literal('functions')]).optional(),
|
||||
titleModel: z.string().optional(),
|
||||
summarize: z.boolean().optional(),
|
||||
summaryModel: z.string().optional(),
|
||||
forcePrompt: z.boolean().optional(),
|
||||
modelDisplayLabel: z.string().optional(),
|
||||
headers: z.record(z.any()).optional(),
|
||||
addParams: z.record(z.any()).optional(),
|
||||
dropParams: z.array(z.string()).optional(),
|
||||
customOrder: z.number().optional(),
|
||||
directEndpoint: z.boolean().optional(),
|
||||
titleMessageRole: z.string().optional(),
|
||||
});
|
||||
);
|
||||
|
||||
export type TEndpoint = z.infer<typeof endpointSchema>;
|
||||
|
||||
|
|
@ -213,6 +223,7 @@ export const azureEndpointSchema = z
|
|||
.and(
|
||||
endpointSchema
|
||||
.pick({
|
||||
streamRate: true,
|
||||
titleConvo: true,
|
||||
titleMethod: true,
|
||||
titleModel: true,
|
||||
|
|
@ -426,10 +437,15 @@ export const configSchema = z.object({
|
|||
modelSpecs: specsConfigSchema.optional(),
|
||||
endpoints: z
|
||||
.object({
|
||||
all: baseEndpointSchema.optional(),
|
||||
[EModelEndpoint.openAI]: baseEndpointSchema.optional(),
|
||||
[EModelEndpoint.google]: baseEndpointSchema.optional(),
|
||||
[EModelEndpoint.anthropic]: baseEndpointSchema.optional(),
|
||||
[EModelEndpoint.gptPlugins]: baseEndpointSchema.optional(),
|
||||
[EModelEndpoint.azureOpenAI]: azureEndpointSchema.optional(),
|
||||
[EModelEndpoint.azureAssistants]: assistantEndpointSchema.optional(),
|
||||
[EModelEndpoint.assistants]: assistantEndpointSchema.optional(),
|
||||
custom: z.array(endpointSchema.partial()).optional(),
|
||||
[EModelEndpoint.custom]: z.array(endpointSchema.partial()).optional(),
|
||||
})
|
||||
.strict()
|
||||
.refine((data) => Object.keys(data).length > 0, {
|
||||
|
|
@ -657,6 +673,16 @@ export enum InfiniteCollections {
|
|||
SHARED_LINKS = 'sharedLinks',
|
||||
}
|
||||
|
||||
/**
|
||||
* Enum for time intervals
|
||||
*/
|
||||
export enum Time {
|
||||
THIRTY_MINUTES = 1800000,
|
||||
TEN_MINUTES = 600000,
|
||||
FIVE_MINUTES = 300000,
|
||||
TWO_MINUTES = 120000,
|
||||
}
|
||||
|
||||
/**
|
||||
* Enum for cache keys.
|
||||
*/
|
||||
|
|
@ -727,6 +753,10 @@ export enum CacheKeys {
|
|||
* Key for the cached audio run Ids.
|
||||
*/
|
||||
AUDIO_RUNS = 'audioRuns',
|
||||
/**
|
||||
* Key for in-progress messages.
|
||||
*/
|
||||
MESSAGES = 'messages',
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -911,6 +941,8 @@ export enum Constants {
|
|||
COMMON_DIVIDER = '__',
|
||||
/** Max length for commands */
|
||||
COMMANDS_MAX_LENGTH = 56,
|
||||
/** Default Stream Rate (ms) */
|
||||
DEFAULT_STREAM_RATE = 1,
|
||||
}
|
||||
|
||||
export enum LocalStorageKeys {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue