Spaces:
Sleeping
Sleeping
from crewai import Agent | |
from langchain_huggingface import HuggingFacePipeline | |
from transformers import AutoTokenizer, AutoModelForCausalLM, pipeline, GenerationConfig | |
from crypto_tools import CryptoTools | |
from news_tools import NewsTools | |
from sentiment_tools import SentimentTools | |
class CryptoAnalysisAgents: | |
def __init__(self): | |
model_name = "microsoft/phi-2" # A smaller, open-source model | |
tokenizer = AutoTokenizer.from_pretrained(model_name) | |
model = AutoModelForCausalLM.from_pretrained(model_name) | |
# Set pad_token_id to eos_token_id if pad_token_id is not defined | |
model.config.pad_token_id = tokenizer.eos_token_id | |
# Create a custom generation config | |
generation_config = GenerationConfig( | |
max_new_tokens=512, | |
do_sample=True, | |
temperature=0.7, | |
top_p=0.95, | |
max_length=2048 | |
) | |
# Update the model' config | |
model.config.max_length = 2048 | |
pipe = pipeline( | |
"text-generation", | |
model=model, | |
tokenizer=tokenizer, | |
generation_config=generation_config, | |
repetition_penalty=1.1 | |
) | |
self.llm = HuggingFacePipeline(pipeline=pipe) | |
def market_analyst(self): | |
return Agent( | |
role='Crypto Market Analyst', | |
goal="Provide in-depth industry, market analysis and insights for cryptocurrencies. You also provide insight on our geo-politics and economic policies impact on crypto", | |
backstory="""You are a seasoned crypto market analyst with years of experience in blockchain technology and cryptocurrency markets. Your expertise helps clients navigate the volatile crypto landscape.""", | |
verbose=True, | |
llm=self.llm, | |
tools=[ | |
CryptoTools.get_crypto_price, | |
CryptoTools.get_market_cap, | |
NewsTools.search_crypto_news, | |
SentimentTools.analyze_sentiment | |
] | |
) | |
def technical_analyst(self): | |
return Agent( | |
role='Crypto Technical Analyst', | |
goal="Analyze cryptocurrency price patterns and provide technical insights", | |
backstory="""You are an expert in technical analysis, specializing in cryptocurrency markets. Your chart reading skills and understanding of technical indicators are unparalleled.""", | |
verbose=True, | |
llm=self.llm, | |
tools=[ | |
CryptoTools.get_crypto_price, | |
CryptoTools.calculate_rsi, | |
CryptoTools.calculate_moving_average | |
] | |
) | |
def crypto_advisor(self): | |
return Agent( | |
role='Cryptocurrency Investment Advisor', | |
goal="Provide comprehensive investment advice for cryptocurrency portfolios", | |
backstory="""You are a trusted cryptocurrency investment advisor with a deep understanding of blockchain technology, market dynamics, and risk management in the crypto space.""", | |
verbose=True, | |
llm=self.llm, | |
tools=[ | |
CryptoTools.get_crypto_price, | |
CryptoTools.get_market_cap, | |
NewsTools.search_crypto_news, | |
SentimentTools.analyze_sentiment | |
] | |
) |