Skip to content

Commit eabeacf

Browse files
author
Dylan Huang
committed
pass subpath based metadata method
1 parent 62867fe commit eabeacf

File tree

3 files changed

+19
-23
lines changed

3 files changed

+19
-23
lines changed

eval_protocol/pytest/remote_rollout_processor.py

Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -13,38 +13,33 @@
1313

1414
def _attach_metadata_to_model_base_url(model_base_url: Optional[str], metadata: RolloutMetadata) -> Optional[str]:
1515
"""
16-
Attach rollout metadata as query parameters to the model_base_url.
16+
Attach rollout metadata as path segments to the model_base_url.
1717
1818
Args:
1919
model_base_url: The base URL for the model API
2020
metadata: The rollout metadata containing IDs to attach
2121
2222
Returns:
23-
The model_base_url with query parameters attached, or None if model_base_url is None
23+
The model_base_url with path segments attached, or None if model_base_url is None
2424
"""
2525
if model_base_url is None:
2626
return None
2727

28-
# Parse existing query parameters
29-
from urllib.parse import urlparse, parse_qs, urlencode, urlunparse
28+
# Parse the URL to extract components
29+
from urllib.parse import urlparse, urlunparse
3030

3131
parsed = urlparse(model_base_url)
32-
query_params = parse_qs(parsed.query)
33-
34-
# Add rollout metadata as query parameters
35-
query_params.update(
36-
{
37-
"rollout_id": [metadata.rollout_id],
38-
"invocation_id": [metadata.invocation_id],
39-
"experiment_id": [metadata.experiment_id],
40-
"run_id": [metadata.run_id],
41-
"row_id": [metadata.row_id],
42-
}
43-
)
44-
45-
# Rebuild the URL with new query parameters
46-
new_query = urlencode(query_params, doseq=True)
47-
new_parsed = parsed._replace(query=new_query)
32+
33+
# Build the path with metadata segments
34+
# Format: /rollout_id/{rollout_id}/invocation_id/{invocation_id}/experiment_id/{experiment_id}/run_id/{run_id}/row_id/{row_id}
35+
metadata_path = f"/rollout_id/{metadata.rollout_id}/invocation_id/{metadata.invocation_id}/experiment_id/{metadata.experiment_id}/run_id/{metadata.run_id}/row_id/{metadata.row_id}"
36+
37+
# Append metadata path to existing path, ensuring proper path joining
38+
base_path = parsed.path.rstrip("/")
39+
new_path = f"{base_path}{metadata_path}"
40+
41+
# Rebuild the URL with the new path
42+
new_parsed = parsed._replace(path=new_path)
4843
return urlunparse(new_parsed)
4944

5045

@@ -53,14 +48,14 @@ class RemoteRolloutProcessor(RolloutProcessor):
5348
Rollout processor that triggers a remote HTTP server to perform the rollout.
5449
5550
The processor automatically attaches rollout metadata (rollout_id, invocation_id,
56-
experiment_id, run_id, row_id) as query parameters to the model_base_url when
51+
experiment_id, run_id, row_id) as path segments to the model_base_url when
5752
provided. This passes along rollout context to the remote server for use in
5853
LLM API calls.
5954
6055
Example:
6156
If model_base_url is "https://api.openai.com/v1" and rollout_id is "abc123",
6257
the enhanced URL will be:
63-
"https://api.openai.com/v1?rollout_id=abc123&invocation_id=def456&..."
58+
"https://api.openai.com/v1/rollout_id/abc123/invocation_id/def456/experiment_id/ghi789/run_id/jkl012/row_id/mno345"
6459
6560
See https://evalprotocol.io/tutorial/remote-rollout-processor for documentation.
6661
"""

eval_protocol/types/remote_rollout_processor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class InitRequest(BaseModel):
3737
3838
Example:
3939
If model_base_url is "https://api.openai.com/v1", it will be enhanced to:
40-
"https://api.openai.com/v1?rollout_id=abc123&invocation_id=def456&experiment_id=ghi789&run_id=jkl012&row_id=mno345"
40+
"https://api.openai.com/v1/rollout_id/abc123/invocation_id/def456/experiment_id/ghi789/run_id/jkl012/row_id/mno345/chat/completions"
4141
"""
4242

4343
metadata: RolloutMetadata

tests/remote_server/remote_server.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ def _worker():
4343
if req.model_base_url:
4444
print(f"Using custom model_base_url: {req.model_base_url}")
4545
# Create a new Langfuse OpenAI client with the custom base URL
46+
# The URL already contains the metadata as path segments, so we can use it directly
4647
custom_openai = openai.OpenAI(api_key=os.getenv("OPENAI_API_KEY"), base_url=req.model_base_url)
4748
completion = custom_openai.chat.completions.create(**completion_kwargs)
4849
else:

0 commit comments

Comments
 (0)