-
Notifications
You must be signed in to change notification settings - Fork 1.2k
feat(providers): add OrcaRouter provider #361
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| # SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| """OrcaRouter provider package (api.orcarouter.ai OpenAI-compatible gateway).""" | ||
|
|
||
| from .provider import ORCAROUTER_BASE_URL, REGISTRY_PATH, OrcaRouterProvider | ||
|
|
||
| __all__ = ["ORCAROUTER_BASE_URL", "REGISTRY_PATH", "OrcaRouterProvider"] |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| # Token-budget metadata for the OrcaRouter provider (api.orcarouter.ai). | ||
| # | ||
| # ``orcarouter/auto`` routes each request to the best available frontier | ||
| # model for the task, so the exact backend context window varies. The | ||
| # budgets below mirror the conservative Claude-class defaults already | ||
| # shipped in this package; tune with SKILLSPECTOR_MODEL_REGISTRY if your | ||
| # routing target needs more headroom. | ||
| # | ||
| # Format: | ||
| # models: | ||
| # "<model-label>": | ||
| # context_length: <int> # total context window in tokens (required) | ||
| # max_output_tokens: <int> # model's max output cap (optional) | ||
|
|
||
| models: | ||
| "orcarouter/auto": | ||
| context_length: 200000 | ||
| max_output_tokens: 64000 | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| # SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| """OrcaRouter provider — model-routing gateway via api.orcarouter.ai. | ||
|
|
||
| Reads ``ORCAROUTER_API_KEY`` for credentials and serves the OpenAI-compatible | ||
| ``https://api.orcarouter.ai/v1`` endpoint (optionally overridden with | ||
| ``ORCAROUTER_BASE_URL``). The ``orcarouter/auto`` model routes each request | ||
| to the best available frontier model for the task, so no per-model API key | ||
| or model id is required. | ||
| """ | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import os | ||
| from pathlib import Path | ||
|
|
||
| from langchain_core.language_models.chat_models import BaseChatModel | ||
|
|
||
| from skillspector.providers import registry | ||
| from skillspector.providers.chat_models import create_openai_compatible_chat_model | ||
|
|
||
| # Default endpoint; overridden by ``ORCAROUTER_BASE_URL`` when set. | ||
| ORCAROUTER_BASE_URL = "https://api.orcarouter.ai/v1" | ||
|
|
||
| REGISTRY_PATH = str(Path(__file__).with_name("model_registry.yaml")) | ||
|
|
||
|
|
||
| class OrcaRouterProvider: | ||
| """OrcaRouter credentials + bundled-YAML metadata provider.""" | ||
|
|
||
| DEFAULT_MODEL = "orcarouter/auto" | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [P1] |
||
| SLOT_DEFAULTS: dict[str, str] = {} | ||
|
|
||
| def resolve_credentials(self) -> tuple[str, str | None] | None: | ||
| """Return ``(api_key, base_url)`` from ``ORCAROUTER_API_KEY`` / ``ORCAROUTER_BASE_URL``.""" | ||
| api_key = os.environ.get("ORCAROUTER_API_KEY", "").strip() | ||
| if not api_key: | ||
| return None | ||
| base_url = os.environ.get("ORCAROUTER_BASE_URL", "").strip() or ORCAROUTER_BASE_URL | ||
| return api_key, base_url | ||
|
|
||
| def create_chat_model( | ||
| self, | ||
| model: str, | ||
| *, | ||
| max_tokens: int, | ||
| timeout: float | None = 120, | ||
| ) -> BaseChatModel | None: | ||
| """Create ``ChatOpenAI`` for the OrcaRouter OpenAI-compatible endpoint.""" | ||
| return create_openai_compatible_chat_model( | ||
| model=model, | ||
| credentials=self.resolve_credentials(), | ||
| max_tokens=max_tokens, | ||
| timeout=timeout, | ||
| ) | ||
|
|
||
| def get_context_length(self, model: str) -> int | None: | ||
| return registry.lookup_context_length(REGISTRY_PATH, model) | ||
|
|
||
| def get_max_output_tokens(self, model: str) -> int | None: | ||
| return registry.lookup_max_output_tokens(REGISTRY_PATH, model) | ||
|
|
||
| def resolve_model(self, slot: str = "default") -> str: | ||
| """Resolve model: ``SKILLSPECTOR_MODEL`` env > slot default > ``DEFAULT_MODEL``.""" | ||
| user_input = os.environ.get("SKILLSPECTOR_MODEL", "").strip() | ||
| return user_input or self.SLOT_DEFAULTS.get(slot, "") or self.DEFAULT_MODEL | ||
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.
[P2] A fixed 200k/64k budget cannot describe
orcarouter/auto, whose candidate backend changes per request and whose default allowed-model pattern matches every chat model the account can access. These values make SkillSpector accept roughly 150k input tokens and request up to 50k output tokens, which can exceed a selected backend context or output cap and turn larger scans into provider errors. Please use limits OrcaRouter contractually guarantees for every auto-router candidate, or avoid publishing metadata for this dynamic alias and require a concrete/custom-router registry entry. Reference: auto router.