melbamorph commited on
Commit
41e1c3e
·
verified ·
1 Parent(s): 1386bbc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -6
app.py CHANGED
@@ -9,14 +9,37 @@ 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:
@@ -55,7 +78,7 @@ with open("prompts.yaml", 'r') as 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,
 
9
 
10
  # Below is an example of a tool that does nothing. Amaze us with your creativity !
11
  @tool
12
+ def get_bookbrain()-> str:
13
  #Keep this format for the description / args / args description but feel free to modify the tool
14
+ """Fetches a list of books from the BookBrain API.
15
  Args:
16
+ None
 
17
  """
18
+ try:
19
+ url = "https://bookbrain.replit.app/api/books"
20
+ response = requests.get(url)
21
+
22
+ if response.status_code != 200:
23
+ return f"Error accessing BookBrain: {response.text}"
24
+
25
+ data = response.json()
26
+ if not isinstance(data, list):
27
+ return "Received an unexpected response format from BookBrain."
28
+
29
+ books_str_list = []
30
+ for book in data:
31
+ title = book.get('title', 'N/A')
32
+ author = book.get('author', 'N/A')
33
+ topics = ', '.join(book.get('topics', []))
34
+ summary = book.get('summary', 'No summary available')
35
+
36
+ books_str_list.append(
37
+ f"Title: {title}\nAuthor: {author}\nTopics: {topics}\nSummary: {summary}"
38
+ )
39
+
40
+ return "\n\n---\n\n".join(books_str_list) if books_str_list else "No books found."
41
+ except Exception as e:
42
+ return f"Failed to fetch books from BookBrain due to: {str(e)}"
43
 
44
  @tool
45
  def get_current_time_in_timezone(timezone: str) -> str:
 
78
 
79
  agent = CodeAgent(
80
  model=model,
81
+ tools=[final_answer, get_bookbrain],
82
  max_steps=6,
83
  verbosity_level=1,
84
  grammar=None,