From ad2eb48d2f8d0506b900c5def2535dc71d589206 Mon Sep 17 00:00:00 2001
From: Clayton Smith <clayton@claytonsmith.io>
Date: Wed, 7 Aug 2024 12:17:15 -0400
Subject: [PATCH] ready to deploy

---
 src/backend/config/tools.py                   | 206 +++++++++---------
 src/backend/tools/minimap.py                  |   7 +-
 .../src/components/Configuration/Tools.tsx    |  11 +-
 3 files changed, 115 insertions(+), 109 deletions(-)

diff --git a/src/backend/config/tools.py b/src/backend/config/tools.py
index 6c70408819..8131a12798 100644
--- a/src/backend/config/tools.py
+++ b/src/backend/config/tools.py
@@ -37,29 +37,29 @@ class ToolName(StrEnum):
 
 
 ALL_TOOLS = {
-    ToolName.Wiki_Retriever_LangChain: ManagedTool(
-        name=ToolName.Wiki_Retriever_LangChain,
-        implementation=LangChainWikiRetriever,
-        parameter_definitions={
-            "query": {
-                "description": "Query for retrieval.",
-                "type": "str",
-                "required": True,
-            }
-        },
-        kwargs={"chunk_size": 300, "chunk_overlap": 0},
-        is_visible=True,
-        is_available=LangChainWikiRetriever.is_available(),
-        error_message="LangChainWikiRetriever not available.",
-        category=Category.DataLoader,
-        description="Retrieves documents from Wikipedia using LangChain.",
-    ),
+    # ToolName.Wiki_Retriever_LangChain: ManagedTool(
+    #     name=ToolName.Wiki_Retriever_LangChain,
+    #     implementation=LangChainWikiRetriever,
+    #     parameter_definitions={
+    #         "query": {
+    #             "description": "Query for retrieval.",
+    #             "type": "str",
+    #             "required": True,
+    #         }
+    #     },
+    #     kwargs={"chunk_size": 300, "chunk_overlap": 0},
+    #     is_visible=True,
+    #     is_available=LangChainWikiRetriever.is_available(),
+    #     error_message="LangChainWikiRetriever not available.",
+    #     category=Category.DataLoader,
+    #     description="Retrieves documents from Wikipedia using LangChain.",
+    # ),
     ToolName.Minimap: ManagedTool(
         name=ToolName.Minimap,
         implementation=LangChainMinimapRetriever,
         parameter_definitions={
             "query": {
-                "description": "Query for searching the news. It can be a topic, a named entities, or a quoted keyword.",
+                "description": "Search API that takes a query or phrase.",
                 "type": "str",
                 "required": True,
             }
@@ -70,91 +70,91 @@ class ToolName(StrEnum):
         category=Category.DataLoader,
         description="Fetches the most relevant news and content from Minimap.ai.",
     ),
-    ToolName.Search_File: ManagedTool(
-        name=ToolName.Search_File,
-        implementation=SearchFileTool,
-        parameter_definitions={
-            "search_query": {
-                "description": "Textual search query to search over the file's content for",
-                "type": "str",
-                "required": True,
-            },
-            "filenames": {
-                "description": "A list of one or more uploaded filename strings to search over",
-                "type": "list",
-                "required": True,
-            },
-        },
-        is_visible=True,
-        is_available=SearchFileTool.is_available(),
-        error_message="SearchFileTool not available.",
-        category=Category.FileLoader,
-        description="Performs a search over a list of one or more of the attached files for a textual search query",
-    ),
-    ToolName.Read_File: ManagedTool(
-        name=ToolName.Read_File,
-        implementation=ReadFileTool,
-        parameter_definitions={
-            "filename": {
-                "description": "The name of the attached file to read.",
-                "type": "str",
-                "required": True,
-            }
-        },
-        is_visible=True,
-        is_available=ReadFileTool.is_available(),
-        error_message="ReadFileTool not available.",
-        category=Category.FileLoader,
-        description="Returns the textual contents of an uploaded file, broken up in text chunks.",
-    ),
-    ToolName.Python_Interpreter: ManagedTool(
-        name=ToolName.Python_Interpreter,
-        implementation=PythonInterpreter,
-        parameter_definitions={
-            "code": {
-                "description": "Python code to execute using an interpreter",
-                "type": "str",
-                "required": True,
-            }
-        },
-        is_visible=True,
-        is_available=PythonInterpreter.is_available(),
-        error_message="PythonInterpreterFunctionTool not available, please make sure to set the PYTHON_INTERPRETER_URL environment variable.",
-        category=Category.Function,
-        description="Runs python code in a sandbox.",
-    ),
-    ToolName.Calculator: ManagedTool(
-        name=ToolName.Calculator,
-        implementation=Calculator,
-        parameter_definitions={
-            "code": {
-                "description": "The expression for the calculator to evaluate, it should be a valid mathematical expression.",
-                "type": "str",
-                "required": True,
-            }
-        },
-        is_visible=True,
-        is_available=Calculator.is_available(),
-        error_message="Calculator tool not available.",
-        category=Category.Function,
-        description="This is a powerful multi-purpose calculator. It is capable of a wide array of math calculation and a range of other useful features. Features include a large library of customizable functions, unit calculations and conversion, currency conversion, symbolic calculations (including integrals and equations) and interval arithmetic.",
-    ),
-    ToolName.Tavily_Internet_Search: ManagedTool(
-        name=ToolName.Tavily_Internet_Search,
-        implementation=TavilyInternetSearch,
-        parameter_definitions={
-            "query": {
-                "description": "Query for retrieval.",
-                "type": "str",
-                "required": True,
-            }
-        },
-        is_visible=True,
-        is_available=TavilyInternetSearch.is_available(),
-        error_message="TavilyInternetSearch not available, please make sure to set the TAVILY_API_KEY environment variable.",
-        category=Category.DataLoader,
-        description="Returns a list of relevant document snippets for a textual query retrieved from the internet using Tavily.",
-    ),
+    # ToolName.Search_File: ManagedTool(
+    #     name=ToolName.Search_File,
+    #     implementation=SearchFileTool,
+    #     parameter_definitions={
+    #         "search_query": {
+    #             "description": "Textual search query to search over the file's content for",
+    #             "type": "str",
+    #             "required": True,
+    #         },
+    #         "filenames": {
+    #             "description": "A list of one or more uploaded filename strings to search over",
+    #             "type": "list",
+    #             "required": True,
+    #         },
+    #     },
+    #     is_visible=True,
+    #     is_available=SearchFileTool.is_available(),
+    #     error_message="SearchFileTool not available.",
+    #     category=Category.FileLoader,
+    #     description="Performs a search over a list of one or more of the attached files for a textual search query",
+    # ),
+    # ToolName.Read_File: ManagedTool(
+    #     name=ToolName.Read_File,
+    #     implementation=ReadFileTool,
+    #     parameter_definitions={
+    #         "filename": {
+    #             "description": "The name of the attached file to read.",
+    #             "type": "str",
+    #             "required": True,
+    #         }
+    #     },
+    #     is_visible=True,
+    #     is_available=ReadFileTool.is_available(),
+    #     error_message="ReadFileTool not available.",
+    #     category=Category.FileLoader,
+    #     description="Returns the textual contents of an uploaded file, broken up in text chunks.",
+    # ),
+    # ToolName.Python_Interpreter: ManagedTool(
+    #     name=ToolName.Python_Interpreter,
+    #     implementation=PythonInterpreter,
+    #     parameter_definitions={
+    #         "code": {
+    #             "description": "Python code to execute using an interpreter",
+    #             "type": "str",
+    #             "required": True,
+    #         }
+    #     },
+    #     is_visible=True,
+    #     is_available=PythonInterpreter.is_available(),
+    #     error_message="PythonInterpreterFunctionTool not available, please make sure to set the PYTHON_INTERPRETER_URL environment variable.",
+    #     category=Category.Function,
+    #     description="Runs python code in a sandbox.",
+    # ),
+    # ToolName.Calculator: ManagedTool(
+    #     name=ToolName.Calculator,
+    #     implementation=Calculator,
+    #     parameter_definitions={
+    #         "code": {
+    #             "description": "The expression for the calculator to evaluate, it should be a valid mathematical expression.",
+    #             "type": "str",
+    #             "required": True,
+    #         }
+    #     },
+    #     is_visible=True,
+    #     is_available=Calculator.is_available(),
+    #     error_message="Calculator tool not available.",
+    #     category=Category.Function,
+    #     description="This is a powerful multi-purpose calculator. It is capable of a wide array of math calculation and a range of other useful features. Features include a large library of customizable functions, unit calculations and conversion, currency conversion, symbolic calculations (including integrals and equations) and interval arithmetic.",
+    # ),
+    # ToolName.Tavily_Internet_Search: ManagedTool(
+    #     name=ToolName.Tavily_Internet_Search,
+    #     implementation=TavilyInternetSearch,
+    #     parameter_definitions={
+    #         "query": {
+    #             "description": "Query for retrieval.",
+    #             "type": "str",
+    #             "required": True,
+    #         }
+    #     },
+    #     is_visible=True,
+    #     is_available=TavilyInternetSearch.is_available(),
+    #     error_message="TavilyInternetSearch not available, please make sure to set the TAVILY_API_KEY environment variable.",
+    #     category=Category.DataLoader,
+    #     description="Returns a list of relevant document snippets for a textual query retrieved from the internet using Tavily.",
+    # ),
 }
 
 
diff --git a/src/backend/tools/minimap.py b/src/backend/tools/minimap.py
index c843f123c8..1e71e0c44e 100644
--- a/src/backend/tools/minimap.py
+++ b/src/backend/tools/minimap.py
@@ -64,7 +64,7 @@ class MinimapAPIWrapper(BaseModel):
     max_retry: int = 5
 
     # Default values for the parameters
-    top_k_results: int = 15
+    top_k_results: int = 100
     MAX_QUERY_LENGTH: int = 300
     doc_content_chars_max: int = 2000
 
@@ -97,11 +97,10 @@ def run(self, query: str) -> str:
             for result in results:
                 result['doc_id'] = result.pop('id')
 
-            print(results)
             return results
 
         except Exception as ex:
-            return f"PubMed exception: {ex}"
+            return f"Minimap exception: {ex}"
 
 
 class MinimapQueryRun(BaseTool):
@@ -122,7 +121,7 @@ def _run(
         query: str,
         run_manager: Optional[CallbackManagerForToolRun] = None,
     ) -> str:
-        """Use the PubMed tool."""
+        """Use the Minimap tool."""
         return self.api_wrapper.run(query)
 
 class LangChainMinimapRetriever(CohereBaseTool):
diff --git a/src/interfaces/coral_web/src/components/Configuration/Tools.tsx b/src/interfaces/coral_web/src/components/Configuration/Tools.tsx
index a58ab6b63a..4485cae25b 100644
--- a/src/interfaces/coral_web/src/components/Configuration/Tools.tsx
+++ b/src/interfaces/coral_web/src/components/Configuration/Tools.tsx
@@ -24,12 +24,12 @@ export const Tools: React.FC<{ className?: string }> = ({ className = '' }) => {
       <ToolSection />
 
       {/* File upload is not supported for conversarions without an id */}
-      {conversationId && files.length > 0 && (
+      {/* {conversationId && files.length > 0 && (
         <>
           <hr className="my-6 border-t border-marble-400" />
           <FilesSection />
         </>
-      )}
+      )} */}
     </article>
   );
 };
@@ -72,6 +72,13 @@ const ToolSection = () => {
     updateEnabledTools(updatedTools);
   };
 
+  // useEffect to enable all tools by default
+  React.useEffect(() => {
+    if (tools.length > 0 && enabledTools.length === 0) {
+      updateEnabledTools(tools);
+    }
+  }, []);
+
   return (
     <section className="relative flex flex-col gap-y-5 px-5">
       <ToolsInfoBox />