Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -7,27 +7,67 @@ from tools.final_answer import FinalAnswerTool
|
|
| 7 |
|
| 8 |
from Gradio_UI import GradioUI
|
| 9 |
|
| 10 |
-
#
|
|
|
|
| 11 |
@tool
|
| 12 |
-
def
|
| 13 |
"""
|
| 14 |
-
|
| 15 |
-
|
| 16 |
Args:
|
| 17 |
-
|
| 18 |
Returns:
|
| 19 |
-
|
| 20 |
"""
|
| 21 |
try:
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
|
|
|
| 28 |
except Exception as e:
|
| 29 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
|
| 32 |
|
| 33 |
final_answer = FinalAnswerTool()
|
|
@@ -39,15 +79,15 @@ custom_role_conversions=None,
|
|
| 39 |
)
|
| 40 |
|
| 41 |
|
| 42 |
-
# Import tool from Hub
|
| 43 |
-
image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
|
| 44 |
|
| 45 |
with open("prompts.yaml", 'r') as stream:
|
| 46 |
prompt_templates = yaml.safe_load(stream)
|
| 47 |
|
| 48 |
agent = CodeAgent(
|
| 49 |
model=model,
|
| 50 |
-
tools=[
|
| 51 |
max_steps=6,
|
| 52 |
verbosity_level=1,
|
| 53 |
grammar=None,
|
|
|
|
| 7 |
|
| 8 |
from Gradio_UI import GradioUI
|
| 9 |
|
| 10 |
+
# 검색 tool
|
| 11 |
+
|
| 12 |
@tool
|
| 13 |
+
def search_news(topic: str) -> str:
|
| 14 |
"""
|
| 15 |
+
주어진 주제에 대한 최신 뉴스를 검색하는 도구입니다.
|
|
|
|
| 16 |
Args:
|
| 17 |
+
topic: 검색할 뉴스 주제
|
| 18 |
Returns:
|
| 19 |
+
검색된 뉴스 정보
|
| 20 |
"""
|
| 21 |
try:
|
| 22 |
+
search_agent = CodeAgent(
|
| 23 |
+
tools=[DuckDuckGoSearchTool()],
|
| 24 |
+
model=model,
|
| 25 |
+
additional_authorized_imports=["requests", "bs4"]
|
| 26 |
+
)
|
| 27 |
+
search_query = f"최신 뉴스 {topic}"
|
| 28 |
+
return search_agent.run(f"Search for: {search_query}")
|
| 29 |
except Exception as e:
|
| 30 |
+
traceback.print_exc()
|
| 31 |
+
return f"검색 중 오류 발생: {str(e)}"
|
| 32 |
+
|
| 33 |
+
# 기자 tool
|
| 34 |
+
@tool
|
| 35 |
+
def write_article(topic: str, search_results: str) -> str:
|
| 36 |
+
"""
|
| 37 |
+
검색 결과를 바탕으로 새로운 기사를 작성하는 도구입니다.
|
| 38 |
+
Args:
|
| 39 |
+
topic: 기사 주제
|
| 40 |
+
search_results: 검색된 뉴스 정보
|
| 41 |
+
Returns:
|
| 42 |
+
작성된 기사
|
| 43 |
+
"""
|
| 44 |
+
try:
|
| 45 |
+
system_prompt = """
|
| 46 |
+
당신은 전문 기자입니다. 주어진 주제에 대해 검색된 정보를 바탕으로 새로운 기사를 한국어로 작성해야 합니다.
|
| 47 |
+
다음 형식으로 기사를 작성해주세요:
|
| 48 |
+
|
| 49 |
+
1. 제목 (흥미롭고 눈에 띄는 제목)
|
| 50 |
+
2. 요약 (핵심 내용을 2-3문장으로 요약)
|
| 51 |
+
3. 본문 (상세한 내용을 단락으로 구분하여 작성)
|
| 52 |
+
4. 결론 (기사의 의의나 향후 전망)
|
| 53 |
+
|
| 54 |
+
기사는 객관적이고 사실에 기반하여 작성해야 하며, 검색된 정보를 재구성하여 새로운 시각으로 작성해주세요.
|
| 55 |
+
"""
|
| 56 |
+
|
| 57 |
+
prompt = f"""
|
| 58 |
+
다음 주제와 검색 결과를 바탕으로 새로운 기사를 한국어로 작성해주세요:
|
| 59 |
|
| 60 |
+
주제: {topic}
|
| 61 |
+
|
| 62 |
+
검색 결과:
|
| 63 |
+
{search_results}
|
| 64 |
+
|
| 65 |
+
위 정보를 바탕으로 새롭고 통찰력 있는 기사를 작성해주세요.
|
| 66 |
+
"""
|
| 67 |
+
return model.generate(system_prompt + prompt)
|
| 68 |
+
except Exception as e:
|
| 69 |
+
traceback.print_exc()
|
| 70 |
+
return f"기사 작성 중 오류 발생: {str(e)}"
|
| 71 |
|
| 72 |
|
| 73 |
final_answer = FinalAnswerTool()
|
|
|
|
| 79 |
)
|
| 80 |
|
| 81 |
|
| 82 |
+
# # Import tool from Hub
|
| 83 |
+
# image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
|
| 84 |
|
| 85 |
with open("prompts.yaml", 'r') as stream:
|
| 86 |
prompt_templates = yaml.safe_load(stream)
|
| 87 |
|
| 88 |
agent = CodeAgent(
|
| 89 |
model=model,
|
| 90 |
+
tools=[search_news, write_article, final_answer], ## add your tools here (don't remove final answer)
|
| 91 |
max_steps=6,
|
| 92 |
verbosity_level=1,
|
| 93 |
grammar=None,
|