Upload aiq_bridge.py with huggingface_hub
Browse files- aiq_bridge.py +63 -0
aiq_bridge.py
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
NVIDIA AI-Q Blueprint Embedded Bridge for Fiber-MoE Autonomous World Model
|
| 3 |
+
Integrates `/aiq-research` and `/aiq-deploy` directly into the agent substrate.
|
| 4 |
+
"""
|
| 5 |
+
|
| 6 |
+
import os
|
| 7 |
+
import sys
|
| 8 |
+
import subprocess
|
| 9 |
+
import json
|
| 10 |
+
from pathlib import Path
|
| 11 |
+
|
| 12 |
+
AIQ_SKILL_DIR = Path(r"C:\Users\gemin\.gemini\config\skills\aiq-research")
|
| 13 |
+
AIQ_SCRIPT = AIQ_SKILL_DIR / "scripts" / "aiq.py"
|
| 14 |
+
DEFAULT_AIQ_SERVER_URL = os.environ.get("AIQ_SERVER_URL", "http://localhost:8000")
|
| 15 |
+
|
| 16 |
+
class AIQBridge:
|
| 17 |
+
def __init__(self, server_url: str = DEFAULT_AIQ_SERVER_URL):
|
| 18 |
+
self.server_url = server_url
|
| 19 |
+
self.script_path = str(AIQ_SCRIPT)
|
| 20 |
+
|
| 21 |
+
def check_health(self) -> dict:
|
| 22 |
+
"""Ping AI-Q server /health endpoint."""
|
| 23 |
+
cmd = [sys.executable, self.script_path, "health"]
|
| 24 |
+
env = os.environ.copy()
|
| 25 |
+
env["AIQ_SERVER_URL"] = self.server_url
|
| 26 |
+
try:
|
| 27 |
+
res = subprocess.run(cmd, capture_output=True, text=True, env=env, timeout=10)
|
| 28 |
+
if res.returncode == 0:
|
| 29 |
+
try:
|
| 30 |
+
return {"status": "healthy", "details": json.loads(res.stdout.strip())}
|
| 31 |
+
except Exception:
|
| 32 |
+
return {"status": "healthy", "raw": res.stdout.strip()}
|
| 33 |
+
return {"status": "unreachable", "error": res.stderr.strip() or res.stdout.strip()}
|
| 34 |
+
except Exception as e:
|
| 35 |
+
return {"status": "error", "error": str(e)}
|
| 36 |
+
|
| 37 |
+
def execute_chat(self, query: str) -> dict:
|
| 38 |
+
"""Route shallow query or dispatch async deep research job."""
|
| 39 |
+
cmd = [sys.executable, self.script_path, "chat", query]
|
| 40 |
+
env = os.environ.copy()
|
| 41 |
+
env["AIQ_SERVER_URL"] = self.server_url
|
| 42 |
+
res = subprocess.run(cmd, capture_output=True, text=True, env=env)
|
| 43 |
+
try:
|
| 44 |
+
return json.loads(res.stdout.strip())
|
| 45 |
+
except Exception:
|
| 46 |
+
return {"raw_output": res.stdout.strip(), "stderr": res.stderr.strip()}
|
| 47 |
+
|
| 48 |
+
def poll_research(self, job_id: str) -> dict:
|
| 49 |
+
"""Poll deep research job until completion."""
|
| 50 |
+
cmd = [sys.executable, self.script_path, "research_poll", job_id]
|
| 51 |
+
env = os.environ.copy()
|
| 52 |
+
env["AIQ_SERVER_URL"] = self.server_url
|
| 53 |
+
res = subprocess.run(cmd, capture_output=True, text=True, env=env)
|
| 54 |
+
try:
|
| 55 |
+
return json.loads(res.stdout.strip())
|
| 56 |
+
except Exception:
|
| 57 |
+
return {"raw_output": res.stdout.strip()}
|
| 58 |
+
|
| 59 |
+
if __name__ == "__main__":
|
| 60 |
+
bridge = AIQBridge()
|
| 61 |
+
print("Testing AIQBridge health check:")
|
| 62 |
+
health = bridge.check_health()
|
| 63 |
+
print(json.dumps(health, indent=2))
|