From 1b4d245d6b6ab4b51f1334a44f6ad6e28d758e79 Mon Sep 17 00:00:00 2001 From: Soham Date: Fri, 24 Oct 2025 20:49:23 +0530 Subject: [PATCH] Removed Duplicate and Wrapper functions --- routers/chat.py | 46 -------------------------------------- routers/game_detection.py | 12 +++++----- services/chatbot.py | 4 ++-- services/vector_service.py | 18 --------------- 4 files changed, 8 insertions(+), 72 deletions(-) diff --git a/routers/chat.py b/routers/chat.py index 401b8c1..346522e 100644 --- a/routers/chat.py +++ b/routers/chat.py @@ -207,52 +207,6 @@ async def clear_chat_history(game: str): raise HTTPException(status_code=500, detail=str(e)) -@router.get("/history/{game}/stats") -async def get_chat_stats(game: str): - """ - Get statistics about chat history for a game - - Example: GET /chat/history/minecraft/stats - """ - try: - stats = chat_history_manager.get_stats(game) - return { - "game": game, - "stats": stats - } - except Exception as e: - raise HTTPException(status_code=500, detail=str(e)) - - -@router.get("/history/games") -async def list_games_with_history(): - """ - List all games that have chat history - - Example: GET /chat/history/games - """ - try: - collections = chat_history_manager.client.list_collections() - - games_with_history = [] - for collection in collections: - if collection.name.endswith("_chat_history"): - game_name = collection.name.replace("_chat_history", "").replace("_", " ").title() - stats = chat_history_manager.get_stats(game_name) - games_with_history.append({ - "game": game_name, - "collection_name": collection.name, - "total_messages": stats.get("total_messages", 0) - }) - - return { - "games": games_with_history, - "total_games": len(games_with_history) - } - except Exception as e: - raise HTTPException(status_code=500, detail=str(e)) - - @router.post("/settings/history") async def update_history_settings(max_history: int): """ diff --git a/routers/game_detection.py b/routers/game_detection.py index 27e2836..3426960 100644 --- a/routers/game_detection.py +++ b/routers/game_detection.py @@ -1,6 +1,6 @@ from services.game_detection import detect_current_game, get_available_games as get_detection_games from services.knowledge_manager import get_available_games as get_csv_games, validate_csv_structure -from services.vector_service import add_game_knowledge, search_knowledge, get_game_stats, list_available_games +from services.vector_service import vector_service from schemas.game_detection import GameDetectionRequest from schemas.knowledge_search import KnowledgeSearchRequest from fastapi import APIRouter,HTTPException @@ -26,7 +26,7 @@ def list_games(): try: detection_games = get_detection_games() csv_games = get_csv_games() - vector_games = list_available_games() + vector_games = vector_service.list_available_games() return { "status": "ok", @@ -48,9 +48,9 @@ def process_game_knowledge(game_name: str): raise HTTPException(status_code=400, detail=f"Invalid CSV structure: {errors}") # Process and add to vector database - success = add_game_knowledge(game_name) + success = vector_service.add_game_knowledge(game_name) if success: - stats = get_game_stats(game_name) + stats = vector_service.get_game_stats(game_name) return { "status": "ok", "message": f"Successfully processed knowledge for {game_name}", @@ -67,7 +67,7 @@ def process_game_knowledge(game_name: str): def search_game_knowledge(game_name: str, request: KnowledgeSearchRequest): """Search knowledge base for a specific game.""" try: - results = search_knowledge( + results = vector_service.search_knowledge( game_name=game_name, query=request.query, content_types=request.content_types, @@ -88,7 +88,7 @@ def search_game_knowledge(game_name: str, request: KnowledgeSearchRequest): def get_game_knowledge_stats(game_name: str): """Get statistics for a game's knowledge base.""" try: - stats = get_game_stats(game_name) + stats = vector_service.get_game_stats(game_name) return { "status": "ok", "game_name": game_name, diff --git a/services/chatbot.py b/services/chatbot.py index 7562d05..0dc602d 100644 --- a/services/chatbot.py +++ b/services/chatbot.py @@ -4,7 +4,7 @@ from dotenv import load_dotenv from services.screenshot import get_recent_screenshots, get_screenshot_by_id, get_screenshot_stats from services.game_detection import detect_current_game -from services.vector_service import search_knowledge +from services import vector_service import base64 system_prompt_file = open("PROMPTS.txt","r") @@ -92,7 +92,7 @@ async def chat_with_gemini(message: str, image_data: str = None): # Search for relevant knowledge try: - knowledge_results = search_knowledge(detected_game, message) + knowledge_results = vector_service.search_knowledge(detected_game, message) if knowledge_results: knowledge_context = "\n\nRELEVANT KNOWLEDGE FROM GAME DATABASE:\n" diff --git a/services/vector_service.py b/services/vector_service.py index 72a860d..45e9179 100644 --- a/services/vector_service.py +++ b/services/vector_service.py @@ -293,21 +293,3 @@ def list_available_games(self) -> List[str]: # Global instance vector_service = VectorService() - -def add_game_knowledge(game_name: str) -> bool: - """Add all knowledge for a game to the vector database.""" - return vector_service.add_game_knowledge(game_name) - -def search_knowledge(game_name: str, query: str, content_types: List[str] = None, - limit: int = 5) -> List[Dict]: - """Search knowledge base for relevant information.""" - return vector_service.search_knowledge(game_name, query, content_types, limit) - -def get_game_stats(game_name: str) -> Dict[str, int]: - """Get statistics for a game's knowledge base.""" - return vector_service.get_game_stats(game_name) - -def list_available_games() -> List[str]: - """List all games with knowledge in the vector database.""" - return vector_service.list_available_games() -