From 82fc9ea5f9a6b88c37797b078ab96b3d8c3265e0 Mon Sep 17 00:00:00 2001
From: Josh Knapp <jknapp85@gmail.com>
Date: Tue, 4 Feb 2025 13:39:34 -0800
Subject: [PATCH] removing the tools calls

---
 open-webui-tool/bedrock-image-tool.py | 100 --------------------------
 open-webui-tool/readme.md             |   5 --
 scripts/discordbot.py                 |  27 +------
 3 files changed, 1 insertion(+), 131 deletions(-)
 delete mode 100644 open-webui-tool/bedrock-image-tool.py
 delete mode 100644 open-webui-tool/readme.md

diff --git a/open-webui-tool/bedrock-image-tool.py b/open-webui-tool/bedrock-image-tool.py
deleted file mode 100644
index e88a1d3..0000000
--- a/open-webui-tool/bedrock-image-tool.py
+++ /dev/null
@@ -1,100 +0,0 @@
-"""
-title: Bedrock Image Description
-author: Josh Knapp
-version: 0.1.0
-description="Provide Direct Bedrock call for image generation"
-"""
-
-import subprocess
-import json
-from pydantic import BaseModel, Field
-
-
-# Try to import boto3, install if not present
-try:
-    import boto3
-except ImportError:
-    print("boto3 package not found. Attempting to install...")
-    try:
-        subprocess.check_call([sys.executable, "-m", "pip", "install", "boto3"])
-        import boto3
-
-        print("boto3 package installed successfully")
-    except subprocess.CalledProcessError as e:
-        print(f"Failed to install boto3 package: {str(e)}")
-
-
-class Tools:
-    class Valves(BaseModel):
-        AWS_ACCESS_KEY: str = Field(
-            default="",
-            description="AWS Access Key",
-        )
-        AWS_SECRET_KEY: str = Field(
-            default="",
-            description="AWS Secret Key",
-        )
-        AWS_BEDROCK_MODEL: str = Field(
-            default="",
-            description="AWS Bedrock Model to use"
-        )
-
-    def __init__(self):
-        self.valves = self.Valves()
-        pass
-
-    def analyze_image(self, base64_image: str) -> str:
-        """
-        Analyze an image using AWS Bedrock's vision model
-        Args:
-            base64_image (str): Base64 encoded image string
-        Returns:
-            str: Description of the image
-        """
-        try:
-            # Initialize Bedrock runtime client
-            bedrock = boto3.client(
-                service_name="bedrock-runtime",
-                aws_access_key_id=self.valves.AWS_ACCESS_KEY,
-                aws_secret_access_key=self.valves.AWS_SECRET_KEY,
-                region_name="us-east-1"  # or your preferred region
-            )
-
-            # Prepare the request body
-            request_body = {
-                "anthropic_version": "bedrock-2023-05-31",
-                "max_tokens": 1000,
-                "messages": [
-                    {
-                        "role": "user",
-                        "content": [
-                            {
-                                "type": "image",
-                                "source": {
-                                    "type": "base64",
-                                    "media_type": "image/jpeg",
-                                    "data": base64_image
-                                }
-                            },
-                            {
-                                "type": "text",
-                                "text": "Please describe this image in detail."
-                            }
-                        ]
-                    }
-                ]
-            }
-
-            # Invoke the model
-            response = bedrock.invoke_model(
-                modelId=self.valves.AWS_BEDROCK_MODEL,
-                body=json.dumps(request_body)
-            )
-
-            # Parse and return the response
-            response_body = json.loads(response['body'].read())
-            return response_body['messages'][0]['content'][0]['text']
-
-        except Exception as e:
-            print(f"Error analyzing image: {str(e)}")
-            return f"Error analyzing image: {str(e)}"
diff --git a/open-webui-tool/readme.md b/open-webui-tool/readme.md
deleted file mode 100644
index 240d292..0000000
--- a/open-webui-tool/readme.md
+++ /dev/null
@@ -1,5 +0,0 @@
-For any model to use this tool, you must set the valve values, and add something to the model to let it know to use the tool.
-
-```
-You have access to a tool that allows you to get descriptions of images called  "Bedrock Image Description". Any image handling should be sent through this tool.
-```
\ No newline at end of file
diff --git a/scripts/discordbot.py b/scripts/discordbot.py
index 4c2fd06..32e7e8c 100644
--- a/scripts/discordbot.py
+++ b/scripts/discordbot.py
@@ -61,35 +61,10 @@ async def get_chat_history(channel, limit=100):
         messages.append(content)
     return "\n".join(reversed(messages))
 
-async def get_available_tools() -> List[Dict[str, Any]]:
-    """Fetch available tools from OpenWebUI API."""
-    try:
-        headers = {
-            "Content-Type": "application/json",
-            "Authorization": f"Bearer {OPENAI_API_KEY}"
-        }
-        
-        async with aiohttp.ClientSession() as session:
-            async with session.get(
-                f"{OPENWEBUI_API_BASE}/v1/tools/list",
-                headers=headers
-            ) as response:
-                if response.status == 200:
-                    tools = await response.json()
-                    return tools
-                else:
-                    print(f"Error fetching tools: {await response.text()}")
-                    return []
-    except Exception as e:
-        print(f"Error fetching tools: {str(e)}")
-        return []
 
 async def get_ai_response(context, user_message, image_urls=None):
-    # Fetch available tools
-    tools = await get_available_tools()
-    tools_json = json.dumps(tools, indent=2)
     
-    system_message = f"\"\"\"Previous conversation context:{context}\nAvailable Tools: {tools_json}\nReturn an empty string if no tools match the query." + """If a function tool matches, construct and return a JSON object in the format {"name": "functionName", "parameters": {"requiredFunctionParamKey": "requiredFunctionParamValue\"}} using the appropriate tool and its parameters. Only return the object and limit the response to the JSON object without additional text."""
+    system_message = f"\"\"\"Previous conversation context:{context}"""
 
     messages = [
         {"role": "system", "content": system_message},