|
1 | 1 | import asyncio |
| 2 | +import base64 |
2 | 3 | import time |
3 | 4 | from typing import Any, Dict, List, Optional, Callable |
4 | 5 |
|
@@ -50,6 +51,11 @@ class RemoteRolloutProcessor(RolloutProcessor): |
50 | 51 | By default, fetches traces from the Fireworks tracing proxy using rollout_id tags. |
51 | 52 | You can provide a custom output_data_loader for different tracing backends. |
52 | 53 |
|
| 54 | + If a `base_url` is provided in `completion_params` (e.g., "https://dev.api.fireworks.ai/inference/v1"), |
| 55 | + it will be base64-encoded and appended to the model_base_url path as `/encoded_base_url/{encoded}`. |
| 56 | + This allows routing LLM calls through a metadata gateway that can inject tracing while |
| 57 | + forwarding to the actual LLM provider endpoint. |
| 58 | +
|
53 | 59 | See https://evalprotocol.io/tutorial/remote-rollout-processor for documentation. |
54 | 60 | """ |
55 | 61 |
|
@@ -144,6 +150,13 @@ async def _process_row(row: EvaluationRow) -> EvaluationRow: |
144 | 150 | "Model must be provided in row.input_metadata.completion_params or config.completion_params" |
145 | 151 | ) |
146 | 152 |
|
| 153 | + # Extract base_url from completion_params if provided |
| 154 | + llm_base_url: Optional[str] = None |
| 155 | + if row.input_metadata and row.input_metadata.completion_params: |
| 156 | + llm_base_url = row.input_metadata.completion_params.get("base_url") |
| 157 | + if llm_base_url is None and config.completion_params: |
| 158 | + llm_base_url = config.completion_params.get("base_url") |
| 159 | + |
147 | 160 | # Strip non-OpenAI fields from messages before sending to remote |
148 | 161 | allowed_message_fields = {"role", "content", "tool_calls", "tool_call_id", "name"} |
149 | 162 | clean_messages = [] |
@@ -180,6 +193,10 @@ async def _process_row(row: EvaluationRow) -> EvaluationRow: |
180 | 193 | f"/row_id/{meta.row_id}" |
181 | 194 | ) |
182 | 195 |
|
| 196 | + if llm_base_url: |
| 197 | + encoded_base_url = base64.urlsafe_b64encode(llm_base_url.encode()).decode() |
| 198 | + final_model_base_url = f"{final_model_base_url}/encoded_base_url/{encoded_base_url}" |
| 199 | + |
183 | 200 | init_payload: InitRequest = InitRequest( |
184 | 201 | model=model, |
185 | 202 | messages=clean_messages, |
|
0 commit comments