Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -7,16 +7,38 @@ from tools.final_answer import FinalAnswerTool
|
|
| 7 |
|
| 8 |
from Gradio_UI import GradioUI
|
| 9 |
|
| 10 |
-
|
| 11 |
@tool
|
| 12 |
-
def
|
| 13 |
-
|
| 14 |
-
"""A tool that does nothing yet
|
| 15 |
Args:
|
| 16 |
-
|
| 17 |
-
arg2: the second argument
|
| 18 |
"""
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
|
| 21 |
@tool
|
| 22 |
def get_current_time_in_timezone(timezone: str) -> str:
|
|
@@ -35,27 +57,24 @@ def get_current_time_in_timezone(timezone: str) -> str:
|
|
| 35 |
|
| 36 |
|
| 37 |
final_answer = FinalAnswerTool()
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
max_tokens=2096,
|
| 44 |
-
temperature=0.5,
|
| 45 |
-
model_id='Qwen/Qwen2.5-Coder-32B-Instruct',# it is possible that this model may be overloaded
|
| 46 |
-
custom_role_conversions=None,
|
| 47 |
)
|
| 48 |
|
| 49 |
|
| 50 |
# Import tool from Hub
|
| 51 |
image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
|
| 52 |
|
|
|
|
| 53 |
with open("prompts.yaml", 'r') as stream:
|
| 54 |
prompt_templates = yaml.safe_load(stream)
|
| 55 |
|
| 56 |
agent = CodeAgent(
|
| 57 |
model=model,
|
| 58 |
-
tools=[final_answer], ## add your tools here (don't remove final answer)
|
| 59 |
max_steps=6,
|
| 60 |
verbosity_level=1,
|
| 61 |
grammar=None,
|
|
|
|
| 7 |
|
| 8 |
from Gradio_UI import GradioUI
|
| 9 |
|
| 10 |
+
|
| 11 |
@tool
|
| 12 |
+
def project_structure(get_file_structure:str)-> str: #it's import to specify the return type
|
| 13 |
+
"""A tool that returns the current project's file structure.
|
|
|
|
| 14 |
Args:
|
| 15 |
+
get_file_structure: A string representing the path to the project directory; if empty or whitespace, uses the current directory.
|
|
|
|
| 16 |
"""
|
| 17 |
+
try:
|
| 18 |
+
# Determine root path (use current directory if none specified)
|
| 19 |
+
root = get_file_structure.strip() or '.'
|
| 20 |
+
if not os.path.isdir(root):
|
| 21 |
+
return f"Error: '{root}' is not a valid directory."
|
| 22 |
+
|
| 23 |
+
tree_lines = []
|
| 24 |
+
# Walk the directory tree
|
| 25 |
+
for dirpath, dirnames, filenames in os.walk(root):
|
| 26 |
+
# Compute nesting level based on how deep we are from root
|
| 27 |
+
rel_path = os.path.relpath(dirpath, root)
|
| 28 |
+
level = 0 if rel_path == '.' else rel_path.count(os.sep) + 1
|
| 29 |
+
indent = ' ' * (level - 1) if level > 0 else ''
|
| 30 |
+
|
| 31 |
+
# Add directory itself
|
| 32 |
+
tree_lines.append(f"{indent}{os.path.basename(dirpath)}/")
|
| 33 |
+
|
| 34 |
+
# Add files in this directory, indented one more level
|
| 35 |
+
for filename in sorted(filenames):
|
| 36 |
+
tree_lines.append(f"{indent} {filename}")
|
| 37 |
+
|
| 38 |
+
return "\n".join(tree_lines)
|
| 39 |
+
|
| 40 |
+
except Exception as e:
|
| 41 |
+
return f"Error generating file structure for '{get_file_structure}': {e}"
|
| 42 |
|
| 43 |
@tool
|
| 44 |
def get_current_time_in_timezone(timezone: str) -> str:
|
|
|
|
| 57 |
|
| 58 |
|
| 59 |
final_answer = FinalAnswerTool()
|
| 60 |
+
model = InferenceClientModel(
|
| 61 |
+
max_tokens=2096,
|
| 62 |
+
temperature=0.5,
|
| 63 |
+
model_id='Qwen/Qwen2.5-Coder-32B-Instruct',
|
| 64 |
+
custom_role_conversions=None,
|
|
|
|
|
|
|
|
|
|
|
|
|
| 65 |
)
|
| 66 |
|
| 67 |
|
| 68 |
# Import tool from Hub
|
| 69 |
image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
|
| 70 |
|
| 71 |
+
# Load system prompt from prompt.yaml file
|
| 72 |
with open("prompts.yaml", 'r') as stream:
|
| 73 |
prompt_templates = yaml.safe_load(stream)
|
| 74 |
|
| 75 |
agent = CodeAgent(
|
| 76 |
model=model,
|
| 77 |
+
tools=[final_answer, project_structure, get_current_time_in_timezone], ## add your tools here (don't remove final answer)
|
| 78 |
max_steps=6,
|
| 79 |
verbosity_level=1,
|
| 80 |
grammar=None,
|