Spaces:
Runtime error
Runtime error
File size: 1,760 Bytes
a6f9b2b c19d193 a6f9b2b 6aae614 8fe992b 9b5b26a a6f9b2b 9b5b26a a6f9b2b 9b5b26a a6f9b2b 9b5b26a a6f9b2b 9b5b26a a6f9b2b 8c01ffb a6f9b2b 8c01ffb ae7a494 a6f9b2b ae7a494 e121372 a6f9b2b 13d500a 8c01ffb 9b5b26a 8c01ffb a6f9b2b 861422e a6f9b2b 8c01ffb 8fe992b a6f9b2b 8c01ffb 861422e 8fe992b 9b5b26a 8c01ffb |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
from smolagents import CodeAgent, HfApiModel, load_tool
import yaml
from smolagents import tool
from duckduckgo_search import DDGS
from tools.final_answer import FinalAnswerTool
from Gradio_UI import GradioUI
@tool
def DuckDuckGoSearchTool(query: str) -> str:
"""
Инструмент для поиска информации в интернете с помощью DuckDuckGo.
Args:
query: Поисковый запрос.
"""
with DDGS() as ddgs:
results = [r for r in ddgs.text(query, max_results=5)] # Ограничиваем до 5 результатов
if not results:
return "По вашему запросу ничего не найдено."
formatted_results = "\n\n".join(
f"**Заголовок:** {r['title']}\n**Ссылка:** {r['href']}\n**Краткое содержание:** {r['body']}"
for r in results
)
return formatted_results
final_answer = FinalAnswerTool()
model = HfApiModel(
max_tokens=2096,
temperature=0.5,
model_id='Qwen/Qwen2.5-Coder-32B-Instruct', # Возможно, эта модель перегружена
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)
prompt_templates['system_prompt'] = system_prompt
agent = CodeAgent(
model=model,
tools=[DuckDuckGoSearchTool, final_answer, image_generation_tool],
max_steps=6,
verbosity_level=1,
grammar=None,
planning_interval=None,
name=None,
description=None,
prompt_templates=prompt_templates
)
GradioUI(agent).launch() |