Support OPENAI_BASE_URL routing and JSON parsing#453
Open
bpulluta wants to merge 1 commit into
Open
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #453 +/- ##
==========================================
+ Coverage 56.11% 56.63% +0.51%
==========================================
Files 63 66 +3
Lines 6080 6298 +218
Branches 591 620 +29
==========================================
+ Hits 3412 3567 +155
- Misses 2598 2656 +58
- Partials 70 75 +5
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adds OpenAI environment-based client configuration and makes LLM JSON response parsing more tolerant of prose-wrapped JSON, supporting routed OpenAI-compatible endpoints.
Changes:
- Maps
OPENAI_API_KEYandOPENAI_BASE_URLinto OpenAI client kwargs while preserving explicit kwargs precedence. - Adds fallback parsing for embedded JSON payloads after strict JSON decoding fails.
- Adds unit tests for OpenAI config env handling and prose-before-JSON parsing.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
compass/llm/config.py |
Adds OpenAI env var mapping for client initialization. |
compass/utilities/parsing.py |
Adds fallback recovery for embedded JSON objects or arrays. |
tests/python/unit/llm/test_config.py |
Adds tests for OpenAI and Azure client kwargs env handling. |
tests/python/unit/utilities/test_utilities_parsing.py |
Adds coverage for prose-prefixed JSON parsing. |
Comment on lines
+99
to
+107
| for start_char in ("{", "["): | ||
| start_ind = content.find(start_char) | ||
| while start_ind != -1: | ||
| try: | ||
| parsed_content, __ = decoder.raw_decode(content[start_ind:]) | ||
| except json.decoder.JSONDecodeError: | ||
| start_ind = content.find(start_char, start_ind + 1) | ||
| else: | ||
| return parsed_content |
Comment on lines
+77
to
+97
| def _parse_first_json_payload(content): | ||
| """[NOT PUBLIC API] Parse first valid JSON payload embedded in text | ||
|
|
||
| Parameters | ||
| ---------- | ||
| content : str | ||
| Text that may contain one or more JSON payloads mixed with | ||
| additional non-JSON prose. | ||
|
|
||
| Returns | ||
| ------- | ||
| object or None | ||
| Parsed JSON payload from the first decodable object/array in | ||
| the string. Returns ``None`` if no decodable payload exists. | ||
|
|
||
| Notes | ||
| ----- | ||
| This helper scans for ``"{"`` and ``"["`` markers and attempts | ||
| ``json.JSONDecoder().raw_decode`` from each candidate position | ||
| until successful. | ||
| """ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Validation