Spaces:
Sleeping
Sleeping
Update src/query_engine.py
Browse files71 unmodified lines7273747576777889 unmodified lines16816917017117217371 unmodified linescfg,max_tokens=512,)return _parse_qcat_result(raw)except Exception:# LLM failure: fall back to raw queryreturn {89 unmodified linesreturn resultdef _parse_qcat_result(raw:str) -> Dict:parsed = None71 unmodified lines7273747576777889 unmodified lines16816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120271 unmodified linescfg,max_tokens=512,)return _parse_qinit_result(raw)except Exception:# LLM failure: fall back to raw queryreturn {89 unmodified linesreturn resultdef _parse_qinit_result(raw:str) -> Dict:parsed = None# Try direct parsetry:parsed = json.loads(raw)except (json.JSONDecodeError, TypeError):pass# Fallback: scan for the first valid JSON object using raw_decodeif parsed is None:decoder = json.JSONDecoder()for i, ch in enumerate(raw):if ch == '{':try:parsed, _ = decoder.raw_decode(raw, i)breakexcept json.JSONDecodeError:continue# Unparseable: fall back to raw queryif not isinstance(parsed, dict) or "country" not in parsed:return {"country": None,"value_chain": None,"investment": None,}return parseddef _parse_qcat_result(raw:str) -> Dict:parsed = None
src/query_engine.py+30-1