1313
1414def _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 """
0 commit comments