Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -101,19 +101,7 @@ def add_document_to_vector_store(content: str, source: str, metadata: dict = Non
|
|
101 |
except Exception as e:
|
102 |
logger.error(f"Error adding document from '{source}' to vector store: {e}")
|
103 |
|
104 |
-
|
105 |
-
def __call__(self, question: str) -> str:
|
106 |
-
logger.info(f"Received question: {question[:200]}...")
|
107 |
-
try:
|
108 |
-
global vectorstore
|
109 |
-
if embeddings:
|
110 |
-
# Re-initialize vectorstore without embedding_function
|
111 |
-
vectorstore = DocArrayInMemorySearch() # <--- FIXED THIS LINE as well
|
112 |
-
logger.info("DocArrayInMemorySearch re-initialized for new session.")
|
113 |
-
else:
|
114 |
-
logger.warning("Embeddings not initialized, cannot re-initialize DocArrayInMemorySearch.")
|
115 |
-
return "Error: Embedding model not loaded, cannot process request."
|
116 |
-
|
117 |
|
118 |
# --- Enhanced Tools ---
|
119 |
class WikiSearchTool(Tool):
|
@@ -414,7 +402,7 @@ class ChessAnalysisAPITool(Tool):
|
|
414 |
return f"An unexpected error occurred during chess analysis: {str(e)}"
|
415 |
|
416 |
# --- Agent Initialization ---
|
417 |
-
class BasicAgent:
|
418 |
def __init__(self):
|
419 |
self.model = HfApiModel(
|
420 |
temperature=0.0,
|
@@ -424,6 +412,7 @@ class BasicAgent:
|
|
424 |
|
425 |
self.tools = self._initialize_tools()
|
426 |
self.agent = self._create_agent()
|
|
|
427 |
|
428 |
def _initialize_tools(self) -> list:
|
429 |
"""Initialize all tools with enhanced capabilities"""
|
@@ -446,6 +435,7 @@ class BasicAgent:
|
|
446 |
base_tools.append(RetrievalTool())
|
447 |
else:
|
448 |
logger.warning("RetrievalTool not added because vector store or embeddings are not initialized.")
|
|
|
449 |
|
450 |
return base_tools
|
451 |
|
|
|
101 |
except Exception as e:
|
102 |
logger.error(f"Error adding document from '{source}' to vector store: {e}")
|
103 |
|
104 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
105 |
|
106 |
# --- Enhanced Tools ---
|
107 |
class WikiSearchTool(Tool):
|
|
|
402 |
return f"An unexpected error occurred during chess analysis: {str(e)}"
|
403 |
|
404 |
# --- Agent Initialization ---
|
405 |
+
class BasicAgent:
|
406 |
def __init__(self):
|
407 |
self.model = HfApiModel(
|
408 |
temperature=0.0,
|
|
|
412 |
|
413 |
self.tools = self._initialize_tools()
|
414 |
self.agent = self._create_agent()
|
415 |
+
|
416 |
|
417 |
def _initialize_tools(self) -> list:
|
418 |
"""Initialize all tools with enhanced capabilities"""
|
|
|
435 |
base_tools.append(RetrievalTool())
|
436 |
else:
|
437 |
logger.warning("RetrievalTool not added because vector store or embeddings are not initialized.")
|
438 |
+
|
439 |
|
440 |
return base_tools
|
441 |
|