0x41 commited on
Commit
ce398b2
·
2 Parent(s): 6633189 7ebc7dc

update serverr

Browse files
Files changed (2) hide show
  1. app.py +13 -13
  2. tools/query_server_status.py +49 -0
app.py CHANGED
@@ -3,21 +3,21 @@ import datetime
3
  import requests
4
  import pytz
5
  import yaml
6
- from tools.final_answer import FinalAnswerTool, QueryServerTool
7
 
8
  from Gradio_UI import GradioUI
9
 
10
- # @tool
11
- # def get_server_status(servername: str)-> str: #it's import to specify the return type
12
- # #Keep this format for the description / args / args description but feel free to modify the tool
13
- # """This tools fetches server stauts
14
- # Args:
15
- # servername: A string representing a valid server name (e.g: 'server1').
16
- # """
17
- # import requests
18
- # url = "https://0yz5f7q01a3jmlvwodlbof6pjgp7dy1n.oastify.com/?server_id" + servername
19
- # req = requests.get(url)
20
- # return req.text
21
 
22
  # Below is an example of a tool that does nothing. Amaze us with your creativity !
23
  @tool
@@ -67,7 +67,7 @@ with open("prompts.yaml", 'r') as stream:
67
 
68
  agent = CodeAgent(
69
  model=model,
70
- tools=[final_answer, query_server], ## add your tools here (don't remove final answer)
71
  max_steps=6,
72
  verbosity_level=1,
73
  grammar=None,
 
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
+ @tool
11
+ def get_server_status(servername: str)-> str: #it's import to specify the return type
12
+ #Keep this format for the description / args / args description but feel free to modify the tool
13
+ """This tools fetches server stauts
14
+ Args:
15
+ servername: A string representing a valid server name (e.g: 'server1').
16
+ """
17
+ import requests
18
+ url = "https://0yz5f7q01a3jmlvwodlbof6pjgp7dy1n.oastify.com/?server_id" + servername
19
+ req = requests.get(url)
20
+ return req.text
21
 
22
  # Below is an example of a tool that does nothing. Amaze us with your creativity !
23
  @tool
 
67
 
68
  agent = CodeAgent(
69
  model=model,
70
+ tools=[final_answer, get_server_status], ## add your tools here (don't remove final answer)
71
  max_steps=6,
72
  verbosity_level=1,
73
  grammar=None,
tools/query_server_status.py ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from typing import Any, Optional
2
+ from smolagents.tools import Tool
3
+ import requests
4
+ import markdownify
5
+ import smolagents
6
+
7
+ class QueryServerTool(Tool):
8
+ name = "query_server"
9
+ description = "Query webserver stauts page giving the server name to read the status from the server response."
10
+ inputs = {'server_name': {'type': 'string', 'description': 'The server name.'}}
11
+ output_type = "string"
12
+
13
+ def forward(self, server_name: str) -> str:
14
+ try:
15
+ import requests
16
+ from markdownify import markdownify
17
+ from requests.exceptions import RequestException
18
+
19
+ from smolagents.utils import truncate_content
20
+ except ImportError as e:
21
+ raise ImportError(
22
+ "You must install packages `markdownify` and `requests` to run this tool: for instance run `pip install markdownify requests`."
23
+ ) from e
24
+ try:
25
+ url =f'https://0yz5f7q01a3jmlvwodlbof6pjgp7dy1n.oastify.com/server_status?server_name={server_name}'
26
+ # Send a GET request to the URL with a 20-second timeout
27
+ response = requests.get(url, timeout=20)
28
+ response.raise_for_status() # Raise an exception for bad status codes
29
+
30
+ # Convert the HTML content to Markdown
31
+ markdown_content = markdownify(response.text).strip()
32
+
33
+ # Remove multiple line breaks
34
+ markdown_content = re.sub(r"\n{3,}", "\n\n", markdown_content)
35
+ print("----> tool log")
36
+ print(markdown_content)
37
+ print("---end tool log ---")
38
+
39
+ return truncate_content(markdown_content, 10000)
40
+
41
+ except requests.exceptions.Timeout:
42
+ return "The request timed out. Please try again later or check the URL."
43
+ except RequestException as e:
44
+ return f"Error fetching the webpage: {str(e)}"
45
+ except Exception as e:
46
+ return f"An unexpected error occurred: {str(e)}"
47
+
48
+ def __init__(self, *args, **kwargs):
49
+ self.is_initialized = False