From 6030b2f387c46db1b9d6b4dce60dbc027ae6cde2 Mon Sep 17 00:00:00 2001 From: Md Abid Hussain Date: Thu, 30 Jan 2025 14:45:22 +0530 Subject: [PATCH] Update README and refactor backend and frontend code for improved clarity and functionality --- README.md | 2 +- docquery-backend/app/agents/utils/database.py | 4 ++-- docquery-backend/app/main.py | 14 +++++++++----- .../app/d/chat/owner/[owner]/repo/[repo]/page.tsx | 10 +++++++++- 4 files changed, 21 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index fc5dbeb..0799e29 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ DocQuery is a comprehensive project consisting of both frontend and backend comp 1. Clone the repository: ```sh - git clone + git clone https://github.com/md-abid-hussain/docquery.git cd docquery-frontend ``` diff --git a/docquery-backend/app/agents/utils/database.py b/docquery-backend/app/agents/utils/database.py index f2de74d..5491c02 100644 --- a/docquery-backend/app/agents/utils/database.py +++ b/docquery-backend/app/agents/utils/database.py @@ -4,7 +4,6 @@ from .models import get_embedding_model client = MongoClient(os.environ.get("MONGODB_ATLAS_CLUSTER_URI")) - DB_NAME = "docquery_db" COLLECTION_NAME = "vectorstore" ATLAS_VECTOR_SEARCH_INDEX = "rag_index" @@ -18,10 +17,11 @@ relevance_score_fn="cosine", ) + def get_vector_store(): return vector_store + def save_to_database(name: str): repository_collection = client["docquery"]["repositories"] repository_collection.insert_one({"name": name}) - diff --git a/docquery-backend/app/main.py b/docquery-backend/app/main.py index e2e45a0..a9fd022 100644 --- a/docquery-backend/app/main.py +++ b/docquery-backend/app/main.py @@ -11,17 +11,21 @@ sdk = CopilotKitSDK( agents=[ LangGraphAgent( - name="ingestion_agent", graph=ingestion_agent_graph, description="Ingestion Agent" + name="ingestion_agent", + graph=ingestion_agent_graph, + description="Ingestion Agent", ), LangGraphAgent( - name="qa_agent", graph=qa_agent_graph, description="QA Agent" - ) + name="qa_agent", + graph=qa_agent_graph, + description="QA Agent" + ), ] ) add_fastapi_endpoint(app, sdk, "/copilotkit") -@app.get("/") +@app.get("/test") def read_root(): - return {"Hello": "World"} + return "running" diff --git a/docquery-frontend/src/app/d/chat/owner/[owner]/repo/[repo]/page.tsx b/docquery-frontend/src/app/d/chat/owner/[owner]/repo/[repo]/page.tsx index f198b01..49ae5bf 100644 --- a/docquery-frontend/src/app/d/chat/owner/[owner]/repo/[repo]/page.tsx +++ b/docquery-frontend/src/app/d/chat/owner/[owner]/repo/[repo]/page.tsx @@ -2,14 +2,17 @@ import { useParams } from 'next/navigation'; import { useEffect } from 'react'; -import { useCoAgent, useCopilotReadable } from '@copilotkit/react-core'; +import { useCoAgent, useCopilotReadable, useCopilotMessagesContext, useCopilotContext } from '@copilotkit/react-core'; import { CopilotChat } from '@copilotkit/react-ui'; import { QAAgentState } from '@/lib/types'; import useRepoDetails from '@/hooks/useRepoDetails'; import CopilotTextMessage from '@/components/copilot/copilot-text-message'; const ChatRepoPage = () => { + const { owner, repo } = useParams(); + const { setMessages } = useCopilotMessagesContext(); + const { setAgentSession } = useCopilotContext() if (!owner || !repo) { return
Loading...
; @@ -30,6 +33,7 @@ const ChatRepoPage = () => { repository_name: `${owner}/${repo}`, messages: [] } + }); useEffect(() => { @@ -37,6 +41,10 @@ const ChatRepoPage = () => { question: "", repository_name: `${owner}/${repo}`, }) + return () => { + setMessages([]); + setAgentSession(null); + } }, []); return (