intital file restructure

This commit is contained in:
serversdwn
2025-11-25 20:50:05 -05:00
parent b5fe47074a
commit 5492d9c0c5
15 changed files with 1 additions and 105 deletions

View File

@@ -0,0 +1,33 @@
# ingest_handler.py
import os
import httpx
NEOMEM_URL = os.getenv("NEOMEM_API", "http://nvgram-api:7077")
async def handle_ingest(payload):
"""
Pass user+assistant turns to NeoMem.
Minimal version. Does not process or annotate.
"""
data = {
"messages": [],
"user_id": "brian" # default for now
}
if payload.user:
data["messages"].append({"role": "user", "content": payload.user})
if payload.assistant:
data["messages"].append({"role": "assistant", "content": payload.assistant})
try:
async with httpx.AsyncClient() as client:
r = await client.post(
f"{NEOMEM_URL}/memories",
json=data,
timeout=5
)
if r.status_code != 200:
print(f"[Ingest] NeoMem returned {r.status_code}: {r.text}")
except Exception as e:
print(f"[Ingest] Failed to send to NeoMem: {e}")

View File

@@ -0,0 +1,38 @@
# cortex/intake_client.py
import os, httpx, logging
from typing import Dict, Any, Optional
logger = logging.getLogger(__name__)
class IntakeClient:
"""Handles short-term / episodic summaries from Intake service."""
def __init__(self):
self.base_url = os.getenv("INTAKE_API", "http://intake:7080")
async def summarize_turn(self, session_id: str, user_msg: str, assistant_msg: Optional[str] = None) -> Dict[str, Any]:
payload = {
"session_id": session_id,
"turns": [{"role": "user", "content": user_msg}]
}
if assistant_msg:
payload["turns"].append({"role": "assistant", "content": assistant_msg})
async with httpx.AsyncClient(timeout=30) as client:
try:
r = await client.post(f"{self.base_url}/summarize", json=payload)
r.raise_for_status()
return r.json()
except Exception as e:
logger.warning(f"Intake summarize_turn failed: {e}")
return {}
async def get_context(self, session_id: str) -> str:
async with httpx.AsyncClient(timeout=15) as client:
try:
r = await client.get(f"{self.base_url}/context/{session_id}")
r.raise_for_status()
return r.text
except Exception as e:
logger.warning(f"Intake get_context failed: {e}")
return ""