mirror of
https://github.com/danny-avila/LibreChat.git
synced 2026-11-21 15:33:45 +00:00
Some checks are pending
Backend Unit Tests / Build packages (push) Waiting to run
Backend Unit Tests / Codegraph select (push) Waiting to run
Backend Unit Tests / TypeScript type checks (push) Blocked by required conditions
Backend Unit Tests / Circular dependency checks (push) Waiting to run
Backend Unit Tests / Tests: api (shard 1/3) (push) Blocked by required conditions
Backend Unit Tests / Tests: api (shard 2/3) (push) Blocked by required conditions
Backend Unit Tests / Tests: api (shard 3/3) (push) Blocked by required conditions
Backend Unit Tests / Tests: data-provider (push) Blocked by required conditions
Backend Unit Tests / Tests: data-schemas (push) Blocked by required conditions
Backend Unit Tests / Tests: @librechat/api (shard 1/4) (push) Blocked by required conditions
Backend Unit Tests / Tests: @librechat/api (shard 2/4) (push) Blocked by required conditions
Backend Unit Tests / Tests: @librechat/api (shard 3/4) (push) Blocked by required conditions
Backend Unit Tests / Tests: @librechat/api (shard 4/4) (push) Blocked by required conditions
Codegraph E2E Votes / vote (full suite) (push) Waiting to run
Docker Dev Branch Images Build / publish (push) Waiting to run
Frontend Unit Tests / Client build recovery regression (push) Waiting to run
Frontend Unit Tests / Codegraph select (push) Waiting to run
Frontend Unit Tests / Build packages (push) Waiting to run
Frontend Unit Tests / TypeScript type checks (client) (push) Blocked by required conditions
Frontend Unit Tests / Tests: @librechat/chat (push) Blocked by required conditions
Frontend Unit Tests / Tests: @librechat/client (push) Blocked by required conditions
Frontend Unit Tests / Tests: Ubuntu (shard 1/2) (push) Blocked by required conditions
Frontend Unit Tests / Tests: Ubuntu (shard 2/2) (push) Blocked by required conditions
Frontend Unit Tests / Vite build verification (push) Blocked by required conditions
* fix: Price 1-Hour Prompt Cache Writes at the 1-Hour Rate * test: Cover 1-Hour Cache Write Pricing End to End * test: Price Cache Scenario on the Configured Mock Model * fix: Accept a 1-Hour Cache Write Rate in Endpoint Token Configs
51 lines
2.1 KiB
TypeScript
51 lines
2.1 KiB
TypeScript
import { expect, test } from '@playwright/test';
|
|
import type { Page } from '@playwright/test';
|
|
import type { TMessage } from 'librechat-data-provider';
|
|
import {
|
|
MOCK_ENDPOINTS,
|
|
NEW_CHAT_PATH,
|
|
fetchJson,
|
|
getAccessToken,
|
|
selectMockEndpoint,
|
|
sendMessageAndWaitForCompletion,
|
|
} from '../helpers';
|
|
|
|
/** `mock-model-a` has no price table, so its prompt costs the default rate (6 per
|
|
* million), its 5-minute writes fall back to that input rate, and its 1-hour writes
|
|
* cost twice the prompt rate, as Anthropic bills them. */
|
|
const DEFAULT_RATE = 6;
|
|
const WRITE_5M = DEFAULT_RATE;
|
|
const WRITE_1H = DEFAULT_RATE * 2;
|
|
/** The fake model reports 2000 of its cache writes as 1-hour for `E2E_CACHE_USAGE: 1h` */
|
|
const ONE_HOUR_WRITES = 2000;
|
|
|
|
/** The persisted cost of the reply to `text`, sent in a new chat */
|
|
async function replyCost(page: Page, text: string): Promise<number> {
|
|
await page.goto(NEW_CHAT_PATH, { timeout: 10000 });
|
|
await selectMockEndpoint(page, MOCK_ENDPOINTS[0]);
|
|
const response = await sendMessageAndWaitForCompletion(page, text);
|
|
const { conversationId } = (await response.json()) as { conversationId: string };
|
|
const token = await getAccessToken(page);
|
|
const messages = await fetchJson<TMessage[]>(
|
|
page,
|
|
`/api/messages/${encodeURIComponent(conversationId)}`,
|
|
token,
|
|
);
|
|
const reply = messages.find((message) => !message.isCreatedByUser);
|
|
const usage = (reply?.metadata as { usage?: { cost?: number; cacheWrite?: number } } | undefined)
|
|
?.usage;
|
|
expect(usage?.cacheWrite).toBe(3000);
|
|
expect(typeof usage?.cost).toBe('number');
|
|
return usage?.cost as number;
|
|
}
|
|
|
|
test.describe('Prompt cache write pricing', () => {
|
|
test('1-hour cache writes cost the 1-hour rate, the rest of the call unchanged @scenario:cache-1h-writes-priced-at-1h-rate', async ({
|
|
page,
|
|
}) => {
|
|
const fiveMinute = await replyCost(page, 'E2E_CACHE_USAGE: 5m price check');
|
|
const oneHour = await replyCost(page, 'E2E_CACHE_USAGE: 1h price check');
|
|
|
|
expect(oneHour - fiveMinute).toBeCloseTo((ONE_HOUR_WRITES * (WRITE_1H - WRITE_5M)) / 1e6, 9);
|
|
});
|
|
});
|