rcbrowder commited on
Commit
524ff5f
·
verified ·
1 Parent(s): 9a8c112

Add random recipe

Browse files
Files changed (1) hide show
  1. app.py +31 -9
app.py CHANGED
@@ -7,16 +7,38 @@ 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_cutom_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:
@@ -51,7 +73,7 @@ with open("prompts.yaml", 'r') as stream:
51
 
52
  agent = CodeAgent(
53
  model=model,
54
- tools=[final_answer], ## add your tools here (don't remove final answer)
55
  max_steps=6,
56
  verbosity_level=1,
57
  grammar=None,
 
7
 
8
  from Gradio_UI import GradioUI
9
 
 
10
  @tool
11
+ def get_random_recipe()-> str: #it's import to specify the return type
12
+ """A tool to get a random recipe
13
+
 
 
 
14
  """
15
+
16
+ try:
17
+ url = "https://www.themealdb.com/api/json/v1/1/random.php"
18
+ response = requests.get(url)
19
+
20
+ # Check for successful response
21
+ response.raise_for_status() # Raise an exception for bad status codes (4xx or 5xx)
22
+
23
+ # Parse the JSON response
24
+ meal_data = response.json()
25
+
26
+ # Convert the dictionary to a JSON string with indentation for readability (optional)
27
+ json_string = json.dumps(meal_data, indent=4) # indent=4 for pretty printing
28
+
29
+
30
+ except requests.exceptions.RequestException as e:
31
+ print(f"Error during API request: {e}")
32
+ return None
33
+ except json.JSONDecodeError as e:
34
+ print(f"Error decoding JSON response: {e}")
35
+ return None
36
+ except Exception as e: # Catch any other potential errors
37
+ print(f"An unexpected error occurred: {e}")
38
+ return None
39
+
40
+
41
+ return json_string
42
 
43
  @tool
44
  def get_current_time_in_timezone(timezone: str) -> str:
 
73
 
74
  agent = CodeAgent(
75
  model=model,
76
+ tools=[final_answer, get_random_recipe], ## add your tools here (don't remove final answer)
77
  max_steps=6,
78
  verbosity_level=1,
79
  grammar=None,