Skip to content

Commit

Permalink
Choose the relevant tools, such as a knowledge base, a search engine,…
Browse files Browse the repository at this point in the history
… or a database, based on the task requirements and the agent's mode.
  • Loading branch information
fx2y committed Oct 9, 2023
1 parent eeb836a commit 8ffbd97
Show file tree
Hide file tree
Showing 4 changed files with 115 additions and 6 deletions.
58 changes: 52 additions & 6 deletions agent_configurator.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
import pymongo

from chatbot import Chatbot
from database import Database
from knowledge_base import KnowledgeBase
from search_engine import SearchEngine
from voice_assistant import VoiceAssistant
from web_interface import WebInterface

Expand All @@ -11,16 +14,13 @@ class AgentConfigurator:
def __init__(self):
self.llm_models = {}
self.human_input_sources = {}
self.tools = {}
self.input_sources = ["text", "voice", "image"]
self.tools = ["NLTK", "spaCy", "gensim"]

# Configure agent's parameters based on mode
def configure_agent(self, agent_id, mode, source):
# Select the appropriate LLM model based on the task requirements and the agent's mode
llm_model = self._select_llm_model(mode, source)
input_source = self._select_input_source(mode)
tools = self._select_tools(mode)

if not llm_model:
print("Error: No compatible LLM model found.")
return False
Expand All @@ -31,15 +31,19 @@ def configure_agent(self, agent_id, mode, source):
print("Error: No compatible human input source found.")
return False

if not llm_model or not input_source or not tools:
print("Error: Invalid mode for agent.")
# Choose the relevant tools based on the task requirements and the agent's mode
tools = self._choose_tools(mode)
if not tools:
print("Error: No compatible tools found.")
return False

# Configure agent's parameters based on mode and user's specifications
if not self._configure_llm_model(agent_id, llm_model):
return False
if not self._configure_human_input_source(agent_id, human_input_source):
return False
if not self._configure_tools(agent_id, tools):
return False

return True

Expand All @@ -63,6 +67,18 @@ def _define_human_input_source(self, mode):
if mode in self.human_input_sources:
return self.human_input_sources[mode]

# Choose the relevant tools based on the task requirements and the agent's mode
def _choose_tools(self, mode):
# Check if tools have been loaded
if not self.tools:
self._load_tools(mode)

# Choose the relevant tools based on the task requirements and the agent's mode
if mode in self.tools:
return self.tools[mode]
else:
return None

def _select_input_source(self, mode):
if mode == "text":
return "text"
Expand Down Expand Up @@ -142,3 +158,33 @@ def _configure_human_input_source(self, agent_id, human_input_source):
# ...

return True

# Load tools from database or file system

# Load tools from database or file system
def _load_tools(self, mode):
# Load tools from database or file system
# ...

# Choose relevant tools based on mode and task requirements
if mode == "mode1":
self.tools["knowledge_base"] = KnowledgeBase()
elif mode == "mode2":
self.tools["search_engine"] = SearchEngine()
elif mode == "mode3":
self.tools["database"] = Database()

# Store tools in dictionary
self.tools = {
"mode1": self.tools["knowledge_base"],
"mode2": self.tools["search_engine"],
"mode3": self.tools["database"],
# ...
}

# Configure agent's tools based on user's specifications
def _configure_tools(self, agent_id, tools):
# Configure agent's tools based on user's specifications
# ...

return True
35 changes: 35 additions & 0 deletions database.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
class Database:
def __init__(self):
self.connection = None
self.host = None
self.port = None
self.username = None
self.password = None
self.database_name = None

def connect(self):
if self.connection is not None:
raise ValueError("Already connected")

# Connect to the database using the configured parameters
# ...

self.connection = ... # store the connection object

def disconnect(self):
if self.connection is None:
raise ValueError("Not connected")

# Disconnect from the database
# ...

self.connection = None

def execute_query(self, query):
if self.connection is None:
raise ValueError("Not connected")

# Execute the given query on the database and return the result
# ...

# return result
9 changes: 9 additions & 0 deletions knowledge_base.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class KnowledgeBase:
def __init__(self):
self.data = {}

def add_data(self, key, value):
self.data[key] = value

def get_data(self, key):
return self.data.get(key)
19 changes: 19 additions & 0 deletions search_engine.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
class SearchEngine:
def __init__(self):
self.name = "search_engine"
self.parameters = {
"model": "BERT",
"input_source": "text",
"output_format": "text",
# ...
}
self.tools = {
"search_engine": {
"name": "Elasticsearch",
"version": "7.14.0",
"host": "localhost",
"port": 9200,
# ...
},
# ...
}

0 comments on commit 8ffbd97

Please sign in to comment.