Refactor and update structure #20
@@ -1,5 +1,5 @@
|
|||||||
import gradio as gr
|
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 dotenv import load_dotenv
|
||||||
from app.chat_manager import ChatManager
|
from app.chat_manager import ChatManager
|
||||||
|
|
||||||
@@ -12,24 +12,24 @@ if __name__ == "__main__":
|
|||||||
########################################
|
########################################
|
||||||
# Funzioni Gradio
|
# 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)
|
response = chat.send_message(message)
|
||||||
history.append({"role": "user", "content": message})
|
history.append({"role": "user", "content": message})
|
||||||
history.append({"role": "assistant", "content": response})
|
history.append({"role": "assistant", "content": response})
|
||||||
return history, history, ""
|
return history, history, ""
|
||||||
|
|
||||||
def save_current_chat():
|
def save_current_chat() -> str:
|
||||||
chat.save_chat("chat.json")
|
chat.save_chat("chat.json")
|
||||||
return "💾 Chat salvata in 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")
|
chat.load_chat("chat.json")
|
||||||
history = []
|
history: list[dict[str, str]] = []
|
||||||
for m in chat.get_history():
|
for m in chat.get_history():
|
||||||
history.append({"role": m["role"], "content": m["content"]})
|
history.append({"role": m["role"], "content": m["content"]})
|
||||||
return history, history
|
return history, history
|
||||||
|
|
||||||
def reset_chat():
|
def reset_chat() -> tuple[list[dict[str, str]], list[dict[str, str]]]:
|
||||||
chat.reset_chat()
|
chat.reset_chat()
|
||||||
return [], []
|
return [], []
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ from agno.models.base import Model
|
|||||||
from agno.models.google import Gemini
|
from agno.models.google import Gemini
|
||||||
from agno.models.ollama import Ollama
|
from agno.models.ollama import Ollama
|
||||||
from agno.tools import Toolkit
|
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
|
from pydantic import BaseModel
|
||||||
|
|
||||||
|
|
||||||
@@ -36,7 +36,7 @@ class AppModels(Enum):
|
|||||||
log_warning(f"Ollama is not running or not reachable {result}")
|
log_warning(f"Ollama is not running or not reachable {result}")
|
||||||
return []
|
return []
|
||||||
|
|
||||||
availables = []
|
availables: list[AppModels] = []
|
||||||
result = result.text
|
result = result.text
|
||||||
for model in [model for model in AppModels if model.name.startswith("OLLAMA")]:
|
for model in [model for model in AppModels if model.name.startswith("OLLAMA")]:
|
||||||
if model.value in result:
|
if model.value in result:
|
||||||
@@ -106,5 +106,5 @@ class AppModels(Enum):
|
|||||||
retries=2,
|
retries=2,
|
||||||
tools=tools,
|
tools=tools,
|
||||||
delay_between_retries=5, # seconds
|
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
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
from agno.team import Team
|
from agno.team import Team
|
||||||
from pydantic import BaseModel, Field
|
|
||||||
from app.agents import AppModels
|
from app.agents import AppModels
|
||||||
from app.markets import MarketAPIsTool, ProductInfo
|
from app.markets import MarketAPIsTool
|
||||||
from app.news import NewsAPIsTool
|
from app.news import NewsAPIsTool
|
||||||
from app.social import SocialAPIsTool
|
from app.social import SocialAPIsTool
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ from agno.run.agent import RunOutput
|
|||||||
from app.agents import AppModels
|
from app.agents import AppModels
|
||||||
from app.agents.team import create_team_with
|
from app.agents.team import create_team_with
|
||||||
from app.agents.predictor import PREDICTOR_INSTRUCTIONS, PredictorInput, PredictorOutput, PredictorStyle
|
from app.agents.predictor import PREDICTOR_INSTRUCTIONS, PredictorInput, PredictorOutput, PredictorStyle
|
||||||
|
from app.markets.base import ProductInfo
|
||||||
|
|
||||||
|
|
||||||
class Pipeline:
|
class Pipeline:
|
||||||
@@ -64,19 +65,20 @@ class Pipeline:
|
|||||||
4. Restituisce la strategia finale
|
4. Restituisce la strategia finale
|
||||||
"""
|
"""
|
||||||
# Step 1: raccolta output dai membri del Team
|
# 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
|
# Step 2: aggregazione output strutturati
|
||||||
all_products = []
|
all_products: list[ProductInfo] = []
|
||||||
sentiments = []
|
sentiments: list[str] = []
|
||||||
|
|
||||||
for agent_output in team_outputs.member_responses:
|
for agent_output in team_outputs.member_responses:
|
||||||
if isinstance(agent_output, RunOutput):
|
if isinstance(agent_output, RunOutput) and agent_output.metadata is not None:
|
||||||
if "products" in agent_output.metadata:
|
keys = agent_output.metadata.keys()
|
||||||
|
if "products" in keys:
|
||||||
all_products.extend(agent_output.metadata["products"])
|
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"])
|
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"])
|
sentiments.append(agent_output.metadata["sentiment_social"])
|
||||||
|
|
||||||
aggregated_sentiment = "\n".join(sentiments)
|
aggregated_sentiment = "\n".join(sentiments)
|
||||||
@@ -88,7 +90,9 @@ class Pipeline:
|
|||||||
sentiment=aggregated_sentiment
|
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
|
prediction: PredictorOutput = result.content
|
||||||
|
|
||||||
# Step 4: restituzione strategia finale
|
# Step 4: restituzione strategia finale
|
||||||
|
|||||||
Reference in New Issue
Block a user