Spaces:
Sleeping
Sleeping
File size: 2,227 Bytes
6bcf7d9 c02d868 6bcf7d9 b8ac549 6bcf7d9 b8ac549 6bcf7d9 b8ac549 6bcf7d9 b8ac549 6bcf7d9 b8ac549 6bcf7d9 b8ac549 6bcf7d9 b8ac549 6bcf7d9 b8ac549 6bcf7d9 b8ac549 6bcf7d9 b8ac549 |
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 64 |
import agent_tools
from smolagents import CodeAgent, AzureOpenAIServerModel
import my_tokens
# Instancia del modelo
model = AzureOpenAIServerModel(
model_id=my_tokens.AZURE_OPENAI_MODEL,
azure_endpoint=my_tokens.AZURE_OPENAI_ENDPOINT,
api_key=my_tokens.AZURE_OPENAI_API_KEY,
api_version=my_tokens.OPENAI_API_VERSION
)
class CustomAgent:
def __init__(self):
# Definir agentes de trabajo con sus herramientas
self.web_agent = CodeAgent(
model=model,
tools=[agent_tools.google_search, agent_tools.wiki_search, agent_tools.visit_page, agent_tools.final_answer],
max_steps=8,
name="web_agent",
description="Este agente maneja búsquedas web."
)
self.audio_agent = CodeAgent(
model=model,
tools=[agent_tools.speech_to_text_tool, agent_tools.final_answer],
max_steps=4,
name="audio_agent",
description="Este agente convierte audio a texto."
)
self.py_agent = CodeAgent(
model=model,
tools=[agent_tools.do_python, agent_tools.final_answer],
additional_authorized_imports=["json", "pandas", "numpy", "regex"],
max_steps=8,
name="python_code_agent",
description="Este agente ejecuta y valida código Python."
)
self.visual_agent = CodeAgent(
model=model,
tools=[agent_tools.visual_qa_tool, agent_tools.final_answer],
max_steps=4,
name="visual_qa_agent",
description="Este agente responde preguntas sobre imágenes."
)
self.manager_agent = CodeAgent(
model=model,
tools=[],
managed_agents=[self.web_agent, self.audio_agent, self.py_agent, self.visual_agent],
planning_interval=8,
verbosity_level=2,
max_steps=12,
)
def forward(self, question: str, attachment: str = None) -> str:
if attachment:
result = self.manager_agent.run(question, additional_args={"attachment": attachment})
else:
result = self.manager_agent.run(question)
return result
|