Repository navigation
port(omniroute): #6681 - fix(providers): register openrouter rerank provider #139
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
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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,18 @@ | ||
| import { describe, expect, it } from "vitest"; | ||
|
|
||
| // PR #139 review (Codex): /v1/models/rerank advertises openrouter/cohere/rerank-* | ||
| // but GET /v1/models/info built endpoint metadata from KIND_ENDPOINT which had | ||
| // no `rerank` entry, so the info response returned endpoint: null and clients | ||
| // could not route the newly-discoverable rerank models. Pin the endpoint. | ||
| describe("GET /v1/models/info rerank endpoint metadata", () => { | ||
| it("returns endpoint /v1/rerank for a rerank model", async () => { | ||
| const { GET } = await import("../../src/app/api/v1/models/info/route.js"); | ||
| const res = await GET( | ||
| new Request("http://local.test/v1/models/info?id=openrouter/cohere/rerank-4-pro"), | ||
| ); | ||
| expect(res.status).toBe(200); | ||
| const body = await res.json(); | ||
| expect(body.kind).toBe("rerank"); | ||
| expect(body.endpoint).toBe("/v1/rerank"); | ||
| }); | ||
| }); |
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,62 @@ | ||
| import { beforeEach, describe, expect, it, vi } from "vitest"; | ||
|
|
||
| // PR #139 review (Codex): static OpenRouter rerank rows carry `kind: "rerank"`. | ||
| // Without `buildModelsList` mapping that kind, the LLM filter would advertise | ||
| // rerank-only models as chat models. This test pins both halves of the fix: | ||
| // - /v1/models (LLM filter) MUST NOT surface openrouter rerank models | ||
| // - /v1/models/rerank (rerank filter) MUST surface them | ||
| const mocks = vi.hoisted(() => ({ | ||
| getProviderConnections: vi.fn(), | ||
| getCombos: vi.fn(), | ||
| getCustomModels: vi.fn(), | ||
| getModelAliases: vi.fn(), | ||
| getDisabledModels: vi.fn(), | ||
| })); | ||
|
|
||
| vi.mock("@/lib/localDb", () => ({ | ||
| getProviderConnections: mocks.getProviderConnections, | ||
| getCombos: mocks.getCombos, | ||
| getCustomModels: mocks.getCustomModels, | ||
| getModelAliases: mocks.getModelAliases, | ||
| })); | ||
|
|
||
| vi.mock("@/lib/disabledModelsDb", () => ({ | ||
| getDisabledModels: mocks.getDisabledModels, | ||
| })); | ||
|
|
||
| describe("buildModelsList rerank kind handling", () => { | ||
| beforeEach(() => { | ||
| vi.clearAllMocks(); | ||
| mocks.getProviderConnections.mockResolvedValue([ | ||
| { provider: "openrouter", isActive: true, apiKey: "sk-test" }, | ||
| ]); | ||
| mocks.getCombos.mockResolvedValue([]); | ||
| mocks.getCustomModels.mockResolvedValue([]); | ||
| mocks.getModelAliases.mockResolvedValue({}); | ||
| mocks.getDisabledModels.mockResolvedValue({}); | ||
| }); | ||
|
|
||
| it("excludes rerank-only models from the chat-completions (llm) list", async () => { | ||
| const { buildModelsList, LLM_KIND } = await import( | ||
| "../../src/app/api/v1/models/buildModelsList.js" | ||
| ); | ||
| const models = await buildModelsList([LLM_KIND]); | ||
| const ids = new Set(models.map((m) => m.id)); | ||
|
|
||
| expect(ids.has("openrouter/cohere/rerank-4-pro")).toBe(false); | ||
| expect(ids.has("openrouter/cohere/rerank-4-fast")).toBe(false); | ||
| expect(ids.has("openrouter/cohere/rerank-v3.5")).toBe(false); | ||
| expect(ids.has("openrouter/nvidia/llama-nemotron-rerank-vl-1b-v2:free")).toBe(false); | ||
| }); | ||
|
|
||
| it("surfaces rerank-only models under the rerank kind filter", async () => { | ||
| const { buildModelsList } = await import( | ||
| "../../src/app/api/v1/models/buildModelsList.js" | ||
| ); | ||
| const models = await buildModelsList(["rerank"]); | ||
| const ids = new Set(models.map((m) => m.id)); | ||
|
|
||
| expect(ids.has("openrouter/cohere/rerank-4-pro")).toBe(true); | ||
| expect(ids.has("openrouter/nvidia/llama-nemotron-rerank-vl-1b-v2:free")).toBe(true); | ||
| }); | ||
| }); |
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,69 @@ | ||
| import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"; | ||
|
|
||
| // PR #139 review (Codex): pingModelByKind used to fall every non-embedding/ | ||
| // image/stt kind through to POST /api/v1/chat/completions, so testing a | ||
| // rerank-only model reported a chat-completion failure. Pin the new rerank | ||
| // branch: it MUST hit /api/v1/rerank and MUST NOT hit chat completions. | ||
| const mocks = vi.hoisted(() => ({ | ||
| getApiKeys: vi.fn(), | ||
| getConsistentMachineId: vi.fn(), | ||
| })); | ||
|
|
||
| vi.mock("@/lib/localDb", () => ({ | ||
| getApiKeys: mocks.getApiKeys, | ||
| })); | ||
|
|
||
| vi.mock("@/shared/utils/machineId", () => ({ | ||
| getConsistentMachineId: mocks.getConsistentMachineId, | ||
| })); | ||
|
|
||
| const originalFetch = global.fetch; | ||
|
|
||
| describe("pingModelByKind rerank endpoint", () => { | ||
| let calls; | ||
|
|
||
| beforeEach(() => { | ||
| vi.resetModules(); | ||
| mocks.getApiKeys.mockResolvedValue([]); | ||
| mocks.getConsistentMachineId.mockResolvedValue("machine-id-test"); | ||
| calls = []; | ||
| global.fetch = vi.fn(async (url) => { | ||
| calls.push(String(url)); | ||
| return { | ||
| ok: true, | ||
| status: 200, | ||
| text: async () => JSON.stringify({ results: [{ index: 0, relevance_score: 0.9 }] }), | ||
| }; | ||
| }); | ||
| }); | ||
|
|
||
| afterEach(() => { | ||
| global.fetch = originalFetch; | ||
| }); | ||
|
|
||
| it("calls POST /api/v1/rerank, not /api/v1/chat/completions", async () => { | ||
| const { pingModelByKind } = await import( | ||
| "../../src/app/api/models/test/ping.js" | ||
| ); | ||
| const result = await pingModelByKind( | ||
| "openrouter/cohere/rerank-4-pro", | ||
| "rerank", | ||
| "http://local.test", | ||
| ); | ||
|
|
||
| expect(result.ok).toBe(true); | ||
| expect(calls.some((u) => u === "http://local.test/api/v1/rerank")).toBe(true); | ||
| expect(calls.some((u) => u.endsWith("/api/v1/chat/completions"))).toBe(false); | ||
|
|
||
| const [url, init] = global.fetch.mock.calls[0]; | ||
| expect(url).toBe("http://local.test/api/v1/rerank"); | ||
| expect(init.method).toBe("POST"); | ||
| const body = JSON.parse(init.body); | ||
| expect(body).toMatchObject({ | ||
| model: "openrouter/cohere/rerank-4-pro", | ||
| query: "ping", | ||
| documents: ["hello world"], | ||
| top_n: 1, | ||
| }); | ||
| }); | ||
| }); |
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,42 @@ | ||
| import { describe, it, expect } from "vitest"; | ||
| import { | ||
| PROVIDERS, | ||
| PROVIDER_MEDIA, | ||
| PROVIDER_MODELS, | ||
| } from "open-sse/providers/index.js"; | ||
| import { deriveRerankUrl } from "open-sse/handlers/rerankCore.js"; | ||
| import { parseModel } from "open-sse/services/model.js"; | ||
| import openrouter from "open-sse/providers/registry/openrouter.js"; | ||
|
|
||
| // #6574 — OpenRouter exposes a Cohere-compatible POST /api/v1/rerank endpoint | ||
| // (confirmed live: openrouter.ai/cohere/rerank-4-pro). The capability/model catalog | ||
| // missed rerank registration, so clients could not discover or route OpenRouter rerank | ||
| // models reliably. | ||
| describe("openrouter rerank provider registration", () => { | ||
| it("parseModel resolves openrouter multi-slash rerank model id", () => { | ||
| expect(parseModel("openrouter/cohere/rerank-4-pro")).toEqual({ | ||
| provider: "openrouter", | ||
| model: "cohere/rerank-4-pro", | ||
| isAlias: false, | ||
| providerAlias: "openrouter", | ||
| }); | ||
| }); | ||
| it("openrouter registry includes rerank service kind", () => { | ||
| expect(openrouter.serviceKinds).toContain("rerank"); | ||
| }); | ||
|
|
||
| it("PROVIDER_MODELS.openrouter contains the rerank model ids", () => { | ||
| const ids = new Set(PROVIDER_MODELS.openrouter.map((m) => m.id)); | ||
| expect(ids.has("cohere/rerank-4-pro")).toBe(true); | ||
| expect(ids.has("cohere/rerank-4-fast")).toBe(true); | ||
| expect(ids.has("cohere/rerank-v3.5")).toBe(true); | ||
|
|
||
| const rerank = PROVIDER_MODELS.openrouter.find((m) => m.id === "cohere/rerank-4-pro"); | ||
| expect(rerank?.kind).toBe("rerank"); | ||
| }); | ||
|
|
||
| it("deriveRerankUrl resolves openrouter to its Cohere-compatible /rerank endpoint", () => { | ||
| const url = deriveRerankUrl(PROVIDERS.openrouter, PROVIDER_MEDIA.openrouter); | ||
| expect(url).toBe("https://openrouter.ai/api/v1/rerank"); | ||
| }); | ||
| }); |
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.