Multi-Tool Chatbot Assistant with Response Filtering

The main purpose of this code is to create a modular and manageable chatbot application that leverages multiple agentic tools. The application uses a Gradio interface to interact with users, allowing them to perform searches, retrieve Wikipedia information, execute SQL queries, get weather updates, and translate text. The chatbot integrates these tools via multiple agents to handle user queries effectively and refine responses based on additional instructions. 

Here’s a breakdown of everything I did

  • I divided the code into independent modules to improve organization and manageability.
  •  
  • First, I created a directory structure with separate folders for tools, language model components, and user interface components, along with a configuration file.
  •  
  • In the config.py file, I stored configuration details like the database URL and API keys to keep sensitive information centralized and easily adjustable.
  •  
  • In the tools folder, I implemented different tools for various functions:
  • DuckDuckGo Search Tool: This module allows performing searches using DuckDuckGo.
  • Wikipedia Tool: This module retrieves summaries from Wikipedia.
  • SQL Query Tool: This module executes SQL queries against a database.
  • Weather Tool: This module fetches weather information from the OpenWeatherMap API.
  • Translation Tool: This module translates text using Google Translator.
  •  
  • In the llm folder: Primary Agent: I set up the main language model agent using OpenAI’s Chat model, integrating the various tools created earlier. This agent determines which tool to use based on the user’s query and manages conversation memory.
  •  
  • Filter LLM: This module is responsible for refining responses from the primary agent based on additional filter instructions.
  •  
  • Chatbot UI: I developed the user interface using Gradio, which allows users to interact with the chatbot. It takes user queries and filter instructions, processes them through the primary agent, and displays the responses.
  •  
  • Finally, the main.py file serves as the entry point for launching the Gradio interface, which starts the application and allows users to interact with the chatbot.