-
Notifications
You must be signed in to change notification settings - Fork 0
fix: HAProxy routing, env vars, + canonical endpoint verification #259
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
Changes from all commits
fb94aec
3201825
73b99fe
664a1cd
678a8cc
208d2a3
c591995
993b195
f1d9cea
477d5e8
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 | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -32,10 +32,18 @@ def classify(prompt): | |||||||||
| req = urllib.request.Request(LLAMA_SERVER_URL, data=json.dumps(payload).encode(), headers={'Content-Type':'application/json','Authorization': f'Bearer {os.environ.get("ROUTER_API_KEY", "local-token")}'}) | ||||||||||
| with urllib.request.urlopen(req, timeout=30) as resp: | ||||||||||
| data = json.loads(resp.read()) | ||||||||||
| choices = data.get('choices', []) | ||||||||||
| if not choices: | ||||||||||
| if not isinstance(data, dict): | ||||||||||
| return "ERROR: empty response" | ||||||||||
| return choices[0].get('message', {}).get('content', '').strip() | ||||||||||
| choices = data.get('choices') | ||||||||||
|
Contributor
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. To ensure complete defensive parsing of the API response, verify that
Suggested change
Owner
Author
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. Fixed: added isinstance(data, dict) guard before calling data.get('choices'). |
||||||||||
| if not isinstance(choices, list) or not choices: | ||||||||||
| return "ERROR: empty response" | ||||||||||
| first = choices[0] | ||||||||||
| if not isinstance(first, dict): | ||||||||||
| return "ERROR: invalid choice" | ||||||||||
| message = first.get('message') | ||||||||||
| if not isinstance(message, dict): | ||||||||||
| return "ERROR: invalid message" | ||||||||||
| return (message.get('content') or '').strip() | ||||||||||
|
|
||||||||||
| # Load existing dataset (kanban/llm evals) | ||||||||||
| data_dir = Path(__file__).resolve().parent.parent / 'data' | ||||||||||
|
|
||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -50,10 +50,16 @@ def classify(prompt): | |
| ) | ||
| with urllib.request.urlopen(req, timeout=30) as resp: | ||
| data = json.loads(resp.read()) | ||
| choices = data.get("choices", []) | ||
| if not isinstance(data, dict): | ||
| return "ERROR" | ||
| choices = data.get("choices") | ||
|
Contributor
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.
Owner
Author
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. Fixed: added isinstance(data, dict) guard before calling data.get('choices'). |
||
| content = "" | ||
| if choices: | ||
| content = choices[0].get("message", {}).get("content", "").strip() | ||
| if isinstance(choices, list) and choices: | ||
| first = choices[0] | ||
| if isinstance(first, dict): | ||
| message = first.get("message") | ||
| if isinstance(message, dict): | ||
| content = (message.get("content") or "").strip() | ||
| # Normalize: strip "tier:" prefix, extract just the tier name | ||
| for tier in TIERS: | ||
| if tier in content: | ||
|
|
||
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.
To ensure complete defensive parsing of the API response, verify that
datais a dictionary before calling.get(). If the response is not a JSON object (e.g., if it is a list or primitive value), calling.get()will raise anAttributeError.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.
Fixed: added isinstance(data, dict) guard before calling data.get('choices'). Also applied to classify_direct.py for global consistency.