-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
93 lines (73 loc) · 2.78 KB
/
main.py
File metadata and controls
93 lines (73 loc) · 2.78 KB
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
# 환경 변수에서 API 키 가져오기
import os
from dotenv import load_dotenv
load_dotenv()
OPENAI_API_KEY = os.getenv("OPENAI_API_KEY")
TAVILY_API_KEY = os.getenv("TAVILY_API_KEY")
# 필요한 라이브러리 import
from crewai import Agent, Task, Crew, Process
from langchain_openai import ChatOpenAI
from langchain.agents import Tool
from langchain_community.tools.tavily_search import TavilySearchResults
import gradio as gr
# LLM 설정
llm = ChatOpenAI(
model='gpt-3.5-turbo',
temperature=0,
api_key=OPENAI_API_KEY
)
# Search Tool 정의 (Tool.from_function으로 래핑)
search_tool = TavilySearchResults(api_key=TAVILY_API_KEY)
# Crew 실행 함수 정의
def run_crypto_crew(topic):
# 에이전트 설정
researcher = Agent(
role='Market Researcher',
goal=f'Uncover emerging trends and investment opportunities in the cryptocurrency market in 2024. Focus on the topic: {topic}.',
backstory='Identify groundbreaking trends and actionable insights.',
verbose=True,
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,
)
# 작업(Task) 정의
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 research results in string format.'
)
analyst_task = Task(
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}.',
agent=analyst,
expected_output='A refined finalized version of the report in string format.'
)
# Crew 정의 및 실행
crypto_crew = Crew(
agents=[researcher, analyst],
tasks=[research_task, analyst_task],
process=Process.sequential,
)
result = crypto_crew.kickoff()
return result
# Gradio용 래퍼 함수
def process_query(message, history):
result = run_crypto_crew(message)
print("CrewOutput result:", result)
return str(result) # 전체 객체를 문자열화해서 반환
# Gradio 앱 실행
if __name__ == '__main__':
app = gr.ChatInterface(
fn=process_query,
title="Crypto Investment Advisor Bot",
description="암호화폐 관련 트렌드를 파악하여 투자 인사이트를 제공해 드립니다."
)
app.launch()