mirror of
https://github.com/danny-avila/LibreChat.git
synced 2026-08-27 04:07:05 +00:00
🧭 feat: Add OpenRouter Prompt Cache Setting (#13029)
* feat: add OpenRouter prompt cache setting * fix: type OpenRouter schema lookup * fix: honor proxied OpenRouter prompt cache * refactor: flatten endpoint schema fallback * chore: Bump `@librechat/agents` to version 3.1.82 * fix: Default OpenRouter prompt cache params * test: Align OpenRouter config expectations * test: Update OpenRouter default cache expectation * fix: Align OpenRouter Detection * chore: Bump `@librechat/agents` to version 3.1.83 * docs: Remove OpenRouter prompt cache setup note * refactor: Use provider enum for OpenRouter defaults * style: Format OpenRouter defaults guard
This commit is contained in:
parent
0d5c2b339a
commit
8a654dc8b1
17 changed files with 487 additions and 38 deletions
|
|
@ -3,6 +3,7 @@ const axios = require('axios');
|
|||
const yaml = require('js-yaml');
|
||||
const keyBy = require('lodash/keyBy');
|
||||
const { loadYaml } = require('@librechat/api');
|
||||
const { Providers } = require('@librechat/agents');
|
||||
const { logger } = require('@librechat/data-schemas');
|
||||
const {
|
||||
configSchema,
|
||||
|
|
@ -17,6 +18,48 @@ const defaultConfigPath = path.resolve(projectRoot, 'librechat.yaml');
|
|||
|
||||
let i = 0;
|
||||
|
||||
const OPENROUTER_PROMPT_CACHE_DEFAULT = {
|
||||
key: 'promptCache',
|
||||
default: true,
|
||||
};
|
||||
|
||||
function includesOpenRouter(value) {
|
||||
return typeof value === 'string' && value.toLowerCase().includes(Providers.OPENROUTER);
|
||||
}
|
||||
|
||||
function isOpenRouterEndpoint(endpoint) {
|
||||
return includesOpenRouter(endpoint.name) || includesOpenRouter(endpoint.baseURL);
|
||||
}
|
||||
|
||||
function shouldPreserveCustomParams(customParams) {
|
||||
const defaultEndpoint = customParams?.defaultParamsEndpoint;
|
||||
return (
|
||||
defaultEndpoint && defaultEndpoint !== 'custom' && defaultEndpoint !== Providers.OPENROUTER
|
||||
);
|
||||
}
|
||||
|
||||
function addOpenRouterDefaults(endpoint) {
|
||||
if (!isOpenRouterEndpoint(endpoint)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (shouldPreserveCustomParams(endpoint.customParams)) {
|
||||
return;
|
||||
}
|
||||
|
||||
const customParams = endpoint.customParams ?? {};
|
||||
const paramDefinitions = customParams.paramDefinitions ?? [];
|
||||
const hasPromptCache = paramDefinitions.some((param) => param.key === 'promptCache');
|
||||
|
||||
endpoint.customParams = {
|
||||
...customParams,
|
||||
defaultParamsEndpoint: Providers.OPENROUTER,
|
||||
paramDefinitions: hasPromptCache
|
||||
? paramDefinitions
|
||||
: [...paramDefinitions, OPENROUTER_PROMPT_CACHE_DEFAULT],
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Load custom configuration files and caches the object if the `cache` field at root is true.
|
||||
* Validation via parsing the config file with the config schema.
|
||||
|
|
@ -119,6 +162,8 @@ https://www.librechat.ai/docs/configuration/stt_tts`);
|
|||
}
|
||||
}
|
||||
|
||||
(customConfig.endpoints?.custom ?? []).forEach(addOpenRouterDefaults);
|
||||
|
||||
(customConfig.endpoints?.custom ?? [])
|
||||
.filter((endpoint) => endpoint.customParams)
|
||||
.forEach((endpoint) => parseCustomParams(endpoint.name, endpoint.customParams));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue