Spaces:
Running
Running
Update crypto_analysis_agents.py
Browse files- crypto_analysis_agents.py +18 -26
crypto_analysis_agents.py
CHANGED
|
@@ -1,10 +1,9 @@
|
|
| 1 |
from crewai import Agent
|
| 2 |
from langchain.llms import HuggingFacePipeline
|
| 3 |
-
from transformers import AutoTokenizer, AutoModelForCausalLM
|
| 4 |
from crypto_tools import CryptoTools
|
| 5 |
from news_tools import NewsTools
|
| 6 |
from sentiment_tools import SentimentTools
|
| 7 |
-
import torch
|
| 8 |
import os
|
| 9 |
|
| 10 |
class CryptoAnalysisAgents:
|
|
@@ -14,29 +13,22 @@ class CryptoAnalysisAgents:
|
|
| 14 |
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 15 |
model = AutoModelForCausalLM.from_pretrained(model_name)
|
| 16 |
|
| 17 |
-
#
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
#
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
do_sample=True,
|
| 31 |
-
pad_token_id=tokenizer.eos_token_id # Ensure the model doesn't stop too early
|
| 32 |
-
)
|
| 33 |
-
|
| 34 |
-
# Decode the output ids to get the generated text
|
| 35 |
-
output_text = tokenizer.decode(output_ids[0], skip_special_tokens=True)
|
| 36 |
-
return output_text
|
| 37 |
|
| 38 |
-
# Wrap
|
| 39 |
-
self.llm = HuggingFacePipeline(
|
| 40 |
|
| 41 |
def market_analyst(self):
|
| 42 |
return Agent(
|
|
@@ -90,6 +82,6 @@ if __name__ == "__main__":
|
|
| 90 |
# Input text for generation (example)
|
| 91 |
input_text = "Analyze the current state of Bitcoin in the market."
|
| 92 |
|
| 93 |
-
# Generate a report
|
| 94 |
-
report = market_analyst.llm
|
| 95 |
print(report)
|
|
|
|
| 1 |
from crewai import Agent
|
| 2 |
from langchain.llms import HuggingFacePipeline
|
| 3 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM, pipeline
|
| 4 |
from crypto_tools import CryptoTools
|
| 5 |
from news_tools import NewsTools
|
| 6 |
from sentiment_tools import SentimentTools
|
|
|
|
| 7 |
import os
|
| 8 |
|
| 9 |
class CryptoAnalysisAgents:
|
|
|
|
| 13 |
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 14 |
model = AutoModelForCausalLM.from_pretrained(model_name)
|
| 15 |
|
| 16 |
+
# Create the text-generation pipeline
|
| 17 |
+
pipe = pipeline(
|
| 18 |
+
"text-generation",
|
| 19 |
+
model=model,
|
| 20 |
+
tokenizer=tokenizer,
|
| 21 |
+
max_new_tokens=512, # Control the maximum number of tokens to generate
|
| 22 |
+
do_sample=True,
|
| 23 |
+
temperature=0.7,
|
| 24 |
+
top_p=0.95,
|
| 25 |
+
top_k=50,
|
| 26 |
+
repetition_penalty=1.1,
|
| 27 |
+
pad_token_id=tokenizer.eos_token_id # Ensure correct padding
|
| 28 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
|
| 30 |
+
# Wrap the pipeline in a HuggingFacePipeline
|
| 31 |
+
self.llm = HuggingFacePipeline(pipeline=pipe)
|
| 32 |
|
| 33 |
def market_analyst(self):
|
| 34 |
return Agent(
|
|
|
|
| 82 |
# Input text for generation (example)
|
| 83 |
input_text = "Analyze the current state of Bitcoin in the market."
|
| 84 |
|
| 85 |
+
# Generate a report using the pipeline
|
| 86 |
+
report = market_analyst.llm(input_text)
|
| 87 |
print(report)
|