Spaces:
Running
Running
Commit Β·
a3a158e
1
Parent(s): e5d4b0f
Separated out the tools info a separate directory
Browse files- {tools β default_tools}/agent_creater_tool.py +0 -0
- {tools β default_tools}/ask_agent_tool.py +0 -0
- {tools β default_tools}/fire_agent.py +0 -0
- {tools β default_tools}/get_agents_tool.py +0 -0
- {tools β default_tools}/google_search_tool.py +0 -0
- {tools β default_tools}/list_files.py +0 -0
- {tools β default_tools}/read_file.py +0 -0
- {tools β default_tools}/tool_creator.py +0 -0
- {tools β default_tools}/tool_deletor.py +7 -0
- src/tool_loader.py +14 -13
- tools/WordleTool.py +103 -0
{tools β default_tools}/agent_creater_tool.py
RENAMED
|
File without changes
|
{tools β default_tools}/ask_agent_tool.py
RENAMED
|
File without changes
|
{tools β default_tools}/fire_agent.py
RENAMED
|
File without changes
|
{tools β default_tools}/get_agents_tool.py
RENAMED
|
File without changes
|
{tools β default_tools}/google_search_tool.py
RENAMED
|
File without changes
|
{tools β default_tools}/list_files.py
RENAMED
|
File without changes
|
{tools β default_tools}/read_file.py
RENAMED
|
File without changes
|
{tools β default_tools}/tool_creator.py
RENAMED
|
File without changes
|
{tools β default_tools}/tool_deletor.py
RENAMED
|
@@ -29,6 +29,13 @@ class ToolDeletor():
|
|
| 29 |
print("Running Tool Deletor")
|
| 30 |
name = kwargs.get("name")
|
| 31 |
file_path = kwargs.get("file_path")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
os = importlib.import_module("os")
|
| 33 |
os.remove(file_path)
|
| 34 |
return {
|
|
|
|
| 29 |
print("Running Tool Deletor")
|
| 30 |
name = kwargs.get("name")
|
| 31 |
file_path = kwargs.get("file_path")
|
| 32 |
+
# make sure the file path is in tools/
|
| 33 |
+
if not file_path.startswith("tools/"):
|
| 34 |
+
return {
|
| 35 |
+
"status": "error",
|
| 36 |
+
"message": "File path must start with tools/",
|
| 37 |
+
"output": None
|
| 38 |
+
}
|
| 39 |
os = importlib.import_module("os")
|
| 40 |
os.remove(file_path)
|
| 41 |
return {
|
src/tool_loader.py
CHANGED
|
@@ -9,13 +9,13 @@ import sys
|
|
| 9 |
from src.budget_manager import BudgetManager
|
| 10 |
from src.utils.singleton import singleton
|
| 11 |
from src.utils.suppress_outputs import suppress_output
|
| 12 |
-
from
|
| 13 |
-
from
|
| 14 |
from src.utils.streamlit_interface import output_assistant_response
|
| 15 |
|
| 16 |
toolsImported = []
|
| 17 |
|
| 18 |
-
|
| 19 |
|
| 20 |
class Tool:
|
| 21 |
def __init__(self, toolClass):
|
|
@@ -64,16 +64,17 @@ class ToolLoader:
|
|
| 64 |
|
| 65 |
def load_tools(self):
|
| 66 |
newToolsImported = []
|
| 67 |
-
for
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
|
|
|
| 77 |
self.toolsImported = newToolsImported
|
| 78 |
|
| 79 |
def runTool(self, toolName, query):
|
|
|
|
| 9 |
from src.budget_manager import BudgetManager
|
| 10 |
from src.utils.singleton import singleton
|
| 11 |
from src.utils.suppress_outputs import suppress_output
|
| 12 |
+
from default_tools.get_agents_tool import GetAgents
|
| 13 |
+
from default_tools.tool_deletor import ToolDeletor
|
| 14 |
from src.utils.streamlit_interface import output_assistant_response
|
| 15 |
|
| 16 |
toolsImported = []
|
| 17 |
|
| 18 |
+
TOOLS_DIRECTORIES = [os.path.abspath("./default_tools"), os.path.abspath("./tools")]
|
| 19 |
|
| 20 |
class Tool:
|
| 21 |
def __init__(self, toolClass):
|
|
|
|
| 64 |
|
| 65 |
def load_tools(self):
|
| 66 |
newToolsImported = []
|
| 67 |
+
for directory in TOOLS_DIRECTORIES:
|
| 68 |
+
for filename in os.listdir(directory):
|
| 69 |
+
if filename.endswith(".py") and filename != "__init__.py":
|
| 70 |
+
module_name = filename[:-3]
|
| 71 |
+
spec = importlib.util.spec_from_file_location(module_name, f"{directory}/{filename}")
|
| 72 |
+
foo = importlib.util.module_from_spec(spec)
|
| 73 |
+
spec.loader.exec_module(foo)
|
| 74 |
+
class_name = foo.__all__[0]
|
| 75 |
+
toolClass = getattr(foo, class_name)
|
| 76 |
+
toolObj = Tool(toolClass)
|
| 77 |
+
newToolsImported.append(toolObj)
|
| 78 |
self.toolsImported = newToolsImported
|
| 79 |
|
| 80 |
def runTool(self, toolName, query):
|
tools/WordleTool.py
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
import re
|
| 3 |
+
import random
|
| 4 |
+
import json
|
| 5 |
+
import requests
|
| 6 |
+
|
| 7 |
+
__all__ = ['WordleTool']
|
| 8 |
+
|
| 9 |
+
class WordleTool():
|
| 10 |
+
dependencies = []
|
| 11 |
+
|
| 12 |
+
inputSchema = {
|
| 13 |
+
"name": "WordleTool",
|
| 14 |
+
"description": "A tool to play Wordle.",
|
| 15 |
+
"parameters": {
|
| 16 |
+
"type": "object",
|
| 17 |
+
"properties": {
|
| 18 |
+
"action": {
|
| 19 |
+
"type": "string",
|
| 20 |
+
"enum": ["new_game", "guess", "reset"],
|
| 21 |
+
"description": "The action to perform: new_game, guess, or reset."
|
| 22 |
+
},
|
| 23 |
+
"guess": {
|
| 24 |
+
"type": "string",
|
| 25 |
+
"description": "A 5-letter word guess. Required for 'guess' action."
|
| 26 |
+
}
|
| 27 |
+
},
|
| 28 |
+
"required": ["action"],
|
| 29 |
+
},
|
| 30 |
+
"invoke_cost": 0.2,
|
| 31 |
+
}
|
| 32 |
+
|
| 33 |
+
def __init__(self):
|
| 34 |
+
self.secret_word = None
|
| 35 |
+
self.word_list_url = "https://github.com/kiprobinson/wordle-solver/raw/main/app/resources/word-list.txt"
|
| 36 |
+
self.file_path = "secret_word.json" # Path for storing the secret word
|
| 37 |
+
|
| 38 |
+
def _load_word_list(self):
|
| 39 |
+
try:
|
| 40 |
+
response = requests.get(self.word_list_url)
|
| 41 |
+
response.raise_for_status() # Raise HTTPError for bad responses (4xx or 5xx)
|
| 42 |
+
word_list_str = response.text
|
| 43 |
+
word_list = word_list_str.strip().split("\n")
|
| 44 |
+
return word_list
|
| 45 |
+
except requests.exceptions.RequestException as e:
|
| 46 |
+
print(f"Error fetching word list: {e}")
|
| 47 |
+
return ['crane', 'house', 'table', 'chair', 'apple']
|
| 48 |
+
|
| 49 |
+
def _get_secret_word(self):
|
| 50 |
+
word_list = self._load_word_list()
|
| 51 |
+
return random.choice(word_list)
|
| 52 |
+
|
| 53 |
+
def _store_secret_word(self, word):
|
| 54 |
+
with open(self.file_path, "w") as f:
|
| 55 |
+
json.dump({"secret_word": word}, f)
|
| 56 |
+
return {"result": "Secret word stored successfully."}
|
| 57 |
+
|
| 58 |
+
def _retrieve_secret_word(self):
|
| 59 |
+
try:
|
| 60 |
+
with open(self.file_path, "r") as f:
|
| 61 |
+
data = json.load(f)
|
| 62 |
+
return {"result": data["secret_word"]}
|
| 63 |
+
except FileNotFoundError:
|
| 64 |
+
return {"result": None}
|
| 65 |
+
|
| 66 |
+
def run(self, **kwargs):
|
| 67 |
+
action = kwargs.get("action")
|
| 68 |
+
guess = kwargs.get("guess")
|
| 69 |
+
|
| 70 |
+
if action == "new_game":
|
| 71 |
+
self.secret_word = self._get_secret_word()
|
| 72 |
+
self._store_secret_word(self.secret_word)
|
| 73 |
+
return "New word generated. Please make your guess."
|
| 74 |
+
|
| 75 |
+
elif action == "reset":
|
| 76 |
+
self.secret_word = None
|
| 77 |
+
return "Game reset."
|
| 78 |
+
|
| 79 |
+
elif action == "guess":
|
| 80 |
+
# Retrieve secret word from file
|
| 81 |
+
secret_word_data = self._retrieve_secret_word()
|
| 82 |
+
if secret_word_data["result"] is None:
|
| 83 |
+
return "No secret word found. Please start a new game."
|
| 84 |
+
self.secret_word = secret_word_data["result"]
|
| 85 |
+
|
| 86 |
+
if not guess:
|
| 87 |
+
return "Please provide a guess."
|
| 88 |
+
|
| 89 |
+
guess = guess.lower()
|
| 90 |
+
if not re.match("^[a-z]{5}$", guess):
|
| 91 |
+
return "Invalid input. Please enter a 5-letter word."
|
| 92 |
+
|
| 93 |
+
result = ""
|
| 94 |
+
for i in range(5):
|
| 95 |
+
if guess[i] == self.secret_word[i]:
|
| 96 |
+
result += "G" # Green: Correct letter, correct position
|
| 97 |
+
elif guess[i] in self.secret_word:
|
| 98 |
+
result += "Y" # Yellow: Correct letter, wrong position
|
| 99 |
+
else:
|
| 100 |
+
result += "X" # Gray: Incorrect letter
|
| 101 |
+
return result
|
| 102 |
+
else:
|
| 103 |
+
return "Invalid action. Please choose 'new_game', 'guess', or 'reset'."
|