Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,4 +1,4 @@
|
|
1 |
-
from smolagents import CodeAgent,DuckDuckGoSearchTool, HfApiModel,load_tool,tool
|
2 |
import datetime
|
3 |
import requests
|
4 |
import pytz
|
@@ -9,29 +9,25 @@ 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
|
13 |
-
#Keep this format for the description / args / args description but feel free to modify the tool
|
14 |
-
"""A tool that does nothing yet
|
15 |
-
Args:
|
16 |
-
arg1: the first argument
|
17 |
-
arg2: the second argument
|
18 |
"""
|
19 |
-
|
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.
|
24 |
Args:
|
25 |
-
|
|
|
|
|
26 |
"""
|
27 |
try:
|
28 |
-
#
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
|
|
33 |
except Exception as e:
|
34 |
-
return f"
|
|
|
35 |
|
36 |
|
37 |
final_answer = FinalAnswerTool()
|
@@ -51,7 +47,7 @@ with open("prompts.yaml", 'r') as stream:
|
|
51 |
|
52 |
agent = CodeAgent(
|
53 |
model=model,
|
54 |
-
tools=[final_answer], ## add your tools here (don't remove final answer)
|
55 |
max_steps=6,
|
56 |
verbosity_level=1,
|
57 |
grammar=None,
|
|
|
1 |
+
from smolagents import CodeAgent,DuckDuckGoSearchTool, HfApiModel,load_tool,tool, LiteLLMModel
|
2 |
import datetime
|
3 |
import requests
|
4 |
import pytz
|
|
|
9 |
|
10 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
11 |
@tool
|
12 |
+
def search_articles(query: str) -> str:
|
|
|
|
|
|
|
|
|
|
|
13 |
"""
|
14 |
+
DuckDuckGo 검색을 사용하여 기사를 검색하고 결과를 반환합니다.
|
15 |
|
|
|
|
|
|
|
16 |
Args:
|
17 |
+
query: 검색어.
|
18 |
+
Returns:
|
19 |
+
검색 결과 문자열.
|
20 |
"""
|
21 |
try:
|
22 |
+
results = ddg(query, max_results=5) # max_results는 검색 결과의 수를 지정합니다.
|
23 |
+
if results:
|
24 |
+
formatted_results = "\n".join([f"Title: {r['title']}\nLink: {r['href']}\nSnippet: {r['body']}" for r in results])
|
25 |
+
return formatted_results
|
26 |
+
else:
|
27 |
+
return "검색 결과가 없습니다."
|
28 |
except Exception as e:
|
29 |
+
return f"오류 발생: {str(e)}"
|
30 |
+
|
31 |
|
32 |
|
33 |
final_answer = FinalAnswerTool()
|
|
|
47 |
|
48 |
agent = CodeAgent(
|
49 |
model=model,
|
50 |
+
tools=[search_articles,final_answer], ## add your tools here (don't remove final answer)
|
51 |
max_steps=6,
|
52 |
verbosity_level=1,
|
53 |
grammar=None,
|