mirror of
https://github.com/danny-avila/LibreChat.git
synced 2026-06-24 08:30:46 +00:00
📡 fix: Respect Custom Endpoint Stream Usage Opt-In (#13237)
This commit is contained in:
parent
05a3d1ed81
commit
cfe0f9f7f6
2 changed files with 40 additions and 1 deletions
|
|
@ -205,6 +205,39 @@ beforeEach(() => {
|
|||
jest.clearAllMocks();
|
||||
});
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Suite: custom endpoint stream usage defaults
|
||||
// ---------------------------------------------------------------------------
|
||||
describe('custom endpoint stream usage defaults', () => {
|
||||
it('disables streamUsage by default for OpenAI-compatible custom endpoints', async () => {
|
||||
const agents = await callAndCapture({
|
||||
agents: [makeAgent({ endpoint: 'LiteLLM' })],
|
||||
});
|
||||
const clientOptions = agents[0].clientOptions as Record<string, unknown>;
|
||||
|
||||
expect(clientOptions.streamUsage).toBe(false);
|
||||
expect(clientOptions.usage).toBe(true);
|
||||
});
|
||||
|
||||
it('respects explicit streamUsage from endpoint-resolved model parameters', async () => {
|
||||
const agents = await callAndCapture({
|
||||
agents: [
|
||||
makeAgent({
|
||||
endpoint: 'LiteLLM',
|
||||
model_parameters: {
|
||||
model: 'gpt-4o',
|
||||
streamUsage: true,
|
||||
},
|
||||
}),
|
||||
],
|
||||
});
|
||||
const clientOptions = agents[0].clientOptions as Record<string, unknown>;
|
||||
|
||||
expect(clientOptions.streamUsage).toBe(true);
|
||||
expect(clientOptions.usage).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Suite 1: reserveRatio
|
||||
// ---------------------------------------------------------------------------
|
||||
|
|
|
|||
|
|
@ -804,6 +804,10 @@ export async function createRun({
|
|||
);
|
||||
|
||||
const modelParameters = normalizeAgentModelParameters(agent.model_parameters);
|
||||
const hasExplicitStreamUsage = Object.prototype.hasOwnProperty.call(
|
||||
modelParameters ?? {},
|
||||
'streamUsage',
|
||||
);
|
||||
const llmConfig = Object.assign(
|
||||
{
|
||||
provider,
|
||||
|
|
@ -847,7 +851,9 @@ export async function createRun({
|
|||
customProviders.has(agent.provider) ||
|
||||
(agent.provider === Providers.OPENAI && agent.endpoint !== agent.provider)
|
||||
) {
|
||||
llmConfig.streamUsage = false;
|
||||
if (!hasExplicitStreamUsage) {
|
||||
llmConfig.streamUsage = false;
|
||||
}
|
||||
llmConfig.usage = true;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue