DhirajSuryawanshi commited on
Commit
bd75325
·
verified ·
1 Parent(s): ae7a494

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -7
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 does nothing. Amaze us with your creativity !
11
  @tool
12
- def my_custom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return type
13
- #Keep this format for the description / args / args description but feel free to modify the tool
14
- """A tool that does nothing yet
15
  Args:
16
- arg1: the first argument
17
- arg2: the second argument
 
 
 
18
  """
19
- return "What magic will you build ?"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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: