ekhatskevich commited on
Commit
91d04ce
·
1 Parent(s): 5c64b24

add location tool

Browse files
Files changed (4) hide show
  1. .gitattributes +1 -0
  2. app.py +18 -1
  3. prompts.yaml +10 -0
  4. requirements.txt +1 -0
.gitattributes CHANGED
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ *.mmdb filter=lfs diff=lfs merge=lfs -text
app.py CHANGED
@@ -1,4 +1,6 @@
1
  from smolagents import CodeAgent,DuckDuckGoSearchTool, HfApiModel,load_tool,tool
 
 
2
  import datetime
3
  import pytz
4
  import yaml
@@ -6,6 +8,21 @@ from tools.final_answer import FinalAnswerTool
6
 
7
  from Gradio_UI import GradioUI
8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9
 
10
  @tool
11
  def search(query: str)-> str:
@@ -57,7 +74,7 @@ with open("prompts.yaml", 'r') as stream:
57
 
58
  agent = CodeAgent(
59
  model=model,
60
- tools=[final_answer,search], ## add your tools here (don't remove final answer)
61
  max_steps=6,
62
  verbosity_level=1,
63
  grammar=None,
 
1
  from smolagents import CodeAgent,DuckDuckGoSearchTool, HfApiModel,load_tool,tool
2
+ import geoip2.database
3
+ import requests
4
  import datetime
5
  import pytz
6
  import yaml
 
8
 
9
  from Gradio_UI import GradioUI
10
 
11
+ @tool
12
+ def show_internet_location()-> str:
13
+ """A tool that shows user's current location based on IP address.
14
+ """
15
+ try:
16
+ response = requests.get("https://api64.ipify.org?format=json")
17
+ public_ip = response.json()["ip"]
18
+
19
+ reader = geoip2.database.Reader('geo_cities/GeoLite2-City.mmdb')
20
+ response = reader.city(public_ip)
21
+
22
+ internet_location = f"Based on your IP address {public_ip}, you are in {response.country.name}, {response.city.name}"
23
+ return internet_location
24
+ except Exception as e:
25
+ return f"Error fetching the response for query internet location: {str(e)}"
26
 
27
  @tool
28
  def search(query: str)-> str:
 
74
 
75
  agent = CodeAgent(
76
  model=model,
77
+ tools=[final_answer,search,show_internet_location], ## add your tools here (don't remove final answer)
78
  max_steps=6,
79
  verbosity_level=1,
80
  grammar=None,
prompts.yaml CHANGED
@@ -37,6 +37,16 @@
37
  result = 5 + 3 + 1294.678
38
  final_answer(result)
39
  ```<end_code>
 
 
 
 
 
 
 
 
 
 
40
 
41
  ---
42
  Task:
 
37
  result = 5 + 3 + 1294.678
38
  final_answer(result)
39
  ```<end_code>
40
+
41
+ ---
42
+ Task: "What is my current location?"
43
+
44
+ Thought: I will use python code to retrieve user's current location based on IP address and then return the final answer using the `final_answer` tool
45
+ Code:
46
+ ```py
47
+ result = show_internet_location()
48
+ final_answer(result)
49
+ ```<end_code>
50
 
51
  ---
52
  Task:
requirements.txt CHANGED
@@ -3,3 +3,4 @@ smolagents
3
  requests
4
  duckduckgo_search
5
  pandas
 
 
3
  requests
4
  duckduckgo_search
5
  pandas
6
+ geoip2