MKshin29 commited on
Commit
1934eeb
·
verified ·
1 Parent(s): 5bf5915

Update app.py

Browse files

add get_ip_details function as a tool
add get_ip_details into tools list

Files changed (1) hide show
  1. app.py +26 -2
app.py CHANGED
@@ -7,7 +7,7 @@ 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
@@ -18,6 +18,30 @@ 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 +79,7 @@ with open("prompts.yaml", 'r') as stream:
55
 
56
  agent = CodeAgent(
57
  model=model,
58
- tools=[final_answer, image_generation_tool], ## add your tools here (don't remove final answer)
59
  max_steps=6,
60
  verbosity_level=1,
61
  grammar=None,
 
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
 
18
  """
19
  return "What magic will you build ?"
20
 
21
+ @tool
22
+ def get_ip_details(ip_address:str) -> str:
23
+ """A tool that fetches information about provided ip address.
24
+ Args:
25
+ ip_adress: A string representing an ip address for study (e.g., '8.8.8.8')
26
+ """
27
+ # Формируем URL для запроса
28
+ url = f"https://ipinfo.io/{ip_address}/json"
29
+
30
+ try:
31
+ # Выполняем GET-запрос к API
32
+ response = requests.get(url)
33
+
34
+ # Проверяем, что запрос был успешным
35
+ if response.status_code == 200:
36
+ # Возвращаем JSON-ответ в виде строки
37
+ return response.text
38
+ else:
39
+ # В случае ошибки возвращаем сообщение с кодом ошибки
40
+ return f"Ошибка: Не удалось получить данные. Код ошибки: {response.status_code}"
41
+ except requests.exceptions.RequestException as e:
42
+ # Обрабатываем возможные исключения при запросе
43
+ return f"Ошибка при выполнении запроса: {e}"
44
+
45
  @tool
46
  def get_current_time_in_timezone(timezone: str) -> str:
47
  """A tool that fetches the current local time in a specified timezone.
 
79
 
80
  agent = CodeAgent(
81
  model=model,
82
+ tools=[final_answer, image_generation_tool, get_ip_details], ## add your tools here (don't remove final answer)
83
  max_steps=6,
84
  verbosity_level=1,
85
  grammar=None,