Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions controllers/repo_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
router = APIRouter()

@router.get("/repo/query", status_code=status.HTTP_200_OK)
async def query_repo(question: str, repo_path: str, history: list[Any]):
response, history = await query(question, repo_path, history)
return JSONResponse(content={"response": response, "history": history}, status_code=status.HTTP_200_OK)
async def query_repo(question: str, repo_path: str, session_id: str):
response = await query(question, repo_path, session_id)
return JSONResponse(content={"response": response}, status_code=status.HTTP_200_OK)

@router.post("/repo/optimize", status_code=status.HTTP_200_OK)
async def optimize_repo(repo_path: str, language: Optional[str] = None, ref: Optional[str] = None):
Expand Down
14 changes: 14 additions & 0 deletions db/session.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import redis
from typing import Any
import json, pickle

r = redis.Redis(host='localhost', port=6379, decode_responses=False)

def get_session(session_id: str):
if r.exists(session_id) == 0:
return []
else:
return pickle.loads(r.get(session_id))

def set_session(session_id: str, history: list[Any]):
r.set(session_id, pickle.dumps(history))
2 changes: 0 additions & 2 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@
from controllers.graph_controller import router as graph_router
from controllers.repo_controller import router as repo_router
from fastapi.middleware.cors import CORSMiddleware
import redis

r = redis.Redis(host='localhost', port=6379, decode_responses=True)
app = FastAPI()

@app.get("/")
Expand Down
10 changes: 7 additions & 3 deletions services/repo_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,25 @@
from rich.panel import Panel
from rich.markdown import Markdown
from typing import Any
from db.session import get_session, set_session

console = Console(width=None, force_terminal=True)

async def query(question: str, repo_path: str, history: list[Any]):
async def query(question: str, repo_path: str, session_id: str):
init_session_log(_setup_common_initialization(repo_path))
log_session_event(f"USER: {question}")
with MemgraphIngestor(
host=settings.MEMGRAPH_HOST,
port=settings.MEMGRAPH_PORT,
) as ingestor:
console.print("[bold green]Successfully connected to Memgraph.[/bold green]")
history = get_session(session_id)
rag_agent = _initialize_services_and_agent(repo_path, ingestor)
response = await rag_agent.run(question + get_session_context(), history)
question_with_context = question + get_session_context()
response = await rag_agent.run(question_with_context, message_history=history)
history.extend(response.new_messages())
return response.output, history
set_session(session_id, history)
return response.output


async def optimize(repo_path: str, language: str, ref: str):
Expand Down
Loading