menikev commited on
Commit
1c0d48c
·
verified ·
1 Parent(s): d48cbbd

Update crypto_analysis_agents.py

Browse files
Files changed (1) hide show
  1. crypto_analysis_agents.py +25 -17
crypto_analysis_agents.py CHANGED
@@ -1,31 +1,39 @@
1
- # crypto_analysis_agents.py - CrewAI Native Version
 
2
  from crewai import Agent
3
- from langchain_together import ChatTogether, Together
4
- from transformers import AutoTokenizer, AutoModelForCausalLM, pipeline, GenerationConfig
5
- import os
6
  from dotenv import load_dotenv
 
7
  from litellm import completion
8
 
9
- # Import the CrewAI native tool classes
10
  from crypto_tools import CryptoPriceTool, MarketCapTool, RSITool, MovingAverageTool
11
  from news_tools import NewsSearchTool
12
  from sentiment_tools import SentimentTool
13
 
14
-
15
  load_dotenv()
16
- TOGETHER_API_KEY = os.getenv("TOGETHER_API_KEY")
17
 
18
- class CryptoAnalysisAgents:
19
- def __init__(self):
20
- # Use Together AI's fast inference
21
- self.llm = Together(
22
- model="togethercomputer/llama-2-7b-chat",
23
- together_api_key=TOGETHER_API_KEY,
24
- temperature=0.7,
25
- max_tokens=512,
26
- top_p=0.9
 
 
 
27
  )
 
28
 
 
 
 
 
 
29
 
30
  def market_analyst(self):
31
  return Agent(
@@ -66,4 +74,4 @@ class CryptoAnalysisAgents:
66
  CryptoPriceTool(),
67
  SentimentTool()
68
  ]
69
- )
 
1
+ # crypto_analysis_agents.py - Refactored to use litellm with Together AI
2
+
3
  from crewai import Agent
 
 
 
4
  from dotenv import load_dotenv
5
+ import os
6
  from litellm import completion
7
 
8
+ # Import native tools
9
  from crypto_tools import CryptoPriceTool, MarketCapTool, RSITool, MovingAverageTool
10
  from news_tools import NewsSearchTool
11
  from sentiment_tools import SentimentTool
12
 
13
+ # Load environment variables
14
  load_dotenv()
15
+ os.environ["TOGETHERAI_API_KEY"] = os.getenv("TOGETHERAI_API_KEY") # Ensure environment is set
16
 
17
+ # Define LLM wrapper using litellm
18
+ class LLMWrapper:
19
+ def __init__(self, model="together_ai/togethercomputer/llama-2-7b-chat"):
20
+ self.model = model
21
+
22
+ def __call__(self, prompt):
23
+ messages = [
24
+ {"role": "user", "content": prompt}
25
+ ]
26
+ response = completion(
27
+ model=self.model,
28
+ messages=messages
29
  )
30
+ return response['choices'][0]['message']['content']
31
 
32
+ llm = LLMWrapper()
33
+
34
+ class CryptoAnalysisAgents:
35
+ def __init__(self):
36
+ self.llm = llm
37
 
38
  def market_analyst(self):
39
  return Agent(
 
74
  CryptoPriceTool(),
75
  SentimentTool()
76
  ]
77
+ )