reecursion commited on
Commit
038368c
·
verified ·
1 Parent(s): 352e2ba

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +39 -1
app.py CHANGED
@@ -3,8 +3,10 @@ import datetime
3
  import requests
4
  import pytz
5
  import yaml
 
6
  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 !
@@ -18,6 +20,42 @@ def my_custom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return
18
  """
19
  return "What magic will you build ?"
20
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
21
  @tool
22
  def get_current_time_in_timezone(timezone: str) -> str:
23
  """A tool that fetches the current local time in a specified timezone.
@@ -55,7 +93,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,
 
3
  import requests
4
  import pytz
5
  import yaml
6
+ import re
7
  from tools.final_answer import FinalAnswerTool
8
 
9
+
10
  from Gradio_UI import GradioUI
11
 
12
  # Below is an example of a tool that does nothing. Amaze us with your creativity !
 
20
  """
21
  return "What magic will you build ?"
22
 
23
+ @tool
24
+ def get_bibtex_citation(title: str) -> str:
25
+ """Retrieves the citation of a particular paper in the specified style
26
+ Args:
27
+ title: Title of the work to cite in the bibtex format"""
28
+ try:
29
+ search_url = f"https://api.crossref.org/works?query.title={title.replace(' ', '+')}&rows=1"
30
+ response = requests.get(search_url)
31
+ data = response.json()
32
+
33
+ if data['message']['total-results'] == 0:
34
+ return f"No results found for '{title}'"
35
+
36
+ paper = data['message']['items'][0]
37
+ doi = paper.get('DOI')
38
+
39
+ if not doi:
40
+ return f"No DOI found for paper: {paper.get('title', [''])[0]}"
41
+
42
+ bibtex_url = f"https://www.doi2bib.org/bib/{doi}"
43
+ bibtex_response = requests.get(bibtex_url)
44
+
45
+ if bibtex_response.status_code != 200:
46
+ return f"Error accessing doi2bib.org: Status code {bibtex_response.status_code}"
47
+
48
+ html = bibtex_response.text
49
+ bibtex_match = re.search(r'<pre class="bibtex-code text-left">.*?<code>(.*?)</code>', html, re.DOTALL)
50
+
51
+ if bibtex_match:
52
+ bibtex = bibtex_match.group(1)
53
+ return bibtex.strip()
54
+
55
+ except Exception as e:
56
+ return f"Error generating citation: {str(e)}"
57
+
58
+
59
  @tool
60
  def get_current_time_in_timezone(timezone: str) -> str:
61
  """A tool that fetches the current local time in a specified timezone.
 
93
 
94
  agent = CodeAgent(
95
  model=model,
96
+ tools=[final_answer, get_bibtex_citation], ## add your tools here (don't remove final answer)
97
  max_steps=6,
98
  verbosity_level=1,
99
  grammar=None,