ð ãªãŒãã³ãœãŒã¹LLMã掻çšããCrewAIãšOllamaã¢ãã«ã«ãããã«ããšãŒãžã§ã³ãéèåæã¬ã€ã ðâš
ã¯ããã« ð
æè¿ãAIã䜿ã£ãéèåæã話é¡ã«ãªã£ãŠããŸãããAnoop Mauryaæ°ã«ããçŽ æŽãããã¢ã€ãã£ã¢ãå ã«ããªãŒãã³ãœãŒã¹ã®LLMã䜿ã£ããã«ããšãŒãžã§ã³ãã·ã¹ãã ã§ã©ããã£ãŠå¹ççã«éèåæãé²ããã®ãããã®å ·äœçãªæ¹æ³ããã®ã¬ã€ãã§ãããããã玹ä»ããŸãïŒðâš CrewAIãšOllamaã¢ãã«ã掻çšããŠãé£ããéèåæãAIãšãŒãžã§ã³ããã¡ãå©ããŠãããŸãïŒããã§ã¯ããã®ãšãŒãžã§ã³ããã¡ã®åœ¹å²ãå®éã®äœ¿ãæ¹ãèŠãŠãããŸãããïŒ
ãã«ããšãŒãžã§ã³ãã·ã¹ãã ã£ãŠäœïŒð€
ããã«ããšãŒãžã§ã³ãã·ã¹ãã ããšããèšèãèããšãã¡ãã£ãšé£ãããã«èãããŸããããã§ããå®éã¯ç°¡åã§ãïŒð¡
ãã«ããšãŒãžã§ã³ãã·ã¹ãã ãšã¯ãããã€ãã®ããšãŒãžã§ã³ãïŒå°ããªAIã¢ã·ã¹ã¿ã³ãïŒããé£æºããŠäžã€ã®å€§ããªä»äºãããªãä»çµã¿ã§ããäŸãã°ãéèåæã®å Žåãæ ªåŒåžå Žã®ããŒã¿ãåéãããšãŒãžã§ã³ãããã¥ãŒã¹ããœãŒã·ã£ã«ã¡ãã£ã¢ã®ææ ãèªã¿åããšãŒãžã§ã³ããªã©ãé£æºããŠåããŸããããããã®ãšãŒãžã§ã³ããåŸæãªåéã§åãçºæ®ããããŒã¿ãå ±æããªããæé©ãªæè³æŠç¥ãå°ãåºãã®ã§ãïŒâš
ç°¡åã«èšãã°ãåãšãŒãžã§ã³ãããå°é家ããŒã ããšããŠåããäžäººã§ã¯ã§ããªãä»äºãåæ ããŠããªããããªã€ã¡ãŒãžã§ããããã«ãããå¹ççã§è©³çŽ°ãªåæãå¯èœã«ãªããŸãã次ã«ãåãšãŒãžã§ã³ãã®åœ¹å²ã«ã€ããŠè©³ããèŠãŠãããŸãããïŒ
ãšãŒãžã§ã³ãã®åœ¹å²ïŒè©³çŽ°è§£èª¬ ð¥
ãã«ããšãŒãžã§ã³ãã·ã¹ãã ã®äžã§ãã©ããªãšãŒãžã§ã³ããã©ããªä»äºãããŠããã®ãïŒããã§ã¯ãäž»èŠãª4ã€ã®ãšãŒãžã§ã³ãã®åœ¹å²ã«ã€ããŠçŽ¹ä»ããŸãïŒ
1. æ ªåŒåžå ŽãªãµãŒãã£ãŒ ð
ãã®ãšãŒãžã§ã³ãã¯ãããŒã±ããããŒã¿ã®æ¢åµãã§ãïŒæ ªåŒåžå ŽãªãµãŒãã£ãŒã¯ãæ ªäŸ¡ã競åã®ããã©ãŒãã³ã¹ããã¯ãã«ã«ãã£ãŒããªã©ã®ããŒã¿ãåéãåæããŸãðãããã«ãããåžå Žã§äœãèµ·ãã£ãŠããã®ããã©ã®äŒæ¥ãæé·ããŠããã®ããæœåšçãªãªã¹ã¯ã¯äœããèŠæ¥µããŸãã
æè¡çã«ã¯ãyfinanceãªã©ã®ããŒã«ã䜿ã£ãŠãªã¢ã«ã¿ã€ã ã§ããŒã¿ãååŸããŸããäŸãã°ããAAPLïŒAppleïŒã®çŸåšã®ç¶æ³ã¯ïŒããšå°ãããšããã®ãªãµãŒãã£ãŒãå³åº§ã«ããŒã¿ãéããŠçããŠãããŸããããã䟿å©ã§ããïŒ
2. éèã¢ããªã¹ã ðŒ
次ã«ç»å Žããã®ãéèã¢ããªã¹ãïŒãã®ãšãŒãžã§ã³ãã¯ãæ ªåŒåžå ŽãªãµãŒãã£ãŒãéããããŒã¿ãåæããæè³ã«é¢ããæŽå¯ãæäŸããŸããð¡
äŸãã°ãæ ªäŸ¡ã®ãªã¹ã¯ãæé·å¯èœæ§ã«ã€ããŠè©äŸ¡ãããä»ãè²·ãæãã©ããããå€æããŸãããªã¹ã¯è©äŸ¡ã®ããã«ãyfinanceã§ååŸããããŒã¿ãçšããŠããŒã¿å€ïŒæ ªäŸ¡ã®å€åãªã¹ã¯ïŒãã·ã£ãŒãã¬ã·ãªïŒãªã¹ã¯ãããã®ãªã¿ãŒã³ïŒãèšç®ããããšãã§ããŸãã
3. ææ åæãšãŒãžã§ã³ã â€ïžð§
ææ ãæ ªåŒåžå Žã«äžãã圱é¿ã£ãŠãå®ã¯ãšãŠã倧ãããã§ããð ãã®ãšãŒãžã§ã³ãã¯ãã¥ãŒã¹ãSNSã®æçš¿ããåžå Žã®ææ ãåæããæ ªåŒãžã®äžéã®é¢å¿ãäžå®æãè©äŸ¡ããŸãã
äŸãã°ãæè¿ã®ãã¥ãŒã¹ãã©ã®ããã«åžå Žã«åœ±é¿ãäžããŠããã®ããSNSã§ã®æ ªã«å¯Ÿããåå¿ãã©ãããªã©ãåæããŸããTextBlobãä»ã®èªç¶èšèªåŠçããŒã«ã䜿ãããã¥ãŒã¹ã®ã¿ã€ãã«ãã³ã¡ã³ãããææ ãèªã¿åããŸããããžãã£ããªææ ã匷ããã°ãæ ªäŸ¡ã®äžæã®å ãã瀺åãããããããŸãããðâ€ïž
4. æè³ã¹ãã©ããžã¹ã ð¡
æåŸã«ãæè³ã¹ãã©ããžã¹ããç»å ŽïŒãã®ãšãŒãžã§ã³ãã¯ããªãµãŒãã£ãŒãã¢ããªã¹ããææ åæãšãŒãžã§ã³ããæäŸããæ å ±ãããšã«ãå ·äœçãªæè³æŠç¥ãç«ãŠãŸããð
ããšãã°ããªã¹ã¯ãåãããšãã§ããæè³å®¶åãã«ã¯é«ãªã¿ãŒã³ãæåŸ ã§ããæŠç¥ããäžæ¹ã§ãå®å®å¿åã®æè³å®¶ã«ã¯äœãªã¹ã¯ã®éžæè¢ãæäŸãããªã©ãæè»ã«æŠç¥ãç«æ¡ããŸããæè³å®¶ã®ããŒãºã«åããããã©ã³ãæ瀺ããããšãããã®ãšãŒãžã§ã³ãã®åœ¹å²ã§ãã
CrewAIãšOllamaã¢ãã«ã®éæ³ã®é£æº âš
ããã§ã®ãéæ³ããšã¯ãCrewAIãšOllamaã¢ãã«ã®é£æºã®ããšãæããŸããâš CrewAIã¯ããã¹ãŠã®ãšãŒãžã§ã³ããå¹æçã«é£æºã§ããããã«ãããåžä»€å¡ãã®åœ¹å²ãæãããŸããOllamaã®ãªãŒãã³ãœãŒã¹LLMïŒå€§èŠæš¡èšèªã¢ãã«ïŒã䜿ãããšã§ãåãšãŒãžã§ã³ãã¯æè»ã§æ£ç¢ºãªåæãè¡ãããšãã§ããŸãã
ãªãŒãã³ãœãŒã¹LLMã®åŒ·ã¿ ðª
ãªãŒãã³ãœãŒã¹LLMã䜿ãããšã®å€§ããªå©ç¹ã¯ãèªç±ã«ã«ã¹ã¿ãã€ãºã§ããããšã§ãããããã©ã€ãšã¿ãªãªAIã¢ãã«ãšæ¯ã¹ãŠãã©ã€ã»ã³ã¹è²»çšã®å¶çŽããªããç¶ç¶çã«æ¹è¯ãå ããããšãã§ããŸããðžâš Ollamaã®ã¢ãã«ã¯éåžžã«åŒ·åã§ãèªç¶èšèªåŠçïŒNLPïŒãæ°å€ããŒã¿ã®åãæ±ããåŸæãªã®ã§ãåãšãŒãžã§ã³ãã®ç²ŸåºŠãšå¹çãå€§å¹ ã«åäžãããŠãããŸãã
å®éã«ãšãŒãžã§ã³ãã掻çšããŠã¿ããïŒ ð§
å®éã«ãšãŒãžã§ã³ãã䜿ã£ãŠåæãè¡ãå Žåãã©ã®ãããªæµãã«ãªãããèŠãŠãããŸãããïŒä»¥äžã®Pythonã³ãŒãã䜿ããšãããã«ãšãŒãžã§ã³ãã·ã¹ãã ãæ§ç¯ããŠãæå®ããæ ªåŒã·ã³ãã«ã®åæãè¡ãããšãã§ããŸãã
from crewai import Agent, Task, Crew, Process
from langchain.llms import Ollama
from tools.yf_tech_analysis_tool import yf_tech_analysis
from tools.yf_fundamental_analysis_tool import yf_fundamental_analysis
from tools.sentiment_analysis_tool import sentiment_analysis
from tools.competitor_analysis_tool import competitor_analysis
from tools.risk_assessment_tool import risk_assessment
def create_crew(stock_symbol):
# Ollama LLMã®åæå
llm = Ollama(model="tinyllama")
# åãšãŒãžã§ã³ãã®å®çŸ©
researcher = Agent(
role='æ ªåŒåžå ŽãªãµãŒãã£ãŒ',
goal='æ ªåŒã®ããŒã¿ã詳现ã«åæãã',
tools=[yf_tech_analysis, yf_fundamental_analysis, competitor_analysis],
llm=llm
)
analyst = Agent(
role='éèã¢ããªã¹ã',
goal='éããããŒã¿ãåæããæè³ã€ã³ãµã€ããæäŸãã',
tools=[yf_tech_analysis, yf_fundamental_analysis, risk_assessment],
llm=llm
)
sentiment_analyst = Agent(
role='ææ
åæãšãŒãžã§ã³ã',
goal='åžå Žã®ææ
ãåæããæ ªåŒã«å¯Ÿãã圱é¿ãè©äŸ¡ãã',
tools=[sentiment_analysis],
llm=llm
)
strategist = Agent(
role='æè³ã¹ãã©ããžã¹ã',
goal='å
šãŠã®æ
å ±ãããšã«æè³æŠç¥ãçå®ãã',
tools=[],
llm=llm
)
# åã¿ã¹ã¯ã®å®çŸ©
research_task = Task(
description=f"{stock_symbol}ã®è©³çŽ°ãªæè¡ã»ãã¡ã³ãã¡ã³ã¿ã«åæãè¡ã",
agent=researcher
)
sentiment_task = Task(
description=f"{stock_symbol}ã«å¯Ÿããåžå Žã®ææ
ãåæãã",
agent=sentiment_analyst
)
analysis_task = Task(
description=f"{stock_symbol}ã«é¢ãããªãµãŒãããŒã¿ãšææ
åæãçµ±åãããªã¹ã¯è©äŸ¡ãè¡ã",
agent=analyst
)
strategy_task = Task(
description=f"{stock_symbol}ã«é¢ããæè³æŠç¥ãçå®ãã",
agent=strategist
)
# Crewã®äœæ
crew = Crew(
agents=[researcher, sentiment_analyst, analyst, strategist],
tasks=[research_task, sentiment_task, analysis_task, strategy_task],
process=Process.sequential
)
return crew
ãã®ããã«ãç°¡åã«åãšãŒãžã§ã³ããå®çŸ©ããã¿ã¹ã¯ãèšå®ããããšãã§ããŸãïŒâš
Streamlitã§èŠããåïŒð
ãã®åæçµæãèŠèŠçã«è¡šç€ºããããã«ãStreamlitãšããPythonã©ã€ãã©ãªã䜿çšããŠã€ã³ã¿ã©ã¯ãã£ããªããã·ã¥ããŒããäœæããŸããããã«ããããŠãŒã¶ãŒã¯æ ªäŸ¡ã®ããŒã¿ãææ åæããªã¹ã¯è©äŸ¡ãªã©ãçŽæçã«ç解ããããšãã§ããŸãïŒ
import streamlit as st
import yfinance as yf
import plotly.graph_objs as go
from crew import run_analysis
import json
def main():
st.set_page_config(layout="wide")
st.title("AIã掻çšããé«åºŠãªæ ªåŒåæ")
# ãŠãŒã¶ãŒå
¥å
stock_symbol = st.text_input("æ ªåŒã·ã³ãã«ãå
¥åããŠãã ãã (äŸ: AAPL):", "AAPL")
if st.button("æ ªåŒãåæãã"):
# CrewAIã«ããåæå®è¡
with st.spinner("å
æ¬çãªæ ªåŒåæãå®è¡äž..."):
result = run_analysis(stock_symbol)
# çµæã衚瀺
analysis = json.loads(result)
st.header("AIåæã¬ããŒã")
col1, col2 = st.columns(2)
with col1:
st.subheader("æè¡åæ")
st.write(analysis.get('technical_analysis', 'æè¡åæã®çµæã¯ãããŸããã'))
with col2:
st.subheader("ãã¡ã³ãã¡ã³ã¿ã«åæ")
st.write(analysis.get('fundamental_analysis', 'ãã¡ã³ãã¡ã³ã¿ã«åæã®çµæã¯ãããŸããã'))
st.subheader("ææ
åæ")
st.write(analysis.get('sentiment_analysis', 'ææ
åæã®çµæã¯ãããŸããã'))
st.subheader("ãªã¹ã¯è©äŸ¡")
st.write(analysis.get('risk_assessment', 'ãªã¹ã¯è©äŸ¡ã®çµæã¯ãããŸããã'))
st.subheader("æè³æŠç¥")
st.write(analysis.get('investment_strategy', 'æè³æŠç¥ã®çµæã¯ãããŸããã'))
ãã®ã³ãŒãã䜿ãã°ãæ ªåŒã®ç¶æ³ãã°ã©ãã§èŠãªãããAIãæäŸããã€ã³ãµã€ããç°¡åã«ç解ããããšãã§ããŸãïŒð
çµè«ãšæ¬¡ã®ã¹ããã ð
CrewAIãšOllamaã¢ãã«ã䜿ã£ããã«ããšãŒãžã§ã³ãã·ã¹ãã ã«ãããéèåæã®ããã»ã¹ã¯åçã«å¹çåãããŸããããããã®ãšãŒãžã§ã³ããç¹åãã圹å²ãæã¡ãååããªããåæãè¡ãããšã§ã人éã®ã¢ããªã¹ããè¡ããããè¿ éãã€æ£ç¢ºã«çµæãåŸãããšãå¯èœã§ããð¡âš
ãã®ã¬ã€ããåèã«ãèªåèªèº«ã§ãšãŒãžã§ã³ãã·ã¹ãã ãæ§ç¯ããå®éã«æ ªåŒã®åæã«åãçµãã§ã¿ãŠãã ããããããŠãStreamlitãªã©ã®å¯èŠåããŒã«ã掻çšããŠãããŒã¿ãèŠèŠçã«ç解ããããšãããããã§ãã
次ã®ã¹ããããšããŠãããã«é«åºŠãªãšãŒãžã§ã³ããè¿œå ããããã«ã¹ã¿ãã€ãºããŠèªåã®ããŒãºã«åã£ãéèåæããŒã«ãäœã£ãŠã¿ãŸãããïŒð ïžâš
ãããæªæ¥ã®éèåæãäžç·ã«äœéšããŠã¿ãŸãããïŒðð