Update app.py
Browse files
app.py
CHANGED
@@ -7,16 +7,40 @@ from tools.final_answer import FinalAnswerTool
|
|
7 |
|
8 |
from Gradio_UI import GradioUI
|
9 |
|
10 |
-
# Below is an example of a tool that
|
11 |
@tool
|
12 |
-
def
|
13 |
-
|
14 |
-
|
15 |
Args:
|
16 |
-
|
17 |
-
|
|
|
|
|
|
|
18 |
"""
|
19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
20 |
|
21 |
@tool
|
22 |
def get_current_time_in_timezone(timezone: str) -> str:
|
|
|
7 |
|
8 |
from Gradio_UI import GradioUI
|
9 |
|
10 |
+
# Below is an example of a tool that analyze code. !
|
11 |
@tool
|
12 |
+
def analyze_code(code: str, language: str) -> str:
|
13 |
+
"""Analyzes the given code for errors or mistakes and provides feedback.
|
14 |
+
|
15 |
Args:
|
16 |
+
code: The source code to analyze.
|
17 |
+
language: The programming language of the code (e.g., Java, C++, Python).
|
18 |
+
|
19 |
+
Returns:
|
20 |
+
A string containing detected issues or confirming that no issues were found.
|
21 |
"""
|
22 |
+
if language.lower() not in ["java", "c++", "python"]:
|
23 |
+
return "Currently, only Java, C++, and Python are supported."
|
24 |
+
|
25 |
+
try:
|
26 |
+
if language.lower() == "python":
|
27 |
+
import ast
|
28 |
+
try:
|
29 |
+
ast.parse(code)
|
30 |
+
return "No syntax errors detected in the Python code."
|
31 |
+
except SyntaxError as e:
|
32 |
+
return f"Python Syntax Error: {e}"
|
33 |
+
|
34 |
+
elif language.lower() == "java":
|
35 |
+
return "Java code analysis requires an external compiler or linter. Consider using a Java compiler like javac for syntax checking."
|
36 |
+
|
37 |
+
elif language.lower() == "c++":
|
38 |
+
return "C++ code analysis requires an external compiler like g++ or a static analysis tool such as Clang-Tidy."
|
39 |
+
|
40 |
+
except Exception as e:
|
41 |
+
return f"Error during code analysis: {e}"
|
42 |
+
|
43 |
+
return "Code analysis completed."
|
44 |
|
45 |
@tool
|
46 |
def get_current_time_in_timezone(timezone: str) -> str:
|