Refactor Predictor and market data handling
- Added Predictor class with input preparation and instructions for financial strategy generation. - Removed PredictorAgent class and integrated its functionality into the new Predictor module. - Created a base market API wrapper and specific implementations for Coinbase and CryptoCompare. - Introduced PublicBinanceAgent for fetching public prices from Binance. - Refactored ToolAgent to utilize the new Predictor and market API wrappers for improved data handling and predictions. - Updated models to streamline the selection of available LLM providers. - Removed deprecated signer classes for Coinbase and CryptoCompare.
This commit is contained in:
@@ -1,27 +1,36 @@
|
||||
from app.agents.market_agent import MarketAgent
|
||||
from app.agents.news_agent import NewsAgent
|
||||
from app.agents.social_agent import SocialAgent
|
||||
from app.agents.predictor_agent import PredictorAgent
|
||||
from app.agents import predictor
|
||||
from app.agents.predictor import PredictorStyle
|
||||
from app.markets import get_first_available_market_api
|
||||
from app.models import Models
|
||||
|
||||
|
||||
class ToolAgent:
|
||||
def __init__(self, available_models: list[Models]):
|
||||
self.market_agent = MarketAgent()
|
||||
self.news_agent = NewsAgent()
|
||||
self.social_agent = SocialAgent()
|
||||
self.predictor_agent = PredictorAgent()
|
||||
def __init__(self, available_models: list[Models], all_styles: list[PredictorStyle]):
|
||||
self.available_models = available_models
|
||||
self.all_styles = all_styles
|
||||
|
||||
def interact(self, query: str, provider: str, style: str):
|
||||
"""
|
||||
Funzione principale che coordina gli agenti per rispondere alla richiesta dell'utente.
|
||||
"""
|
||||
self.market = get_first_available_market_api(currency="USD")
|
||||
self.choose_provider(0) # Default to the first model
|
||||
|
||||
def choose_provider(self, index: int):
|
||||
# TODO Utilizzare AGNO per gestire i modelli... è molto più semplice e permette di cambiare modello facilmente
|
||||
# TODO https://docs.agno.com/introduction
|
||||
# Inoltre permette di creare dei team e workflow di agenti più facilmente
|
||||
chosen_model = self.available_models[index]
|
||||
self.predictor = chosen_model.get_agent(predictor.instructions())
|
||||
self.news_agent = NewsAgent()
|
||||
self.social_agent = SocialAgent()
|
||||
|
||||
def interact(self, query: str, style_index: int):
|
||||
"""
|
||||
Funzione principale che coordina gli agenti per rispondere alla richiesta dell'utente.
|
||||
"""
|
||||
|
||||
# Step 1: raccolta analisi
|
||||
market_data = self.market_agent.analyze(query)
|
||||
cryptos = ["BTC", "ETH", "XRP", "LTC", "BCH"] # TODO rendere dinamico in futuro
|
||||
market_data = self.market.get_products(cryptos)
|
||||
news_sentiment = self.news_agent.analyze(query)
|
||||
social_sentiment = self.social_agent.analyze(query)
|
||||
|
||||
@@ -29,11 +38,15 @@ class ToolAgent:
|
||||
sentiment = f"{news_sentiment}\n{social_sentiment}"
|
||||
|
||||
# Step 3: previsione
|
||||
prediction = self.predictor_agent.predict(
|
||||
inputs = predictor.prepare_inputs(
|
||||
data=market_data,
|
||||
sentiment=sentiment,
|
||||
style=style,
|
||||
provider=provider
|
||||
style=self.all_styles[style_index],
|
||||
sentiment=sentiment
|
||||
)
|
||||
|
||||
return f"{market_data}\n{sentiment}\n\n📈 Consiglio finale:\n{prediction}"
|
||||
prediction = self.predictor.run(inputs)
|
||||
#output = prediction.content.split("</think>")[-1] # remove thinking steps and reasoning from the final output
|
||||
output = prediction.content
|
||||
|
||||
market_data = "\n".join([f"{product.symbol}: {product.price}" for product in market_data])
|
||||
return f"{market_data}\n{sentiment}\n\n📈 Consiglio finale:\n{output}"
|
||||
|
||||
Reference in New Issue
Block a user