File size: 2,531 Bytes
ad5d82d
7a7243d
ad5d82d
 
 
 
 
 
7a7243d
ad5d82d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d278324
ad5d82d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d278324
ad5d82d
 
 
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
# ํ™˜๊ฒฝ ๋ณ€์ˆ˜์—์„œ API ํ‚ค ๊ฐ€์ ธ์˜ค๊ธฐ
from dotenv import load_dotenv

# CrewAI ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ์—์„œ ํ•„์š”ํ•œ ํด๋ž˜์Šค ๊ฐ€์ ธ์˜ค๊ธฐ
from crewai import Agent, Task, Crew, Process
from langchain_openai import ChatOpenAI
import gradio as gr

load_dotenv()

# LLM
llm = ChatOpenAI(model='gpt-4o-mini', temperature=0.3)

# Search Tool
from langchain_community.tools.tavily_search import TavilySearchResults

search_tool = TavilySearchResults()

def run_crypto_crew(topic):

    # Agent
    researcher = Agent(
    role='Market Researcher',
    goal=f'Uncover emerging trends and investment opportunities in the cryptocurrency market in 2025. Focus on the topic: {topic}.',
    backstory='Identify groundbreaking trends and actionable insights.',
    verbose=True,
    tools=[search_tool],
    allow_delegation=False,
    llm=llm,
    max_iter=3,
    max_rpm=10,
    )


    analyst = Agent(
    role='Investment Analyst',
    goal=f'Analyze cryptocurrency market data to extract actionable insights and investment leads. Focus on the topic: {topic}.',
    backstory='Draw meaningful conclusions from cryptocurrency market data.',
    verbose=True,
    allow_delegation=False,
    llm=llm,
    )


    # Tasks
    research_task = Task(
    description=f'Explore the internet to pinpoint emerging trends and potential investment opportunities. Focus on the topic: {topic}.',
    agent=researcher,
    expected_output='A detailed summary of the reserch results in string format'
    )


    analyst_task = Task(
    description=f'Analyze the provided cryptocurrency market data to extract key insights and compile a concise report. Focus on the topic: {topic}.',
    agent=analyst,
    expected_output='A refined finalized version of the report in string format'
    )


    #`Crew` is a group of agents working together to accomplish a task
    crypto_crew = Crew(
    agents=[researcher, analyst],
    tasks=[research_task, analyst_task],
    process=Process.sequential  
    )

    #`kickoff` method starts the crew's process
    result = crypto_crew.kickoff()

    return result.raw    # raw text ์†์„ฑ์„ ์ถœ๋ ฅ 


def process_query(message, history):
    return run_crypto_crew(message)


if __name__ == '__main__':
    app = gr.ChatInterface(
        fn=process_query,
        type="messages",     
        title="Crypto Investment Advisor Bot",
        description="Get insights into cryptocurrency trends to guide your investments. AI-generated results are for reference only. invest responsibly."
    )

    app.launch()