mirror of
https://github.com/danny-avila/LibreChat.git
synced 2026-02-19 08:58:09 +01:00
🎭 feat: Override Custom Endpoint Schema with Specified Params Endpoint (#11788)
* 🔧 refactor: Simplify payload parsing and enhance getSaveOptions logic - Removed unused bedrockInputSchema from payloadParser, streamlining the function. - Updated payloadParser to handle optional chaining for model parameters. - Enhanced getSaveOptions to ensure runOptions defaults to an empty object if parsing fails, improving robustness. - Adjusted the assignment of maxContextTokens to use the instance variable for consistency. * 🔧 fix: Update maxContextTokens assignment logic in initializeAgent function - Enhanced the maxContextTokens assignment to allow for user-defined values, ensuring it defaults to a calculated value only when not provided or invalid. This change improves flexibility in agent initialization. * 🧪 test: Add unit tests for initializeAgent function - Introduced comprehensive unit tests for the initializeAgent function, focusing on maxContextTokens behavior. - Tests cover scenarios for user-defined values, fallback calculations, and edge cases such as zero and negative values, enhancing overall test coverage and reliability of agent initialization logic. * refactor: default params Endpoint Configuration Handling - Integrated `getEndpointsConfig` to fetch endpoint configurations, allowing for dynamic handling of `defaultParamsEndpoint`. - Updated `buildEndpointOption` to pass `defaultParamsEndpoint` to `parseCompactConvo`, ensuring correct parameter handling based on endpoint type. - Added comprehensive unit tests for `buildDefaultConvo` and `cleanupPreset` to validate behavior with `defaultParamsEndpoint`, covering various scenarios and edge cases. - Refactored related hooks and utility functions to support the new configuration structure, improving overall flexibility and maintainability. * refactor: Centralize defaultParamsEndpoint retrieval - Introduced `getDefaultParamsEndpoint` function to streamline the retrieval of `defaultParamsEndpoint` across various hooks and middleware. - Updated multiple files to utilize the new function, enhancing code consistency and maintainability. - Removed redundant logic for fetching `defaultParamsEndpoint`, simplifying the codebase.
This commit is contained in:
parent
6cc6ee3207
commit
467df0f07a
19 changed files with 1234 additions and 45 deletions
|
|
@ -1908,3 +1908,14 @@ export function getEndpointField<
|
|||
}
|
||||
return config[property];
|
||||
}
|
||||
|
||||
/** Resolves the `defaultParamsEndpoint` for a given endpoint from its custom params config */
|
||||
export function getDefaultParamsEndpoint(
|
||||
endpointsConfig: TEndpointsConfig | undefined | null,
|
||||
endpoint: string | null | undefined,
|
||||
): string | undefined {
|
||||
if (!endpointsConfig || !endpoint) {
|
||||
return undefined;
|
||||
}
|
||||
return endpointsConfig[endpoint]?.customParams?.defaultParamsEndpoint;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -144,26 +144,25 @@ export const parseConvo = ({
|
|||
endpointType,
|
||||
conversation,
|
||||
possibleValues,
|
||||
defaultParamsEndpoint,
|
||||
}: {
|
||||
endpoint: EndpointSchemaKey;
|
||||
endpointType?: EndpointSchemaKey | null;
|
||||
conversation: Partial<s.TConversation | s.TPreset> | null;
|
||||
possibleValues?: TPossibleValues;
|
||||
// TODO: POC for default schema
|
||||
// defaultSchema?: Partial<EndpointSchema>,
|
||||
defaultParamsEndpoint?: string | null;
|
||||
}) => {
|
||||
let schema = endpointSchemas[endpoint] as EndpointSchema | undefined;
|
||||
|
||||
if (!schema && !endpointType) {
|
||||
throw new Error(`Unknown endpoint: ${endpoint}`);
|
||||
} else if (!schema && endpointType) {
|
||||
schema = endpointSchemas[endpointType];
|
||||
} else if (!schema) {
|
||||
const overrideSchema = defaultParamsEndpoint
|
||||
? endpointSchemas[defaultParamsEndpoint as EndpointSchemaKey]
|
||||
: undefined;
|
||||
schema = overrideSchema ?? (endpointType ? endpointSchemas[endpointType] : undefined);
|
||||
}
|
||||
|
||||
// if (defaultSchema && schemaCreators[endpoint]) {
|
||||
// schema = schemaCreators[endpoint](defaultSchema);
|
||||
// }
|
||||
|
||||
const convo = schema?.parse(conversation) as s.TConversation | undefined;
|
||||
const { models } = possibleValues ?? {};
|
||||
|
||||
|
|
@ -310,13 +309,13 @@ export const parseCompactConvo = ({
|
|||
endpointType,
|
||||
conversation,
|
||||
possibleValues,
|
||||
defaultParamsEndpoint,
|
||||
}: {
|
||||
endpoint?: EndpointSchemaKey;
|
||||
endpointType?: EndpointSchemaKey | null;
|
||||
conversation: Partial<s.TConversation | s.TPreset>;
|
||||
possibleValues?: TPossibleValues;
|
||||
// TODO: POC for default schema
|
||||
// defaultSchema?: Partial<EndpointSchema>,
|
||||
defaultParamsEndpoint?: string | null;
|
||||
}): Omit<s.TConversation, 'iconURL'> | null => {
|
||||
if (!endpoint) {
|
||||
throw new Error(`undefined endpoint: ${endpoint}`);
|
||||
|
|
@ -326,8 +325,11 @@ export const parseCompactConvo = ({
|
|||
|
||||
if (!schema && !endpointType) {
|
||||
throw new Error(`Unknown endpoint: ${endpoint}`);
|
||||
} else if (!schema && endpointType) {
|
||||
schema = compactEndpointSchemas[endpointType];
|
||||
} else if (!schema) {
|
||||
const overrideSchema = defaultParamsEndpoint
|
||||
? compactEndpointSchemas[defaultParamsEndpoint as EndpointSchemaKey]
|
||||
: undefined;
|
||||
schema = overrideSchema ?? (endpointType ? compactEndpointSchemas[endpointType] : undefined);
|
||||
}
|
||||
|
||||
if (!schema) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue