-
Notifications
You must be signed in to change notification settings - Fork 1.3k
feat: add FIM support to KilocodeOpenrouterHandler #3492
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
5187ec9 to
0cfe7ed
Compare
- Add supportsFim() method to check if model supports FIM (codestral models) - Add completeFim() method for non-streaming FIM completions - Add streamFim() method for streaming FIM completions - Reuse customRequestOptions() for header management (DRY principle) - Use DEFAULT_HEADERS for consistency with chat completions - Add comprehensive test coverage with 6 new test cases - Implementation follows the same pattern as KiloCode.ts for consistency All tests pass (14/14)
0cfe7ed to
6374a1c
Compare
b2903be to
e1f904b
Compare
| it("completeFim makes request with correct parameters", async () => { | ||
| const handler = new KilocodeOpenrouterHandler({ | ||
| ...mockOptions, | ||
| kilocodeModel: "mistral/codestral-latest", | ||
| kilocodeOrganizationId: "test-org-id", | ||
| }) | ||
|
|
||
| const mockStream = new ReadableStream({ | ||
| start(controller) { | ||
| controller.enqueue( | ||
| new TextEncoder().encode('data: {"choices":[{"delta":{"content":"completed "}}]}\n'), | ||
| ) | ||
| controller.enqueue(new TextEncoder().encode('data: {"choices":[{"delta":{"content":"code"}}]}\n')) | ||
| controller.enqueue(new TextEncoder().encode("data: [DONE]\n")) | ||
| controller.close() | ||
| }, | ||
| }) | ||
|
|
||
| const mockResponse = { | ||
| ok: true, | ||
| body: mockStream, | ||
| } | ||
|
|
||
| global.fetch = vitest.fn().mockResolvedValue(mockResponse) | ||
|
|
||
| const result = await handler.completeFim("prefix code", "suffix code", "test-task-id") | ||
|
|
||
| expect(result).toBe("completed code") | ||
| expect(global.fetch).toHaveBeenCalledWith( | ||
| expect.any(URL), | ||
| expect.objectContaining({ | ||
| method: "POST", | ||
| headers: expect.objectContaining({ | ||
| "Content-Type": "application/json", | ||
| Accept: "application/json", | ||
| "x-api-key": "test-token", | ||
| Authorization: "Bearer test-token", | ||
| [X_KILOCODE_TASKID]: "test-task-id", | ||
| [X_KILOCODE_ORGANIZATIONID]: "test-org-id", | ||
| }), | ||
| body: expect.stringContaining('"stream":true'), | ||
| }), | ||
| ) | ||
| }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
delete test, I think?
All tests pass (14/14)
Context
Implementation
Screenshots
How to Test
Get in Touch