Spaces:
Sleeping
Sleeping
File size: 2,441 Bytes
68025ee | 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 65 66 67 68 69 70 71 72 73 | from agents.base import Agent
from llm.prompts import (
TECHNICAL_ANALYST_SYSTEM,
NEWS_ANALYST_SYSTEM,
SENTIMENT_ANALYST_SYSTEM,
build_technical_analyst_prompt,
build_news_analyst_prompt,
build_sentiment_analyst_prompt,
)
class TechnicalAnalyst(Agent):
def __init__(self, llm_client):
super().__init__("TechnicalAnalyst", TECHNICAL_ANALYST_SYSTEM, llm_client)
def build_prompt(self, context: dict) -> str:
return build_technical_analyst_prompt(context)
def parse(self, raw: str) -> dict:
result = super().parse(raw)
signal = result.get("signal", "NEUTRAL").upper()
if signal not in ("BULLISH", "BEARISH", "NEUTRAL"):
signal = "NEUTRAL"
return {
"signal": signal,
"strength": float(result.get("strength", 0.5)),
"key_levels": result.get("key_levels", {}),
"summary": str(result.get("summary", "")),
}
class NewsAnalyst(Agent):
def __init__(self, llm_client):
super().__init__("NewsAnalyst", NEWS_ANALYST_SYSTEM, llm_client)
def build_prompt(self, context: dict) -> str:
return build_news_analyst_prompt(
context.get("news", []),
context.get("asset", "BTC/USDT"),
)
def parse(self, raw: str) -> dict:
result = super().parse(raw)
sentiment = result.get("sentiment", "NEUTRAL").upper()
if sentiment not in ("POSITIVE", "NEGATIVE", "NEUTRAL"):
sentiment = "NEUTRAL"
return {
"sentiment": sentiment,
"score": float(result.get("score", 0.0)),
"key_themes": result.get("key_themes", []),
"summary": str(result.get("summary", "")),
}
class SentimentAnalyst(Agent):
def __init__(self, llm_client):
super().__init__("SentimentAnalyst", SENTIMENT_ANALYST_SYSTEM, llm_client)
def build_prompt(self, context: dict) -> str:
return build_sentiment_analyst_prompt(
context.get("onchain", {}),
context.get("asset", "BTC/USDT"),
)
def parse(self, raw: str) -> dict:
result = super().parse(raw)
return {
"sentiment": str(result.get("sentiment", "NEUTRAL")),
"score": float(result.get("score", 0.0)),
"funding_bias": str(result.get("funding_bias", "NEUTRAL")),
"summary": str(result.get("summary", "")),
}
|