Upload 2 files
Browse files- app.py +89 -0
- requirements.txt +0 -0
app.py
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 환경 변수에서 API 키 가져오기
|
| 2 |
+
import os
|
| 3 |
+
from dotenv import load_dotenv
|
| 4 |
+
load_dotenv()
|
| 5 |
+
OPENAI_API_KEY = os.getenv("OPENAI_API_KEY")
|
| 6 |
+
TAVILY_API_KEY = os.getenv("TAVILY_API_KEY")
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
# CrewAI 라이브러리에서 필요한 클래스 가져오기
|
| 10 |
+
from crewai import Agent, Task, Crew, Process
|
| 11 |
+
from langchain_openai import ChatOpenAI
|
| 12 |
+
import gradio as gr
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
# LLM
|
| 16 |
+
llm = ChatOpenAI(model='gpt-3.5-turbo', temperature=0,
|
| 17 |
+
api_key=OPENAI_API_KEY)
|
| 18 |
+
|
| 19 |
+
# Search Tool
|
| 20 |
+
from langchain_community.tools.tavily_search import TavilySearchResults
|
| 21 |
+
|
| 22 |
+
search_tool = TavilySearchResults(api_key=TAVILY_API_KEY)
|
| 23 |
+
|
| 24 |
+
def run_crypto_crew(topic):
|
| 25 |
+
|
| 26 |
+
# Agent
|
| 27 |
+
researcher = Agent(
|
| 28 |
+
role='Market Researcher',
|
| 29 |
+
goal=f'Uncover emerging trends and investment opportunities in the cryptocurrency market in 2024. Focus on the topic: {topic}.',
|
| 30 |
+
backstory='Identify groundbreaking trends and actionable insights.',
|
| 31 |
+
verbose=True,
|
| 32 |
+
tools=[search_tool],
|
| 33 |
+
allow_delegation=False,
|
| 34 |
+
llm=llm,
|
| 35 |
+
max_iter=3,
|
| 36 |
+
max_rpm=10,
|
| 37 |
+
)
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
analyst = Agent(
|
| 41 |
+
role='Investment Analyst',
|
| 42 |
+
goal=f'Analyze cryptocurrency market data to extract actionable insights and investment leads. Focus on the topic: {topic}.',
|
| 43 |
+
backstory='Draw meaningful conclusions from cryptocurrency market data.',
|
| 44 |
+
verbose=True,
|
| 45 |
+
allow_delegation=False,
|
| 46 |
+
llm=llm,
|
| 47 |
+
)
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
# Tasks
|
| 51 |
+
research_task = Task(
|
| 52 |
+
description=f'Explore the internet to pinpoint emerging trends and potential investment opportunities. Focus on the topic: {topic}.',
|
| 53 |
+
agent=researcher,
|
| 54 |
+
expected_output='A detailed summary of the reserch results in string format'
|
| 55 |
+
)
|
| 56 |
+
|
| 57 |
+
|
| 58 |
+
analyst_task = Task(
|
| 59 |
+
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}.',
|
| 60 |
+
agent=analyst,
|
| 61 |
+
expected_output='A refined finalized version of the report in string format'
|
| 62 |
+
)
|
| 63 |
+
|
| 64 |
+
|
| 65 |
+
#`Crew` is a group of agents working together to accomplish a task
|
| 66 |
+
crypto_crew = Crew(
|
| 67 |
+
agents=[researcher, analyst],
|
| 68 |
+
tasks=[research_task, analyst_task],
|
| 69 |
+
process=Process.sequential
|
| 70 |
+
)
|
| 71 |
+
|
| 72 |
+
#`kickoff` method starts the crew's process
|
| 73 |
+
result = crypto_crew.kickoff()
|
| 74 |
+
|
| 75 |
+
return result
|
| 76 |
+
|
| 77 |
+
|
| 78 |
+
def process_query(message, history):
|
| 79 |
+
return run_crypto_crew(message)
|
| 80 |
+
|
| 81 |
+
|
| 82 |
+
if __name__ == '__main__':
|
| 83 |
+
app = gr.ChatInterface(
|
| 84 |
+
fn=process_query,
|
| 85 |
+
title="Crypto Investment Advisor Bot",
|
| 86 |
+
description="암호화폐 관련 트렌드를 파악하여 투자 인사이트를 제공해 드립니다."
|
| 87 |
+
)
|
| 88 |
+
|
| 89 |
+
app.launch()
|
requirements.txt
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|