a lot
This commit is contained in:
@@ -58,6 +58,24 @@ describe('proxy', () => {
|
||||
expect(JSON.parse(fetchImpl.mock.calls[0][1].body)).toEqual(body);
|
||||
});
|
||||
|
||||
it('enforces the configured context and IP limits and records cost', async () => {
|
||||
const fetchImpl = vi.fn()
|
||||
.mockResolvedValueOnce(response(JSON.stringify({ id: 'c', cost: 0 })))
|
||||
.mockResolvedValue(response(JSON.stringify({ id: 'c', cost: 10 })));
|
||||
const app = createProxyApp({ keys: ['key'], fetchImpl, maxContextTokens: 100 });
|
||||
await request(app).post('/oai/v1/chat/completions').set('X-Real-IP', '198.51.100.1').send({ model: 'm', max_tokens: 101 }).expect(400);
|
||||
await request(app).post('/oai/v1/chat/completions').set('X-Real-IP', '198.51.100.1').send({ model: 'm', max_tokens: 1 }).expect(200);
|
||||
await request(app).post('/oai/v1/chat/completions').set('X-Real-IP', '198.51.100.1').send({ model: 'm', max_tokens: 1 }).expect(200);
|
||||
await request(app).post('/oai/v1/chat/completions').set('X-Real-IP', '198.51.100.1').send({ model: 'm', max_tokens: 1 }).expect(429);
|
||||
});
|
||||
|
||||
it('adds the global context limit to model listings', async () => {
|
||||
const fetchImpl = vi.fn().mockResolvedValue(response('{"data":[{"id":"m"}]}'));
|
||||
const app = createProxyApp({ keys: ['key'], fetchImpl, maxContextTokens: 123 });
|
||||
const result = await request(app).get('/oai/v1/models').expect(200);
|
||||
expect(result.body.data[0]).toMatchObject({ context_length: 123, context_window: 123, max_context_tokens: 123 });
|
||||
});
|
||||
|
||||
it('passes through streaming responses', async () => {
|
||||
const fetchImpl = vi.fn().mockResolvedValue(response('data: {"delta":"Hi"}\n\ndata: [DONE]\n\n', {
|
||||
headers: { 'content-type': 'text/event-stream' },
|
||||
|
||||
Reference in New Issue
Block a user