Spaces:
Sleeping
Sleeping
add habr news
Browse files
app.py
CHANGED
@@ -8,16 +8,6 @@ import os
|
|
8 |
|
9 |
from Gradio_UI import GradioUI
|
10 |
|
11 |
-
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
12 |
-
@tool
|
13 |
-
def my_custom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return type
|
14 |
-
#Keep this format for the description / args / args description but feel free to modify the tool
|
15 |
-
"""A tool that does nothing yet
|
16 |
-
Args:
|
17 |
-
arg1: the first argument
|
18 |
-
arg2: the second argument
|
19 |
-
"""
|
20 |
-
return "What magic will you build ?"
|
21 |
|
22 |
@tool
|
23 |
def get_current_time_in_timezone(timezone: str) -> str:
|
@@ -35,6 +25,28 @@ def get_current_time_in_timezone(timezone: str) -> str:
|
|
35 |
return f"Error fetching time for timezone '{timezone}': {str(e)}"
|
36 |
|
37 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
38 |
final_answer = FinalAnswerTool()
|
39 |
|
40 |
# If the agent does not answer, the model is overloaded, please use another model or the following Hugging Face Endpoint that also contains qwen2.5 coder:
|
@@ -57,7 +69,7 @@ with open("prompts.yaml", 'r') as stream:
|
|
57 |
|
58 |
agent = CodeAgent(
|
59 |
model=model,
|
60 |
-
tools=[get_current_time_in_timezone ,final_answer], ## add your tools here (don't remove final answer)
|
61 |
max_steps=6,
|
62 |
verbosity_level=1,
|
63 |
grammar=None,
|
|
|
8 |
|
9 |
from Gradio_UI import GradioUI
|
10 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
|
12 |
@tool
|
13 |
def get_current_time_in_timezone(timezone: str) -> str:
|
|
|
25 |
return f"Error fetching time for timezone '{timezone}': {str(e)}"
|
26 |
|
27 |
|
28 |
+
# Tool to search for news on Habr
|
29 |
+
@tool
|
30 |
+
def get_habr_news(query: str = "") -> str:
|
31 |
+
"""Searches for news on Habr based on the given query. If no query is provided, it returns the latest news.
|
32 |
+
Args:
|
33 |
+
query: A string representing the search query for news on Habr.
|
34 |
+
"""
|
35 |
+
try:
|
36 |
+
if not query:
|
37 |
+
url = "https://habr.com/ru/news/"
|
38 |
+
return f"Latest news on Habr: {url}"
|
39 |
+
|
40 |
+
url = f"https://habr.com/ru/search/?q={query}&target_type=posts"
|
41 |
+
response = requests.get(url, headers={"User-Agent": "Mozilla/5.0"})
|
42 |
+
if response.status_code == 200:
|
43 |
+
return f"Search results for news on Habr with query '{query}': {url}"
|
44 |
+
else:
|
45 |
+
return "Error retrieving data from Habr. Please try again later."
|
46 |
+
except Exception as e:
|
47 |
+
return f"Error performing request: {str(e)}"
|
48 |
+
|
49 |
+
|
50 |
final_answer = FinalAnswerTool()
|
51 |
|
52 |
# If the agent does not answer, the model is overloaded, please use another model or the following Hugging Face Endpoint that also contains qwen2.5 coder:
|
|
|
69 |
|
70 |
agent = CodeAgent(
|
71 |
model=model,
|
72 |
+
tools=[get_current_time_in_timezone, get_habr_news ,final_answer], ## add your tools here (don't remove final answer)
|
73 |
max_steps=6,
|
74 |
verbosity_level=1,
|
75 |
grammar=None,
|