forked from cline/cline
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Add support for LLM routing using developer preferences #6075
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
Open
adilhafeez
wants to merge
22
commits into
RooCodeInc:main
Choose a base branch
from
adilhafeez:adil/add_archgw
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,163
−37
Open
Changes from 21 commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
82386ea
initial commit
adilhafeez 369933c
add more changes
adilhafeez b994004
add more changes
adilhafeez 8848a3d
add more changes
adilhafeez a428f64
Merge branch 'main' into adil/add_archgw
adilhafeez 5b8eed2
add more changes
adilhafeez ffd9487
fix tests
adilhafeez 449a38a
revert locales
adilhafeez 36d01ee
Merge branch 'main' into adil/add_archgw
adilhafeez 9a5a8cd
add more changes
adilhafeez 3f89636
add tests
adilhafeez 9ac61bd
add provider tests
adilhafeez 41a42af
add fetcher test
adilhafeez 1f525e1
rename
adilhafeez abbb8fd
remove unnecessary log lines
adilhafeez ef2be7c
fix more
adilhafeez b5e0e6e
use same format as arch_config for usage preferences in request path
adilhafeez 1c26001
Merge remote-tracking branch 'RooCodeInc/main' into adil/add_archgw
adilhafeez 6f1be84
fix tests
adilhafeez 21469bc
Merge branch 'main' into adil/add_archgw
adilhafeez d72040c
add validation and i8n changes
adilhafeez 4ad271f
spellcheck
adilhafeez File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import type { ModelInfo } from "../model.js" | ||
|
||
export const archgwDefaultModelId = "openai/gpt-4.1" | ||
|
||
export const archgwDefaultModelInfo: ModelInfo = { | ||
maxTokens: 32_768, | ||
contextWindow: 1_047_576, | ||
supportsImages: true, | ||
supportsPromptCache: true, | ||
inputPrice: 2, | ||
outputPrice: 8, | ||
cacheReadsPrice: 0.5, | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,214 @@ | ||
// npx vitest run src/api/providers/__tests__/archgw.spec.ts | ||
|
||
import { Anthropic } from "@anthropic-ai/sdk" | ||
import { ArchGwHandler } from "../archgw" | ||
import { ApiHandlerOptions } from "../../../shared/api" | ||
|
||
const mockCreate = vitest.fn() | ||
|
||
vitest.mock("openai", () => { | ||
return { | ||
__esModule: true, | ||
default: vitest.fn().mockImplementation(() => ({ | ||
chat: { | ||
completions: { | ||
create: mockCreate.mockImplementation((options) => { | ||
if (!options.stream) { | ||
return Promise.resolve({ | ||
id: "test-completion", | ||
choices: [ | ||
{ | ||
message: { role: "assistant", content: "ArchGW response" }, | ||
finish_reason: "stop", | ||
index: 0, | ||
}, | ||
], | ||
usage: { | ||
prompt_tokens: 10, | ||
completion_tokens: 5, | ||
total_tokens: 15, | ||
}, | ||
}) | ||
} | ||
|
||
// Streaming: return an object with withResponse() method | ||
return { | ||
withResponse: () => ({ | ||
data: { | ||
[Symbol.asyncIterator]: async function* () { | ||
yield { | ||
choices: [ | ||
{ | ||
delta: { content: "ArchGW stream" }, | ||
index: 0, | ||
}, | ||
], | ||
usage: null, | ||
} | ||
yield { | ||
choices: [ | ||
{ | ||
delta: {}, | ||
index: 0, | ||
}, | ||
], | ||
usage: { | ||
prompt_tokens: 10, | ||
completion_tokens: 5, | ||
total_tokens: 15, | ||
}, | ||
} | ||
}, | ||
}, | ||
}), | ||
} | ||
}), | ||
}, | ||
}, | ||
})), | ||
} | ||
}) | ||
|
||
describe("ArchGwHandler", () => { | ||
let handler: ArchGwHandler | ||
let mockOptions: ApiHandlerOptions | ||
|
||
beforeEach(() => { | ||
mockOptions = { | ||
archgwModelId: "arch-model", | ||
archgwBaseUrl: "http://localhost:12000/v1", | ||
archgwApiKey: "test-key", | ||
archgwPreferenceConfig: "test-pref", | ||
} | ||
handler = new ArchGwHandler(mockOptions) | ||
mockCreate.mockClear() | ||
}) | ||
|
||
describe("constructor", () => { | ||
it("should initialize with provided options", () => { | ||
expect(handler).toBeInstanceOf(ArchGwHandler) | ||
expect(handler.preferenceConfig).toBe("test-pref") | ||
}) | ||
|
||
it("should use default base URL if not provided", () => { | ||
const handlerWithoutUrl = new ArchGwHandler({ | ||
archgwModelId: "arch-model", | ||
archgwApiKey: "test-key", | ||
}) | ||
expect(handlerWithoutUrl).toBeInstanceOf(ArchGwHandler) | ||
}) | ||
|
||
it("should not set preferenceConfig if not provided", () => { | ||
const handlerNoPref = new ArchGwHandler({ | ||
archgwModelId: "arch-model", | ||
archgwApiKey: "test-key", | ||
}) | ||
expect(handlerNoPref.preferenceConfig).toBeUndefined() | ||
}) | ||
|
||
it("should set preferenceConfig to empty string if provided as empty", () => { | ||
const handlerEmptyPref = new ArchGwHandler({ | ||
archgwModelId: "arch-model", | ||
archgwApiKey: "test-key", | ||
archgwPreferenceConfig: "", | ||
}) | ||
expect(handlerEmptyPref.preferenceConfig).toBe("") | ||
}) | ||
}) | ||
|
||
describe("createMessage", () => { | ||
const systemPrompt = "You are a helpful assistant." | ||
const messages: Anthropic.Messages.MessageParam[] = [ | ||
{ | ||
role: "user", | ||
content: "Hello!", | ||
}, | ||
] | ||
|
||
it("should handle streaming responses", async () => { | ||
const stream = handler.createMessage(systemPrompt, messages) | ||
const chunks: any[] = [] | ||
for await (const chunk of stream) { | ||
chunks.push(chunk) | ||
} | ||
|
||
expect(chunks.length).toBeGreaterThan(0) | ||
const textChunks = chunks.filter((chunk) => chunk.type === "text") | ||
expect(textChunks).toHaveLength(1) | ||
expect(textChunks[0].text).toBe("ArchGW stream") | ||
}) | ||
|
||
it("should handle API errors", async () => { | ||
mockCreate.mockImplementationOnce(() => ({ | ||
withResponse: () => { | ||
throw new Error("API Error") | ||
}, | ||
})) | ||
|
||
const stream = handler.createMessage(systemPrompt, messages) | ||
|
||
await expect(async () => { | ||
for await (const _chunk of stream) { | ||
// Should not reach here | ||
} | ||
}).rejects.toThrow("archgw streaming error: API Error") | ||
}) | ||
}) | ||
|
||
describe("completePrompt", () => { | ||
it("should complete prompt successfully", async () => { | ||
const result = await handler.completePrompt("Test prompt") | ||
expect(result).toBe("ArchGW response") | ||
expect(mockCreate).toHaveBeenCalledWith({ | ||
model: mockOptions.archgwModelId, | ||
messages: [{ role: "user", content: "Test prompt" }], | ||
temperature: 0, | ||
max_tokens: 32768, | ||
metadata: { archgw_preference_config: "test-pref" }, | ||
}) | ||
}) | ||
|
||
it("should not include archgw_preference_config in metadata if preferenceConfig is not set", async () => { | ||
const handlerNoPref = new ArchGwHandler({ | ||
archgwModelId: "arch-model", | ||
archgwApiKey: "test-key", | ||
}) | ||
mockCreate.mockClear() | ||
await handlerNoPref.completePrompt("Test prompt") | ||
const call = mockCreate.mock.calls[0][0] | ||
expect(call.metadata).toBeUndefined() | ||
}) | ||
|
||
it("should include archgw_preference_config in metadata if preferenceConfig is empty string", async () => { | ||
const preferenceConfig = `- name: code generation | ||
model: gpt-4o-mini | ||
usage: generating new code snippets | ||
- name: code understanding | ||
model: gpt-4.1 | ||
usage: understand and explain existing code snippets | ||
` | ||
const handlerEmptyPref = new ArchGwHandler({ | ||
archgwModelId: "arch-modael", | ||
archgwApiKey: "test-key", | ||
archgwPreferenceConfig: preferenceConfig, | ||
}) | ||
mockCreate.mockClear() | ||
await handlerEmptyPref.completePrompt("Test prompt") | ||
const call = mockCreate.mock.calls[0][0] | ||
expect(call.metadata).toEqual({ archgw_preference_config: preferenceConfig }) | ||
}) | ||
|
||
it("should handle API errors", async () => { | ||
mockCreate.mockRejectedValueOnce(new Error("API Error")) | ||
await expect(handler.completePrompt("Test prompt")).rejects.toThrow("archgw completion error: API Error") | ||
}) | ||
|
||
it("should handle empty response", async () => { | ||
mockCreate.mockResolvedValueOnce({ | ||
choices: [{ message: { content: "" } }], | ||
}) | ||
const result = await handler.completePrompt("Test prompt") | ||
expect(result).toBe("") | ||
}) | ||
}) | ||
}) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.