CryptoScoutv1's picture
Update app.py
8b5f8cb verified
import os
from crewai import Agent, Task, Crew, Process
from langchain.tools import Tool # Assuming DuckDuckGoSearchRun or equivalent tool is available
import gradio as gr
############################################# - GOOGLE LLM - #############################################
import os
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 - #############################################
from langchain.tools import DuckDuckGoSearchRun
duckduckgo_search_tool = DuckDuckGoSearchRun()
from WebScape_TOOL import WebSearchTools
search = WebSearchTools()
process = WebSearchTools().process_search_results
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 market analysis on cryptocurrency, your job is search, research and generate a report based on the clients prompt.
NOTE - Make sure the report is clear, concise and professional with actionable advice and provide any relavant metrics / information.
Your audience is professional traders that understand the risks.
Ensure that you focus your search and research on the cryptocurrency symbol/name provided in the prompt along with the scope of or details the client wants.
Here is the clients prompt - {crypto_symbol}.
Note: Always use the process tool after the search to get futher data.
""",
backstory="Expert in technical analysis, market sentiment, and investment strategy for cryptocurrencies.",
verbose=True,
allow_delegation=True,
tools=[duckduckgo_search_tool],
llm=llm,
)
research_agent2 = Agent(
role="Crypto Analysis Expert",
goal=f"""Using the websearchtools perform in-depth research for the cryptocurrency - {crypto_symbol},
focusing on market outlook, investment strategies, technical/trade signals, etc
NOTE: Use the Search tool to search and the process tool to scape the url for additonal data, every serch much be followed by a process (webscrape)
""",
backstory="Expert in technical analysis, market sentiment, and investment strategy for cryptocurrencies.",
verbose=True,
allow_delegation=False,
llm=llm,
)
# Task 1: Market Outlook
market_data_t0 = Task(
description=f"""
Research using the following clients prompt which includes a cryptocurrency symbol or coin name - {crypto_symbol}.
Focus on the topic/details that are relavant to the clients prompt.
Research and search the information desired using the search tools available. Always attempt to use the process tool after every search.
Then orgainze your information and metrics which will be used and refered to in order to create a market/trade report for the client
""",
expected_output="Group similar data into sections, with information and data metrics presented in a clear and concise manner",
tools=[search.pricetargets_search,
search.forecast_search,
search.technicalsignals_search,
process],
agent=research_agent,
)
# Task 3: Technical/Trade Signals
technical_signals_t3 = Task(
description=f""""Research and perform technical analysis on cryptocurrency - {crypto_symbol},
identify recent trade and techincal signals, report over various timeframes, trend type (Bullish, neutral, bearish),
and type of indicator like moving averages, RSI, MACD, or other related signars if present during search.
note - Use only the crypto symbol to perfom your search""",
expected_output="Information in list with summary grouped if possible",
tools=[search.technicalsignals_search, process],
agent=research_agent,
)
### Gather information and structure it? or not ?
#### DEFINE What sections we need in the report for t3
Summary_t3 = Task(
description=f""""
Organize the data into a report format that focuses on the clients prompt.
Use the search tool to perform quality control on the final output, double check any price to make sure it matches todays price.
** NOTE **
- Any current price or marketcap data should be converted to appprox numbers.
- Remove all disclaimers or warnings regarding trade risk.
- Remove irrelevant information.
- Use search tool if needed.
""",
agent=research_agent,
)
# Crew setup for processing the tasks sequentially
crypto_crew = Crew(
agents=[research_agent, research_agent2],
tasks=[market_data_t0, Summary_t3],
verbose=2,
process=Process.sequential,
)
crew_result = crypto_crew.kickoff()
return crew_result
# Gradio Interface
def run_crewai_app(crypto_symbol):
crew_result = create_crewai_crypto_setup(crypto_symbol)
return crew_result
iface = gr.Interface(
fn=run_crewai_app,
inputs="text",
outputs="text",
title="CrewAI Trade Analysis",
description="Enter a Cryptocurrency Ticker + (optional) Techincal/trading signals, price predictions, price targets, buy/sell/hold prices."
)
iface.launch()