maybe fix
This commit is contained in:
@@ -69,12 +69,39 @@ describe('proxy', () => {
|
||||
expect(JSON.parse(fetchImpl.mock.calls[0][1].body)).toEqual(body);
|
||||
});
|
||||
|
||||
it('normalizes max_completion_tokens for OpenCode Go providers', async () => {
|
||||
const fetchImpl = vi.fn().mockResolvedValue(response('{"id":"completion-1"}'));
|
||||
const app = createProxyApp({ keys: ['key'], fetchImpl });
|
||||
|
||||
await request(app).post('/oai/v1/chat/completions').send({
|
||||
model: 'kimi-k3', messages: [{ role: 'user', content: 'Hi' }],
|
||||
max_completion_tokens: 4096, stream: true, stream_options: { include_usage: true },
|
||||
}).expect(200);
|
||||
|
||||
expect(JSON.parse(fetchImpl.mock.calls[0][1].body)).toEqual({
|
||||
model: 'kimi-k3', messages: [{ role: 'user', content: 'Hi' }],
|
||||
max_tokens: 4096, stream: true, stream_options: { include_usage: true },
|
||||
});
|
||||
});
|
||||
|
||||
it('prefers max_tokens when both token limit field names are supplied', async () => {
|
||||
const fetchImpl = vi.fn().mockResolvedValue(response('{"id":"completion-1"}'));
|
||||
const app = createProxyApp({ keys: ['key'], fetchImpl });
|
||||
|
||||
await request(app).post('/oai/v1/chat/completions').send({
|
||||
model: 'm', max_tokens: 2048, max_completion_tokens: 4096,
|
||||
}).expect(200);
|
||||
|
||||
expect(JSON.parse(fetchImpl.mock.calls[0][1].body)).toEqual({ model: 'm', max_tokens: 2048 });
|
||||
});
|
||||
|
||||
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_completion_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);
|
||||
|
||||
Reference in New Issue
Block a user