Spaces:
Running
Running
Update crypto_analysis_agents.py
Browse files- crypto_analysis_agents.py +35 -47
crypto_analysis_agents.py
CHANGED
|
@@ -1,81 +1,69 @@
|
|
| 1 |
from crewai import Agent
|
|
|
|
| 2 |
from langchain_huggingface import HuggingFacePipeline
|
| 3 |
from transformers import AutoTokenizer, AutoModelForCausalLM, pipeline, GenerationConfig
|
| 4 |
from crypto_tools import CryptoTools
|
| 5 |
from news_tools import NewsTools
|
| 6 |
from sentiment_tools import SentimentTools
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
class CryptoAnalysisAgents:
|
| 9 |
def __init__(self):
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
# Set pad_token_id to eos_token_id if pad_token_id is not defined
|
| 15 |
-
model.config.pad_token_id = tokenizer.eos_token_id
|
| 16 |
-
|
| 17 |
-
# Create a custom generation config
|
| 18 |
-
generation_config = GenerationConfig(
|
| 19 |
-
max_new_tokens=512,
|
| 20 |
-
do_sample=True,
|
| 21 |
temperature=0.7,
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
)
|
| 25 |
-
|
| 26 |
-
# Update the model' config
|
| 27 |
-
model.config.max_length = 2048
|
| 28 |
-
|
| 29 |
-
pipe = pipeline(
|
| 30 |
-
"text-generation",
|
| 31 |
-
model=model,
|
| 32 |
-
tokenizer=tokenizer,
|
| 33 |
-
generation_config=generation_config,
|
| 34 |
-
repetition_penalty=1.1
|
| 35 |
)
|
| 36 |
-
|
| 37 |
|
| 38 |
-
|
|
|
|
|
|
|
|
|
|
| 39 |
|
| 40 |
def market_analyst(self):
|
| 41 |
return Agent(
|
| 42 |
role='Crypto Market Analyst',
|
| 43 |
-
goal="Provide
|
| 44 |
-
backstory="
|
| 45 |
-
verbose=
|
| 46 |
llm=self.llm,
|
| 47 |
tools=[
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
SentimentTools.analyze_sentiment
|
| 52 |
]
|
| 53 |
)
|
|
|
|
| 54 |
def technical_analyst(self):
|
| 55 |
return Agent(
|
| 56 |
role='Crypto Technical Analyst',
|
| 57 |
-
goal="Analyze
|
| 58 |
-
backstory="
|
| 59 |
-
verbose=
|
| 60 |
llm=self.llm,
|
| 61 |
tools=[
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
]
|
| 66 |
)
|
| 67 |
|
| 68 |
def crypto_advisor(self):
|
| 69 |
return Agent(
|
| 70 |
-
role='
|
| 71 |
-
goal="
|
| 72 |
-
backstory="
|
| 73 |
-
verbose=
|
| 74 |
llm=self.llm,
|
| 75 |
tools=[
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
NewsTools.search_crypto_news,
|
| 79 |
-
SentimentTools.analyze_sentiment
|
| 80 |
]
|
| 81 |
)
|
|
|
|
| 1 |
from crewai import Agent
|
| 2 |
+
from langchain_together import Together
|
| 3 |
from langchain_huggingface import HuggingFacePipeline
|
| 4 |
from transformers import AutoTokenizer, AutoModelForCausalLM, pipeline, GenerationConfig
|
| 5 |
from crypto_tools import CryptoTools
|
| 6 |
from news_tools import NewsTools
|
| 7 |
from sentiment_tools import SentimentTools
|
| 8 |
+
import os
|
| 9 |
+
from dotenv import load_dotenv
|
| 10 |
+
|
| 11 |
+
TOGETHER_API_KEY=TOGETHER_API_KEY
|
| 12 |
+
load_dotenv()
|
| 13 |
|
| 14 |
class CryptoAnalysisAgents:
|
| 15 |
def __init__(self):
|
| 16 |
+
# Use Together AI's fast inference instead of local models
|
| 17 |
+
self.llm = Together(
|
| 18 |
+
model="meta-llama/Llama-2-7b-chat-hf", # Fast, efficient model
|
| 19 |
+
together_api_key=os.getenv("TOGETHER_API_KEY"),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
temperature=0.7,
|
| 21 |
+
max_tokens=512,
|
| 22 |
+
top_p=0.9
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
)
|
|
|
|
| 24 |
|
| 25 |
+
# Initialize tools once to avoid repeated loading
|
| 26 |
+
self.crypto_tools = CryptoTools()
|
| 27 |
+
self.news_tools = NewsTools()
|
| 28 |
+
self.sentiment_tools = SentimentTools()
|
| 29 |
|
| 30 |
def market_analyst(self):
|
| 31 |
return Agent(
|
| 32 |
role='Crypto Market Analyst',
|
| 33 |
+
goal="Provide concise market analysis and insights for cryptocurrencies",
|
| 34 |
+
backstory="Expert crypto analyst with focus on market trends and news impact",
|
| 35 |
+
verbose=False, # Reduce verbosity for speed
|
| 36 |
llm=self.llm,
|
| 37 |
tools=[
|
| 38 |
+
self.crypto_tools.get_crypto_price,
|
| 39 |
+
self.crypto_tools.get_market_cap,
|
| 40 |
+
self.news_tools.search_crypto_news
|
|
|
|
| 41 |
]
|
| 42 |
)
|
| 43 |
+
|
| 44 |
def technical_analyst(self):
|
| 45 |
return Agent(
|
| 46 |
role='Crypto Technical Analyst',
|
| 47 |
+
goal="Analyze price patterns and technical indicators quickly",
|
| 48 |
+
backstory="Technical analysis specialist focused on key indicators",
|
| 49 |
+
verbose=False,
|
| 50 |
llm=self.llm,
|
| 51 |
tools=[
|
| 52 |
+
self.crypto_tools.get_crypto_price,
|
| 53 |
+
self.crypto_tools.calculate_rsi,
|
| 54 |
+
self.crypto_tools.calculate_moving_average
|
| 55 |
]
|
| 56 |
)
|
| 57 |
|
| 58 |
def crypto_advisor(self):
|
| 59 |
return Agent(
|
| 60 |
+
role='Investment Advisor',
|
| 61 |
+
goal="Synthesize analysis into clear investment recommendations",
|
| 62 |
+
backstory="Investment advisor specializing in crypto portfolio recommendations",
|
| 63 |
+
verbose=False,
|
| 64 |
llm=self.llm,
|
| 65 |
tools=[
|
| 66 |
+
self.crypto_tools.get_crypto_price,
|
| 67 |
+
self.sentiment_tools.analyze_sentiment
|
|
|
|
|
|
|
| 68 |
]
|
| 69 |
)
|