Initial commit: Agentic OS troubleshooting platform
Self-hosted, Docker-based agentic troubleshooting platform: FastAPI backend + LangGraph agent, Next.js UI, tiered LLM routing (local Ollama -> Gemini -> DeepSeek -> OpenRouter), MCP server manager, encrypted device credentials, RBAC, audit log, project-memory + Obsidian integrations, and editable troubleshooting decision rules tuned for the GeneseasX vessel stack. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
24
backend/app/agent/json_utils.py
Normal file
24
backend/app/agent/json_utils.py
Normal file
@@ -0,0 +1,24 @@
|
||||
"""Shared helpers for extracting JSON objects from LLM responses."""
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
|
||||
|
||||
def parse_json(text: str) -> dict:
|
||||
"""Best-effort extraction of a single JSON object from LLM output.
|
||||
|
||||
Handles fenced ```json blocks and leading/trailing prose by slicing
|
||||
between the first '{' and last '}'. Returns {} when nothing parses.
|
||||
"""
|
||||
text = text.strip()
|
||||
if text.startswith("```"):
|
||||
text = text.split("```", 2)[1]
|
||||
if text.startswith("json"):
|
||||
text = text[4:]
|
||||
start, end = text.find("{"), text.rfind("}")
|
||||
if start != -1 and end != -1:
|
||||
try:
|
||||
return json.loads(text[start : end + 1])
|
||||
except json.JSONDecodeError:
|
||||
pass
|
||||
return {}
|
||||
Reference in New Issue
Block a user