Spaces:
Runtime error
Runtime error
from smolagents import CodeAgent,DuckDuckGoSearchTool, HfApiModel,load_tool,tool, LiteLLMModel | |
import datetime | |
import requests | |
import pytz | |
import yaml | |
from tools.final_answer import FinalAnswerTool | |
from Gradio_UI import GradioUI | |
# Below is an example of a tool that does nothing. Amaze us with your creativity ! | |
def search_articles(query: str) -> str: | |
""" | |
DuckDuckGo 검색을 사용하여 기사를 검색하고 결과를 반환합니다. | |
Args: | |
query: 검색어. | |
Returns: | |
검색 결과 문자열. | |
""" | |
try: | |
results = ddg(query, max_results=5) # max_results는 검색 결과의 수를 지정합니다. | |
if results: | |
formatted_results = "\n".join([f"Title: {r['title']}\nLink: {r['href']}\nSnippet: {r['body']}" for r in results]) | |
return formatted_results | |
else: | |
return "검색 결과가 없습니다." | |
except Exception as e: | |
return f"오류 발생: {str(e)}" | |
final_answer = FinalAnswerTool() | |
model = HfApiModel( | |
max_tokens=2096, | |
temperature=0.5, | |
model_id='https://wxknx1kg971u7k1n.us-east-1.aws.endpoints.huggingface.cloud',# it is possible that this model may be overloaded | |
custom_role_conversions=None, | |
) | |
# Import tool from Hub | |
image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True) | |
with open("prompts.yaml", 'r') as stream: | |
prompt_templates = yaml.safe_load(stream) | |
agent = CodeAgent( | |
model=model, | |
tools=[search_articles,final_answer], ## add your tools here (don't remove final answer) | |
max_steps=6, | |
verbosity_level=1, | |
grammar=None, | |
planning_interval=None, | |
name=None, | |
description=None, | |
prompt_templates=prompt_templates | |
) | |
GradioUI(agent).launch() |