Upload 2 files
Browse files- app.py +83 -0
- requirements.txt +0 -0
app.py
ADDED
@@ -0,0 +1,83 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
from dotenv import load_dotenv
|
3 |
+
|
4 |
+
load_dotenv()
|
5 |
+
|
6 |
+
OPENAI_API_KEY = os.getenv('OPENAI_API_KEY')
|
7 |
+
TAVILY_API_KEY = os.getenv('TAVILY_API_KEY')
|
8 |
+
|
9 |
+
from crewai import Agent, Task, Crew, Process
|
10 |
+
from langchain_openai import ChatOpenAI
|
11 |
+
import gradio as gr
|
12 |
+
|
13 |
+
|
14 |
+
# LLM
|
15 |
+
llm = ChatOpenAI(model='gpt-4o', temperature=0, api_key=OPENAI_API_KEY)
|
16 |
+
|
17 |
+
# ๊ฒ์ ๋๊ตฌ (Search tools) ์ง์
|
18 |
+
from langchain_community.tools.tavily_search import TavilySearchResults
|
19 |
+
|
20 |
+
|
21 |
+
search_tool = TavilySearchResults(api_key=TAVILY_API_KEY)
|
22 |
+
|
23 |
+
def run_crypto_crew(topic):
|
24 |
+
# Agent
|
25 |
+
researcher = Agent(
|
26 |
+
role='Market Researcher',
|
27 |
+
goal=f'Uncover emerging trends and investment opportunities in the cryptocurrency market in 2024. Focus on the topic: {topic}.',
|
28 |
+
backstory='Identify groundbreaking trends and actionable insights.',
|
29 |
+
verbose=True,
|
30 |
+
tools=[search_tool],
|
31 |
+
allow_delegation=False,
|
32 |
+
llm=llm,
|
33 |
+
max_iter=3,
|
34 |
+
max_rpm=10,
|
35 |
+
)
|
36 |
+
analyst = Agent(
|
37 |
+
role='Investment Analyst',
|
38 |
+
goal=f'Analyze cryptocurrency market data to extract actionable insights and investment leads. Focus on the topic: {topic}.',
|
39 |
+
backstory='Draw meaningful conclusions from cryptocurrency market data.',
|
40 |
+
verbose=True,
|
41 |
+
allow_delegation=False,
|
42 |
+
llm=llm,
|
43 |
+
)
|
44 |
+
|
45 |
+
|
46 |
+
# Tasks
|
47 |
+
research_task = Task(
|
48 |
+
description=f'Explore the internet to pinpoint emerging trends and potential investment opportunities. Focus on the topic: {topic}.',
|
49 |
+
agent=researcher,
|
50 |
+
expected_output='A detailed summary of the reserch results in string format'
|
51 |
+
)
|
52 |
+
|
53 |
+
analyst_task = Task(
|
54 |
+
description=f'Analyze the provided cryptocurrency market data to extract key insights and compile a concise report in Korean Hangul. Focus on the topic: {topic}.',
|
55 |
+
agent=analyst,
|
56 |
+
expected_output='A refined finalized version of the report in string format'
|
57 |
+
)
|
58 |
+
|
59 |
+
#`Crew` is a group of agents working together to accomplish a task
|
60 |
+
crypto_crew = Crew(
|
61 |
+
agents=[researcher, analyst],
|
62 |
+
tasks=[research_task, analyst_task],
|
63 |
+
process=Process.sequential
|
64 |
+
)
|
65 |
+
|
66 |
+
#`kickoff` method starts the crew's process
|
67 |
+
result = crypto_crew.kickoff()
|
68 |
+
|
69 |
+
return result
|
70 |
+
|
71 |
+
|
72 |
+
def process_query(message, history):
|
73 |
+
return run_crypto_crew(message)
|
74 |
+
|
75 |
+
|
76 |
+
if __name__ == '__main__':
|
77 |
+
app = gr.ChatInterface(
|
78 |
+
fn=process_query,
|
79 |
+
title="Crypto Investment Advisor Bot",
|
80 |
+
description="์ํธํํ ๊ด๋ จ ํธ๋ ๋๋ฅผ ํ์
ํ์ฌ ํฌ์ ์ธ์ฌ์ดํธ๋ฅผ ์ ๊ณตํด ๋๋ฆฝ๋๋ค."
|
81 |
+
)
|
82 |
+
|
83 |
+
app.launch()
|
requirements.txt
ADDED
The diff for this file is too large to render.
See raw diff
|
|