File size: 6,340 Bytes
0d5b75b ffb3dcb 0d5b75b ffb3dcb 0d5b75b ffb3dcb 0d5b75b ffb3dcb 0d5b75b ffb3dcb 0d5b75b ffb3dcb 0d5b75b ffb3dcb 0d5b75b ffb3dcb 0d5b75b ffb3dcb 0d5b75b ffb3dcb 0d5b75b ffb3dcb 0d5b75b ffb3dcb 1176507 ffb3dcb 1176507 4c0b28d 0d5b75b ffb3dcb 0d5b75b | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 | import os
from crewai import Agent, Task, Crew, Process
from langchain.tools import DuckDuckGoSearchRun
from langchain.agents import Tool
import gradio as gr
# Initialize CoinGecko API for cryptocurrency data
duckduckgo_search_tool = DuckDuckGoSearchRun()
################################## - GOOGLE LLM - ##################################
from langchain_google_genai import ChatGoogleGenerativeAI
api_gemini = os.environ["api_gemini"]
llm = ChatGoogleGenerativeAI(model="gemini-pro", verbose=True, temperature=0.1, google_api_key=api_gemini)
################################## - GOOGLE LLM - ##################################
##################################### DDG Crypto Search ######################################
from langchain.tools import DuckDuckGoSearchRun
from langchain.agents import Tool
# Define wrapper functions for specific searches
ddg_search = DuckDuckGoSearchRun()
def coingecko_search_wrapper(input_text):
return ddg_search.run(f"site:coingecko.com {input_text}")
def coinmarketcap_search_wrapper(input_text):
return ddg_search.run(f"site:coinmarketcap.com {input_text}")
def general_search_wrapper(input_text):
return ddg_search.run(f'cryptocurrency {input_text}')
# Initialize tools with specific functions
GeneralSearch = Tool(
name="GeneralSearch",
func=general_search_wrapper,
description="General search for cryptocurrencies"
)
CoinGeckoSearch = Tool(
name="CoingeckoSearch",
func=coingecko_search_wrapper,
description="Searches on Coingecko"
)
CoinMarketCapSearch = Tool(
name="CoinmarketcapSearch",
func=coinmarketcap_search_wrapper,
description="Searches on CoinMarketCap"
)
##################################### DDG Crypto Search ######################################
def create_crewai_crypto_setup(crypto_symbol):
# Main Research Agent for technical and market analysis
research_agent = Agent(
role="Crypto Analysis Expert",
goal=f"Perform in-depth analysis on {crypto_symbol}, focusing on technical indicators, market trends, and recent news.",
backstory="Expert in technical analysis and market sentiment for cryptocurrencies, capable of identifying investment opportunities and risks.",
verbose=True,
max_iter=40,
allow_delegation=False,
tools=[duckduckgo_search_tool, CoinGeckoSearch, CoinMarketCapSearch],
llm=llm,
)
# Agent for compiling analysis into an investment strategy report
report_formatting_agent = Agent(
role="Strategy Report Creator",
goal="Synthesize analysis into a clear, actionable investment strategy report.",
backstory="Specializes in creating detailed investment strategies based on comprehensive market and technical analysis.",
verbose=True,
allow_delegation=True,
max_iter=30,
llm=llm,
)
# Market Trends and Price History Analysis
MarketTrends_T1 = Task(
description=f"Examine cryptocurrency coin - {crypto_symbol} price history to identify current market trends and potential future movements.",
expected_output="Summary of market trends and historical price analysis, list of key datapoints including price outlook short, medium, longterm",
async_execution=True,
agent=research_agent,
)
# Technical Analysis with Key Indicators
TechnicalAnalysis_T2 = Task(
description=f"Apply technical analysis on the cryptocurrency {crypto_symbol}, focusing on RSI, MACD, support/resistance levels, and other relevant indicators.",
expected_output="Technical analysis summary with key indicator findings, techincal setups, and numerical datapoints",
async_execution=True,
agent=research_agent,
)
# Sentiment and News Analysis
SentimentNews_T3 = Task(
description=f"Gather and analyze recent news and community sentiment regarding cryptocurrency - {crypto_symbol} to gauge market sentiment.",
expected_output="Summary of recent developments, news impact, and community sentiment",
async_execution=True,
agent=research_agent,
)
# Investment Opportunities and Risks Identification
OpportunitiesRisks_T4 = Task(
description=f"Identify and evaluate potential investment opportunities and risks associated with cryptocurrency - {crypto_symbol}.",
expected_output="List of investment opportunities and risks",
async_execution=True,
agent=research_agent,
)
# Comprehensive Investment Strategy Report
StrategyReport_T5 = Task(
description=f"""Create a detailed investment plan for the cryptocurrency - {crypto_symbol}, incorporating price targets, technical analysis, investment strategies, and timelines.
Ensure the plan includes actionable advice on when to buy, sell, and hold, along with risk management strategies.
""",
expected_output="""Sectioned report that focuses on breif bullet points and notes and key data points, Investment strategy report with actionable insights and strategies
NOTES:
The report is for advanced cryptocurrency experts.
Do note include disclaimers or warnings
Remove uneeded words make it concise.
Final output needs to be strictly 2000 characters or less.
I will tip you 10,000 dollars if you report great.""",
context=[MarketTrends_T1,TechnicalAnalysis_T2,SentimentNews_T3,OpportunitiesRisks_T4],
agent=report_formatting_agent,
)
# Crew setup for processing the tasks sequentially
crypto_crew = Crew(
agents=[research_agent, report_formatting_agent],
tasks=[MarketTrends_T1, TechnicalAnalysis_T2, SentimentNews_T3, OpportunitiesRisks_T4, StrategyReport_T5],
verbose=2,
process=Process.sequential,
)
crew_result = crypto_crew.kickoff()
return crew_result
# Gradio Interface setup
def run_crewai_crypto_app(crypto_symbol):
crew_result = create_crewai_crypto_setup(crypto_symbol)
return crew_result
iface = gr.Interface(
fn=run_crewai_crypto_app,
inputs="text",
outputs="text",
title="CryptoScout - CrewAI - Cryptocurrency Investment Advisor",
description="Enter a cryptocurrency symbol to analyze and generate a comprehensive investment plan."
)
iface.launch()
|