langroid 0.59.10__py3-none-any.whl → 0.59.11__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- langroid/parsing/parse_json.py +25 -14
- {langroid-0.59.10.dist-info → langroid-0.59.11.dist-info}/METADATA +1 -1
- {langroid-0.59.10.dist-info → langroid-0.59.11.dist-info}/RECORD +5 -5
- {langroid-0.59.10.dist-info → langroid-0.59.11.dist-info}/WHEEL +0 -0
- {langroid-0.59.10.dist-info → langroid-0.59.11.dist-info}/licenses/LICENSE +0 -0
langroid/parsing/parse_json.py
CHANGED
@@ -135,21 +135,32 @@ def top_level_json_field(s: str, f: str) -> Any:
|
|
135
135
|
Returns:
|
136
136
|
str: The value of the field f in the top-level JSON object, if any.
|
137
137
|
Otherwise, return an empty string.
|
138
|
-
"""
|
139
138
|
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
if isinstance(
|
152
|
-
|
139
|
+
Note:
|
140
|
+
This function is designed to never crash. If any exception occurs during
|
141
|
+
JSON parsing or field extraction, it gracefully returns an empty string.
|
142
|
+
"""
|
143
|
+
try:
|
144
|
+
jsons = extract_top_level_json(s)
|
145
|
+
if len(jsons) == 0:
|
146
|
+
return ""
|
147
|
+
for j in jsons:
|
148
|
+
try:
|
149
|
+
json_data = json.loads(j)
|
150
|
+
if isinstance(json_data, dict):
|
151
|
+
if f in json_data:
|
152
|
+
return json_data[f]
|
153
|
+
elif isinstance(json_data, list):
|
154
|
+
# Some responses wrap candidate JSON objects in a list; scan them.
|
155
|
+
for item in json_data:
|
156
|
+
if isinstance(item, dict) and f in item:
|
157
|
+
return item[f]
|
158
|
+
except (json.JSONDecodeError, TypeError, KeyError):
|
159
|
+
# If this specific JSON fails to parse, continue to next candidate
|
160
|
+
continue
|
161
|
+
except Exception:
|
162
|
+
# Catch any unexpected errors to ensure we never crash
|
163
|
+
pass
|
153
164
|
|
154
165
|
return ""
|
155
166
|
|
@@ -94,7 +94,7 @@ langroid/parsing/document_parser.py,sha256=cUcp4JKS_LpsjX7OqnGBhHorDHx7FG5pvKGjR
|
|
94
94
|
langroid/parsing/file_attachment.py,sha256=f-MBRCI58XsCqJDH2HwTWwTQxLbYsDrOLgjrM1kw3XE,7350
|
95
95
|
langroid/parsing/md_parser.py,sha256=8LX9RDRWV1dZSYa-uBD8-whC_L6UYco-AQUxIuviqEk,21656
|
96
96
|
langroid/parsing/para_sentence_split.py,sha256=AJBzZojP3zpB-_IMiiHismhqcvkrVBQ3ZINoQyx_bE4,2000
|
97
|
-
langroid/parsing/parse_json.py,sha256=
|
97
|
+
langroid/parsing/parse_json.py,sha256=NxECxPndhIpyVdSYFEe7QpoIQktMPrFjo1i5P139dNA,5608
|
98
98
|
langroid/parsing/parser.py,sha256=IcwmVLlAae5LiKZ9OFhrnVOoHxcnsV7feFSHQiFfoi4,16112
|
99
99
|
langroid/parsing/pdf_utils.py,sha256=QogxU_B1N3WSLyZ9PEcJDaJoZShKs7CPQRVyF1V2DiE,3143
|
100
100
|
langroid/parsing/repo_loader.py,sha256=oB0TNifWCaqvlj7C0U76C4NZT7b94BbGkVX_-mrcH_4,30220
|
@@ -139,7 +139,7 @@ langroid/vector_store/pineconedb.py,sha256=7V0Bkt4ZrOR3V90tdXvdFmyNGuww7SFdyPq7-
|
|
139
139
|
langroid/vector_store/postgres.py,sha256=TY_VshimwFZglYgKYm7Qn1F-dCSL8GsXRTgmh7VTe9c,16110
|
140
140
|
langroid/vector_store/qdrantdb.py,sha256=mqxMOrcLAQpl0opuL8vXhdIt6ppv2zYyAvddHZoEW0Y,19184
|
141
141
|
langroid/vector_store/weaviatedb.py,sha256=BS95bxVKNYfQc9VPb85a1HlcgnXfAkgMzjydnjCgRHc,11853
|
142
|
-
langroid-0.59.
|
143
|
-
langroid-0.59.
|
144
|
-
langroid-0.59.
|
145
|
-
langroid-0.59.
|
142
|
+
langroid-0.59.11.dist-info/METADATA,sha256=bAKWmjVR0qVyzuBz89HWXyID4WEZ-FQeS9I4tHg4lMM,66518
|
143
|
+
langroid-0.59.11.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
144
|
+
langroid-0.59.11.dist-info/licenses/LICENSE,sha256=EgVbvA6VSYgUlvC3RvPKehSg7MFaxWDsFuzLOsPPfJg,1065
|
145
|
+
langroid-0.59.11.dist-info/RECORD,,
|
File without changes
|
File without changes
|