From d918bf965d0b0bb09445b9d1726a431a8ad37193 Mon Sep 17 00:00:00 2001 From: Berack96 Date: Sun, 12 Oct 2025 16:45:10 +0200 Subject: [PATCH] Aggiornato config per app & api --- src/app/__main__.py | 7 +++---- src/app/agents/pipeline.py | 2 +- src/app/agents/team.py | 30 +++++++++++++----------------- src/app/api/wrapper_handler.py | 10 ++++++++++ 4 files changed, 27 insertions(+), 22 deletions(-) diff --git a/src/app/__main__.py b/src/app/__main__.py index a8e63ce..7454156 100644 --- a/src/app/__main__.py +++ b/src/app/__main__.py @@ -77,7 +77,6 @@ if __name__ == "__main__": save_btn.click(save_current_chat, inputs=None, outputs=None) load_btn.click(load_previous_chat, inputs=None, outputs=[chatbot, chatbot]) - server, port = ("0.0.0.0", 8000) # 0.0.0.0 per accesso esterno (Docker) - server_log = "localhost" if server == "0.0.0.0" else server - log_info(f"Starting UPO AppAI Chat on http://{server_log}:{port}") # noqa - demo.launch(server_name=server, server_port=port, quiet=True) + _app, local, shared = demo.launch(server_name="0.0.0.0", server_port=configs.port, quiet=True, prevent_thread_lock=True, share=configs.gradio_share) + log_info(f"Starting UPO AppAI Chat on {shared or local}") + demo.queue().block_thread() diff --git a/src/app/agents/pipeline.py b/src/app/agents/pipeline.py index fa260f1..40bdaf2 100644 --- a/src/app/agents/pipeline.py +++ b/src/app/agents/pipeline.py @@ -68,7 +68,7 @@ class Pipeline: team_model = self.configs.get_model_by_name(self.configs.agents.team_model) leader_model = self.configs.get_model_by_name(self.configs.agents.team_leader_model) - team = create_team_with(team_model, leader_model) + team = create_team_with(self.configs, team_model, leader_model) team_outputs = team.run(query) # type: ignore # Step 2: aggregazione output strutturati diff --git a/src/app/agents/team.py b/src/app/agents/team.py index 076bfb3..9de5b64 100644 --- a/src/app/agents/team.py +++ b/src/app/agents/team.py @@ -3,25 +3,21 @@ from app.api.markets import MarketAPIsTool from app.api.news import NewsAPIsTool from app.api.social import SocialAPIsTool from app.agents.prompts import * -from app.configs import AppModel +from app.configs import AppConfig, AppModel -def create_team_with(model: AppModel, coordinator: AppModel | None = None) -> Team: - market_agent = model.get_agent( - instructions=MARKET_INSTRUCTIONS, - name="MarketAgent", - tools=[MarketAPIsTool()] - ) - news_agent = model.get_agent( - instructions=NEWS_INSTRUCTIONS, - name="NewsAgent", - tools=[NewsAPIsTool()] - ) - social_agent = model.get_agent( - instructions=SOCIAL_INSTRUCTIONS, - name="SocialAgent", - tools=[SocialAPIsTool()] - ) +def create_team_with(configs: AppConfig, model: AppModel, coordinator: AppModel | None = None) -> Team: + + market_tool = MarketAPIsTool(currency=configs.api.currency) + market_tool.handler.set_retries(configs.api.retry_attempts, configs.api.retry_delay_seconds) + news_tool = NewsAPIsTool() + news_tool.handler.set_retries(configs.api.retry_attempts, configs.api.retry_delay_seconds) + social_tool = SocialAPIsTool() + social_tool.handler.set_retries(configs.api.retry_attempts, configs.api.retry_delay_seconds) + + market_agent = model.get_agent(instructions=MARKET_INSTRUCTIONS, name="MarketAgent", tools=[market_tool]) + news_agent = model.get_agent(instructions=NEWS_INSTRUCTIONS, name="NewsAgent", tools=[news_tool]) + social_agent = model.get_agent(instructions=SOCIAL_INSTRUCTIONS, name="SocialAgent", tools=[social_tool]) coordinator = coordinator or model return Team( diff --git a/src/app/api/wrapper_handler.py b/src/app/api/wrapper_handler.py index 504cf41..d28bd62 100644 --- a/src/app/api/wrapper_handler.py +++ b/src/app/api/wrapper_handler.py @@ -35,6 +35,16 @@ class WrapperHandler(Generic[WrapperType]): self.retry_delay = retry_delay self.index = 0 + def set_retries(self, try_per_wrapper: int, retry_delay: int) -> None: + """ + Sets the retry parameters for the handler. + Args: + try_per_wrapper (int): Number of retries per wrapper before switching to the next. + retry_delay (int): Delay in seconds between retries. + """ + self.retry_per_wrapper = try_per_wrapper + self.retry_delay = retry_delay + def try_call(self, func: Callable[[WrapperType], OutputType]) -> OutputType: """ Attempts to call the provided function on the current wrapper.