-
Notifications
You must be signed in to change notification settings - Fork 10
support extra headers #373
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 |
|---|---|---|
|
|
@@ -13,8 +13,7 @@ | |
|
|
||
| import requests | ||
|
|
||
| from .auth import get_fireworks_account_id, get_fireworks_api_base, get_fireworks_api_key | ||
| from .common_utils import get_user_agent | ||
| from .auth import get_fireworks_account_id, get_fireworks_api_base, get_fireworks_api_key, get_platform_headers | ||
|
|
||
|
|
||
| def _map_api_host_to_app_host(api_base: str) -> str: | ||
|
|
@@ -142,11 +141,17 @@ def create_dataset_from_jsonl( | |
| display_name: Optional[str], | ||
| jsonl_path: str, | ||
| ) -> Tuple[str, Dict[str, Any]]: | ||
| headers = { | ||
| "Authorization": f"Bearer {api_key}", | ||
| "Content-Type": "application/json", | ||
| "User-Agent": get_user_agent(), | ||
| } | ||
| import os | ||
|
|
||
| # DEBUG: Check environment variable | ||
| extra_headers_env = os.environ.get("FIREWORKS_EXTRA_HEADERS", "<NOT SET>") | ||
| print(f"[DEBUG] FIREWORKS_EXTRA_HEADERS env: {extra_headers_env}") | ||
|
|
||
| headers = get_platform_headers(api_key=api_key, content_type="application/json") | ||
|
|
||
| # DEBUG: Print headers (mask auth token) | ||
| debug_headers = {k: (v[:20] + "..." if k == "Authorization" else v) for k, v in headers.items()} | ||
| print(f"[DEBUG] Headers being sent: {debug_headers}") | ||
|
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. Bug: Debug print statements accidentally committed to production codeDebug print statements were left in the 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. Bug: Debug print statements accidentally committed to production codeDebug print statements were left in the |
||
| # Count examples quickly | ||
| example_count = 0 | ||
| with open(jsonl_path, "r", encoding="utf-8") as f: | ||
|
|
@@ -171,10 +176,8 @@ def create_dataset_from_jsonl( | |
| upload_url = f"{api_base.rstrip('/')}/v1/accounts/{account_id}/datasets/{dataset_id}:upload" | ||
| with open(jsonl_path, "rb") as f: | ||
| files = {"file": f} | ||
| up_headers = { | ||
| "Authorization": f"Bearer {api_key}", | ||
| "User-Agent": get_user_agent(), | ||
| } | ||
| # For file uploads, omit Content-Type (let requests set multipart boundary) | ||
| up_headers = get_platform_headers(api_key=api_key, content_type=None) | ||
| up_resp = requests.post(upload_url, files=files, headers=up_headers, timeout=600) | ||
| if up_resp.status_code not in (200, 201): | ||
| raise RuntimeError(f"Dataset upload failed: {up_resp.status_code} {up_resp.text}") | ||
|
|
@@ -196,12 +199,8 @@ def create_reinforcement_fine_tuning_job( | |
| # Remove from body and append as query param | ||
| body.pop("jobId", None) | ||
| url = f"{url}?{urlencode({'reinforcementFineTuningJobId': job_id})}" | ||
| headers = { | ||
| "Authorization": f"Bearer {api_key}", | ||
| "Content-Type": "application/json", | ||
| "Accept": "application/json", | ||
| "User-Agent": get_user_agent(), | ||
| } | ||
| headers = get_platform_headers(api_key=api_key, content_type="application/json") | ||
| headers["Accept"] = "application/json" | ||
| resp = requests.post(url, json=body, headers=headers, timeout=60) | ||
| if resp.status_code not in (200, 201): | ||
| raise RuntimeError(f"RFT job creation failed: {resp.status_code} {resp.text}") | ||
|
|
@@ -217,22 +216,22 @@ def build_default_dataset_id(evaluator_id: str) -> str: | |
| def build_default_output_model(evaluator_id: str) -> str: | ||
| base = evaluator_id.lower().replace("_", "-") | ||
| uuid_suffix = str(uuid.uuid4())[:4] | ||
|
|
||
| # suffix is "-rft-{4chars}" -> 9 chars | ||
| suffix_len = 9 | ||
| max_len = 63 | ||
|
|
||
| # Check if we need to truncate | ||
| if len(base) + suffix_len > max_len: | ||
| # Calculate hash of the full base to preserve uniqueness | ||
| hash_digest = hashlib.sha256(base.encode("utf-8")).hexdigest()[:6] | ||
| # New structure: {truncated_base}-{hash}-{uuid_suffix} | ||
| # Space needed for "-{hash}" is 1 + 6 = 7 | ||
| hash_part_len = 7 | ||
|
|
||
| allowed_base_len = max_len - suffix_len - hash_part_len | ||
| truncated_base = base[:allowed_base_len].strip("-") | ||
|
|
||
| return f"{truncated_base}-{hash_digest}-rft-{uuid_suffix}" | ||
|
|
||
| return f"{base}-rft-{uuid_suffix}" | ||
|
|
||
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.
create_dataset_from_jsonlnow unconditionally prints the value ofFIREWORKS_EXTRA_HEADERS(and the constructed headers below) to stdout. If callers set that env var with API tokens or other sensitive headers, every dataset creation leaks those secrets into logs/terminals because there is no debug guard or masking.Useful? React with 👍 / 👎.