Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,29 @@ After running, the operator will append the generated results into output_key. F
]
```

### 🧠 6.1 Named LLM Backends

Besides pointing a serving class at any OpenAI-compatible endpoint, DataFlow ships a few
pre-configured named backends. For example, `APIOrcaRouterServing` wires the operator
stack to the [OrcaRouter](https://www.orcarouter.ai) gateway — an OpenAI-compatible AI
gateway that, like OpenRouter, exposes a provider/model namespace across many models
through a single endpoint, while also adding adaptive routing, automatic failover,
zero-markup inference, observability, guardrails, and agent-tool governance behind the
same endpoint:

```python
from dataflow.serving import APIOrcaRouterServing

# configure LLM serving with the OrcaRouter gateway
# api key needs to be set via `export ORCAROUTER_API_KEY=sk-orca-...`
llm_serving = APIOrcaRouterServing(model_name="orcarouter/auto")

prompted_generator = PromptedGenerator(
llm_serving=llm_serving, # pre-configured LLM backend
system_prompt="Please solve this math problem."
)
```

<details>
<summary><h2>🛠️ 7. Pipelines (Click to expand)</h2></summary>

Expand Down
2 changes: 2 additions & 0 deletions dataflow/serving/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from .api_llm_serving_request import APILLMServing_request
from .api_orca_router_serving import APIOrcaRouterServing
from .local_model_llm_serving import LocalModelLLMServing_vllm
from .local_model_llm_serving import LocalModelLLMServing_sglang
from .api_vlm_serving_openai import APIVLMServing_openai
Expand All @@ -18,6 +19,7 @@
__all__ = [
"APIGoogleVertexAIServing",
"APILLMServing_request",
"APIOrcaRouterServing",
"LocalModelLLMServing_vllm",
"LocalModelLLMServing_sglang",
"APIVLMServing_openai",
Expand Down
55 changes: 55 additions & 0 deletions dataflow/serving/api_orca_router_serving.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
from .api_llm_serving_request import APILLMServing_request


class APIOrcaRouterServing(APILLMServing_request):
"""
OpenAI-compatible serving class backed by the OrcaRouter gateway.

OrcaRouter (https://www.orcarouter.ai) is an OpenAI-compatible AI gateway that,
like OpenRouter, exposes a provider/model namespace across many models through a
single endpoint. On top of that it adds adaptive routing, automatic failover,
zero-markup inference, observability, guardrails, and agent-tool governance on
the same OpenAI-compatible API.

This class reuses the request/retry/formatting logic of APILLMServing_request and
only wires it to OrcaRouter defaults, so DataFlow users can adopt the gateway
without treating it as an anonymous custom base URL.
"""
def __init__(self,
api_url: str = "https://api.orcarouter.ai/v1/chat/completions",
key_name_of_api_key: str = "ORCAROUTER_API_KEY",
model_name: str = "orcarouter/auto",
temperature: float = 0.0,
max_workers: int = 10,
max_retries: int = 5,
connect_timeout: float = 10.0,
read_timeout: float = 120.0,
**configs: dict):
"""
Initialize OrcaRouter serving instance.

Args:
api_url: OrcaRouter OpenAI-compatible chat completions endpoint
key_name_of_api_key: Environment variable holding the OrcaRouter API key
model_name: OrcaRouter model namespace id (e.g. "orcarouter/auto")
temperature: Sampling temperature
max_workers: Number of concurrent workers for batch processing
max_retries: Number of LLM inference retry chances for each input
connect_timeout: Connection timeout in seconds
read_timeout: Read timeout in seconds
**configs: Additional parameters forwarded to the API payload

Note:
Set the API key via `export ORCAROUTER_API_KEY=sk-orca-...` before use.
"""
super().__init__(
api_url=api_url,
key_name_of_api_key=key_name_of_api_key,
model_name=model_name,
temperature=temperature,
max_workers=max_workers,
max_retries=max_retries,
connect_timeout=connect_timeout,
read_timeout=read_timeout,
**configs,
)
45 changes: 45 additions & 0 deletions test/cpu_only/test_api_orca_router_serving.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import pytest
from dataflow.serving import APIOrcaRouterServing


@pytest.mark.api
def test_orca_router_serving_defaults_and_request(dummy_server_base_url, monkeypatch):
monkeypatch.setenv("ORCAROUTER_API_KEY", "dummy-key")

api_url = (
f"{dummy_server_base_url}/v1/chat/completions"
f"?queue=0&ka_interval=0.05&stream=0"
f"&body=hello&think="
)

cli = APIOrcaRouterServing(
api_url=api_url,
model_name="orcarouter/auto",
connect_timeout=1.0,
read_timeout=3.0,
max_retries=1,
max_workers=1,
)

assert cli.api_url == api_url
assert cli.model_name == "orcarouter/auto"
assert cli.api_key == "dummy-key"

_id, resp = cli._api_chat_with_id(
id=0,
payload=[{"role": "user", "content": "hi"}],
model="orcarouter/auto",
is_embedding=False,
)

assert _id == 0
assert resp == "hello"

cli.cleanup()


@pytest.mark.api
def test_orca_router_serving_requires_key(monkeypatch):
monkeypatch.delenv("ORCAROUTER_API_KEY", raising=False)
with pytest.raises(ValueError):
APIOrcaRouterServing()