forked from cline/cline
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
feat: add dynamic model discovery for xAI provider #8900
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
hannesrudolph
wants to merge
8
commits into
main
Choose a base branch
from
feat/xai-dynamic-model-discovery
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.
+659
−167
Open
Changes from 7 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
a981925
feat(xai): add dynamic model discovery with correct pricing
hannesrudolph d6e594e
fix(xai): enforce positive integer for xaiModelContextWindow and hand…
hannesrudolph 427fbec
chore: resolve merge conflicts from main
hannesrudolph 1c1ed4e
fix: update requesty provider to use new calculateApiCostOpenAI signa…
hannesrudolph dd6d37e
fix: update cost tests to match new calculateApiCost signature
hannesrudolph b69e2b5
fix: update remaining providers to use new calculateApiCost signature
hannesrudolph 27830f2
fix: update Task.ts to use new calculateApiCost signature
hannesrudolph 8c81c55
fix: update XAI component links to point to the correct documentation
hannesrudolph 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
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
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,56 @@ | ||
| import { describe, it, expect, vi, beforeEach } from "vitest" | ||
| import axios from "axios" | ||
|
|
||
| vi.mock("axios") | ||
|
|
||
| import { getXaiModels } from "../xai" | ||
| import { xaiModels } from "@roo-code/types" | ||
hannesrudolph marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| describe("getXaiModels", () => { | ||
| const mockedAxios = axios as unknown as { get: ReturnType<typeof vi.fn> } | ||
|
|
||
| beforeEach(() => { | ||
| vi.clearAllMocks() | ||
| }) | ||
|
|
||
| it("returns mapped models with pricing and modalities (augmenting static info when available)", async () => { | ||
| mockedAxios.get = vi.fn().mockResolvedValue({ | ||
| data: { | ||
| models: [ | ||
| { | ||
| id: "grok-3", | ||
| input_modalities: ["text"], | ||
| output_modalities: ["text"], | ||
| prompt_text_token_price: 2000, // 2000 fractional cents = $0.20 per 1M tokens | ||
| cached_prompt_text_token_price: 500, // 500 fractional cents = $0.05 per 1M tokens | ||
| completion_text_token_price: 10000, // 10000 fractional cents = $1.00 per 1M tokens | ||
| aliases: ["grok-3-latest"], | ||
| }, | ||
| ], | ||
| }, | ||
| }) | ||
|
|
||
| const result = await getXaiModels("key", "https://api.x.ai/v1") | ||
| expect(result["grok-3"]).toBeDefined() | ||
| expect(result["grok-3"]?.supportsImages).toBe(false) | ||
| expect(result["grok-3"]?.inputPrice).toBeCloseTo(0.2) // $0.20 per 1M tokens | ||
| expect(result["grok-3"]?.outputPrice).toBeCloseTo(1.0) // $1.00 per 1M tokens | ||
| expect(result["grok-3"]?.cacheReadsPrice).toBeCloseTo(0.05) // $0.05 per 1M tokens | ||
| // aliases are not added to avoid UI duplication | ||
| expect(result["grok-3-latest"]).toBeUndefined() | ||
| }) | ||
|
|
||
| it("returns empty object on schema mismatches (graceful degradation)", async () => { | ||
| mockedAxios.get = vi.fn().mockResolvedValue({ | ||
| data: { data: [{ bogus: true }] }, | ||
| }) | ||
| const result = await getXaiModels("key") | ||
| expect(result).toEqual({}) | ||
| }) | ||
|
|
||
| it("includes Authorization header when apiKey provided", async () => { | ||
| mockedAxios.get = vi.fn().mockResolvedValue({ data: { data: [] } }) | ||
hannesrudolph marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| await getXaiModels("secret") | ||
| expect((axios.get as any).mock.calls[0][1].headers.Authorization).toBe("Bearer secret") | ||
| }) | ||
| }) | ||
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
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.