Refactor and update structure #20

Merged
Berack96 merged 22 commits from 16-refactoring-e-sanity-check into main 2025-10-08 16:21:10 +02:00
4 changed files with 22 additions and 19 deletions
Showing only changes of commit f8b41cd63a - Show all commits

View File

@@ -1,5 +1,5 @@
import gradio as gr
from agno.utils.log import log_info
from agno.utils.log import log_info #type: ignore
from dotenv import load_dotenv
from app.chat_manager import ChatManager
@@ -12,24 +12,24 @@ if __name__ == "__main__":
########################################
# Funzioni Gradio
########################################
def respond(message, history):
def respond(message: str, history: list[dict[str, str]]) -> tuple[list[dict[str, str]], list[dict[str, str]], str]:
response = chat.send_message(message)
history.append({"role": "user", "content": message})
history.append({"role": "assistant", "content": response})
return history, history, ""
def save_current_chat():
def save_current_chat() -> str:
chat.save_chat("chat.json")
return "💾 Chat salvata in chat.json"
def load_previous_chat():
def load_previous_chat() -> tuple[list[dict[str, str]], list[dict[str, str]]]:
chat.load_chat("chat.json")
history = []
history: list[dict[str, str]] = []
for m in chat.get_history():
history.append({"role": m["role"], "content": m["content"]})
return history, history
def reset_chat():
def reset_chat() -> tuple[list[dict[str, str]], list[dict[str, str]]]:
chat.reset_chat()
return [], []

View File

@@ -6,7 +6,7 @@ from agno.models.base import Model
from agno.models.google import Gemini
from agno.models.ollama import Ollama
from agno.tools import Toolkit
from agno.utils.log import log_warning
from agno.utils.log import log_warning #type: ignore
from pydantic import BaseModel
@@ -36,7 +36,7 @@ class AppModels(Enum):
log_warning(f"Ollama is not running or not reachable {result}")
return []
availables = []
availables: list[AppModels] = []
result = result.text
for model in [model for model in AppModels if model.name.startswith("OLLAMA")]:
if model.value in result:
@@ -106,5 +106,5 @@ class AppModels(Enum):
retries=2,
tools=tools,
delay_between_retries=5, # seconds
output_schema=output # se si usa uno schema di output, lo si passa qui
output_schema=output.__class__ if output else None # se si usa uno schema di output, lo si passa qui
)

View File

@@ -1,7 +1,6 @@
from agno.team import Team
from pydantic import BaseModel, Field
from app.agents import AppModels
from app.markets import MarketAPIsTool, ProductInfo
from app.markets import MarketAPIsTool
from app.news import NewsAPIsTool
from app.social import SocialAPIsTool

View File

@@ -2,6 +2,7 @@ from agno.run.agent import RunOutput
from app.agents import AppModels
from app.agents.team import create_team_with
from app.agents.predictor import PREDICTOR_INSTRUCTIONS, PredictorInput, PredictorOutput, PredictorStyle
from app.markets.base import ProductInfo
class Pipeline:
@@ -64,19 +65,20 @@ class Pipeline:
4. Restituisce la strategia finale
"""
# Step 1: raccolta output dai membri del Team
team_outputs = self.team.run(query)
team_outputs = self.team.run(query) # type: ignore
# Step 2: aggregazione output strutturati
all_products = []
sentiments = []
all_products: list[ProductInfo] = []
sentiments: list[str] = []
for agent_output in team_outputs.member_responses:
if isinstance(agent_output, RunOutput):
if "products" in agent_output.metadata:
if isinstance(agent_output, RunOutput) and agent_output.metadata is not None:
keys = agent_output.metadata.keys()
if "products" in keys:
all_products.extend(agent_output.metadata["products"])
if "sentiment_news" in agent_output.metadata:
if "sentiment_news" in keys:
sentiments.append(agent_output.metadata["sentiment_news"])
if "sentiment_social" in agent_output.metadata:
if "sentiment_social" in keys:
sentiments.append(agent_output.metadata["sentiment_social"])
aggregated_sentiment = "\n".join(sentiments)
@@ -88,7 +90,9 @@ class Pipeline:
sentiment=aggregated_sentiment
)
result = self.predictor.run(predictor_input)
result = self.predictor.run(predictor_input) # type: ignore
if not isinstance(result.content, PredictorOutput):
return "❌ Errore: il modello non ha restituito un output valido."
prediction: PredictorOutput = result.content
# Step 4: restituzione strategia finale