Skip to content
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions e2e/helpers/selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -623,6 +623,9 @@ export const Selectors = {
get apiKeyInput(): string {
return byTestId('remote-apikey-input');
},
get timeoutInput(): string {
return byTestId('remote-timeout-input');
},
get addModelButton(): string {
return byTestId('add-model-button');
},
Expand All @@ -636,6 +639,9 @@ export const Selectors = {
get apiKeyInput(): string {
return byTestId('server-details-apikey-input');
},
get timeoutInput(): string {
return byTestId('server-details-timeout-input');
},
get removeButton(): string {
return byTestId('remove-server-button');
},
Expand Down
31 changes: 31 additions & 0 deletions src/api/__tests__/completionEngines.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ describe('OpenAICompletionEngine', () => {
'sk-key',
expect.any(Object), // AbortSignal
onToken,
undefined, // timeoutMs
);

expect(result).toEqual(mockResult);
Expand Down Expand Up @@ -186,6 +187,7 @@ describe('OpenAICompletionEngine', () => {
'sk-key',
expect.any(Object),
undefined,
undefined,
);
});

Expand Down Expand Up @@ -215,6 +217,7 @@ describe('OpenAICompletionEngine', () => {
'sk-key',
expect.any(Object),
undefined,
undefined,
);
});

Expand Down Expand Up @@ -244,6 +247,7 @@ describe('OpenAICompletionEngine', () => {
'sk-key',
expect.any(Object),
undefined,
undefined,
);
});

Expand Down Expand Up @@ -272,6 +276,32 @@ describe('OpenAICompletionEngine', () => {
await engine.stopCompletion();
});

// The engine carries the timeoutMs it was constructed with and forwards it
// raw (no normalization here) to streamChatCompletion. A rebuilt engine (on
// the next setRemoteModel) therefore applies an edited value.
it('forwards the constructed timeoutMs to streamChatCompletion', async () => {
const timedEngine = new OpenAICompletionEngine(
'http://localhost:1234',
'test-model',
'sk-key',
600000,
);
mockedStreamChat.mockResolvedValueOnce({text: '', content: ''});

await timedEngine.completion({
messages: [{role: 'user', content: 'Hi'}],
} as any);

expect(mockedStreamChat).toHaveBeenCalledWith(
expect.any(Object),
'http://localhost:1234',
'sk-key',
expect.any(Object), // AbortSignal
undefined, // callback
600000, // raw timeoutMs forwarded, not normalized
);
});

it('creates engine without api key', () => {
const noKeyEngine = new OpenAICompletionEngine(
'http://localhost:1234',
Expand All @@ -288,6 +318,7 @@ describe('OpenAICompletionEngine', () => {
undefined,
expect.any(Object),
undefined,
undefined,
);
});
});
Loading
Loading