menikev commited on
Commit
d35a027
·
verified ·
1 Parent(s): 4473217

Update crypto_analysis_agents.py

Browse files
Files changed (1) hide show
  1. crypto_analysis_agents.py +53 -62
crypto_analysis_agents.py CHANGED
@@ -1,66 +1,57 @@
1
- import asyncio
2
- from crewai import Crew
3
- from textwrap import dedent
4
- import json
5
- from crypto_analysis_agents import CryptoAnalysisAgents
6
- from crypto__analysis_tasks import CryptoAnalysisTasks
7
-
8
- class CryptoCrew:
9
- def __init__(self, crypto):
10
- self.crypto = crypto
11
-
12
- async def run(self):
13
- agents = CryptoAnalysisAgents()
14
- tasks = CryptoAnalysisTasks()
15
-
16
- market_analyst_agent = agents.market_analyst()
17
- technical_analyst_agent = agents.technical_analyst()
18
- crypto_advisor_agent = agents.crypto_advisor()
19
-
20
- market_research_task = tasks.market_research(market_analyst_agent, self.crypto)
21
- technical_analysis_task = tasks.technical_analysis(technical_analyst_agent)
22
- sentiment_analysis_task = tasks.sentiment_analysis(market_analyst_agent)
23
- recommend_task = tasks.recommend(crypto_advisor_agent)
24
-
25
- crew = Crew(
26
- agents=[
27
- market_analyst_agent,
28
- technical_analyst_agent,
29
- crypto_advisor_agent
30
- ],
31
- tasks=[
32
- market_research_task,
33
- technical_analysis_task,
34
- sentiment_analysis_task,
35
- recommend_task
36
- ],
37
  verbose=True,
38
- iteration_limit=300,
39
- time_limit=600
 
 
 
 
 
40
  )
41
 
42
- try:
43
- result = await asyncio.wait_for(crew.kickoff(), timeout=600)
44
- except asyncio.TimeoutError:
45
- return {"summary": "Analysis timed out. Please try again with a simpler query or increased time limit."}
46
-
47
- parsed_result = self.parse_result(result)
48
- return parsed_result
49
-
50
- def parse_result(self, result):
51
- # Implement your parse_result method here
52
- # This is a placeholder implementation
53
- return {"summary": str(result)}
 
54
 
55
- if __name__ == "__main__":
56
- print("## Welcome to Crypto Analysis Crew")
57
- print('-------------------------------')
58
- crypto = input(dedent("""
59
- What is the cryptocurrency you want to analyze?
60
- """))
61
- crypto_crew = CryptoCrew(crypto)
62
- result = asyncio.run(crypto_crew.run())
63
- print("\n\n########################")
64
- print("## Here is the Report")
65
- print("########################\n")
66
- print(json.dumps(result, indent=2))
 
 
 
1
+ from crewai import Agent
2
+ from langchain.llms import HuggingFaceHub
3
+ from langchain_community.embeddings import HuggingFaceEmbeddings
4
+ from langchain_community.llms import HuggingFaceHub
5
+ from tools.crypto_tools import CryptoTools
6
+ from tools.news_tools import NewsTools
7
+ from tools.sentiment_tools import SentimentTools
8
+
9
+ class CryptoAnalysisAgents:
10
+ def __init__(self):
11
+ self.llm = HuggingFaceHub(repo_id="bigscience/bloom", model_kwargs={"temperature": 0.7, "max_length": 1024})
12
+ self.embeddings = HuggingFaceEmbeddings(model_name="sentence-transformers/all-MiniLM-L6-v2")
13
+ huggingfacehub_api_token=os.getenv("HUGGINGFACEHUB_API_TOKEN"
14
+
15
+ def market_analyst(self):
16
+ return Agent(
17
+ role='Crypto Market Analyst',
18
+ goal="Provide in-depth industry, market analysis and insights for cryptocurrencies. You also provide insight on on our geo-politics and economic policies impact on crypto",
19
+ 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.""",
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
20
  verbose=True,
21
+ llm=self.llm,
22
+ tools=[
23
+ CryptoTools.get_crypto_price,
24
+ CryptoTools.get_market_cap,
25
+ NewsTools.search_crypto_news,
26
+ SentimentTools.analyze_sentiment
27
+ ]
28
  )
29
 
30
+ def technical_analyst(self):
31
+ return Agent(
32
+ role='Crypto Technical Analyst',
33
+ goal="Analyze cryptocurrency price patterns and provide technical insights",
34
+ backstory="""You are an expert in technical analysis, specializing in cryptocurrency markets. Your chart reading skills and understanding of technical indicators are unparalleled.""",
35
+ verbose=True,
36
+ llm=self.llm,
37
+ tools=[
38
+ CryptoTools.get_crypto_price,
39
+ CryptoTools.calculate_rsi,
40
+ CryptoTools.calculate_moving_average
41
+ ]
42
+ )
43
 
44
+ def crypto_advisor(self):
45
+ return Agent(
46
+ role='Cryptocurrency Investment Advisor',
47
+ goal="Provide comprehensive investment advice for cryptocurrency portfolios",
48
+ backstory="""You are a trusted cryptocurrency investment advisor with a deep understanding of blockchain technology, market dynamics, and risk management in the crypto space.""",
49
+ verbose=True,
50
+ llm=self.llm,
51
+ tools=[
52
+ CryptoTools.get_crypto_price,
53
+ CryptoTools.get_market_cap,
54
+ NewsTools.search_crypto_news,
55
+ SentimentTools.analyze_sentiment
56
+ ]
57
+ )