menikev commited on
Commit
a326317
·
verified ·
1 Parent(s): 6727726

Update crypto_analysis_agents.py

Browse files
Files changed (1) hide show
  1. 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
- model_name = "microsoft/phi-2" # A smaller, open-source model
11
- tokenizer = AutoTokenizer.from_pretrained(model_name)
12
- model = AutoModelForCausalLM.from_pretrained(model_name)
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
- top_p=0.95,
23
- max_length=2048
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
- self.llm = HuggingFacePipeline(pipeline=pipe)
 
 
 
39
 
40
  def market_analyst(self):
41
  return Agent(
42
  role='Crypto Market Analyst',
43
- 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",
44
- 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.""",
45
- verbose=True,
46
  llm=self.llm,
47
  tools=[
48
- CryptoTools.get_crypto_price,
49
- CryptoTools.get_market_cap,
50
- NewsTools.search_crypto_news,
51
- SentimentTools.analyze_sentiment
52
  ]
53
  )
 
54
  def technical_analyst(self):
55
  return Agent(
56
  role='Crypto Technical Analyst',
57
- goal="Analyze cryptocurrency price patterns and provide technical insights",
58
- backstory="""You are an expert in technical analysis, specializing in cryptocurrency markets. Your chart reading skills and understanding of technical indicators are unparalleled.""",
59
- verbose=True,
60
  llm=self.llm,
61
  tools=[
62
- CryptoTools.get_crypto_price,
63
- CryptoTools.calculate_rsi,
64
- CryptoTools.calculate_moving_average
65
  ]
66
  )
67
 
68
  def crypto_advisor(self):
69
  return Agent(
70
- role='Cryptocurrency Investment Advisor',
71
- goal="Provide comprehensive investment advice for cryptocurrency portfolios",
72
- backstory="""You are a trusted cryptocurrency investment advisor with a deep understanding of blockchain technology, market dynamics, and risk management in the crypto space.""",
73
- verbose=True,
74
  llm=self.llm,
75
  tools=[
76
- CryptoTools.get_crypto_price,
77
- CryptoTools.get_market_cap,
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
  )