LangChainのToolsにYahoo Finance Newsが追加されていたので使ってみました。
コード
ToolsにGoogle Search、Wikipedia、Yahoo Finance Newsを設定し、Agentを作成します。
その後、AgentにMicrosoftについての2つの質問をします。
以下、コードです。
import os
from langchain.chat_models import ChatOpenAI
from langchain.agents import initialize_agent, AgentType
from langchain.tools import Tool
from langchain.tools.yahoo_finance_news import YahooFinanceNewsTool
from langchain.utilities import GoogleSearchAPIWrapper
from langchain.tools import WikipediaQueryRun
from langchain.utilities import WikipediaAPIWrapper
os.environ["GOOGLE_CSE_ID"] = "YOUR_CSE_ID"
os.environ["GOOGLE_API_KEY"] = "YOUR_GOOGLE_API_KEY"
os.environ["OPENAI_API_KEY"] = "YOUR_OPENAI_API_KEY"
googleSearch = GoogleSearchAPIWrapper()
tools = [Tool.from_function(
func=googleSearch.run,
name="Google Search",
description="Search Google for recent results",
)]
wikipediaSearch = WikipediaQueryRun(api_wrapper=WikipediaAPIWrapper())
tools.append(
Tool.from_function(
func=wikipediaSearch.run,
name="Wikipedia Search",
description="Search Wikipedia for company information.",
),
)
yahooFinanceNewsSearch = YahooFinanceNewsTool()
tools.append(
Tool.from_function(
func=yahooFinanceNewsSearch.run,
name="Yahoo Finance News Search",
description="Useful for when you need to answer questions about stock or finance.",
)
)
llm = ChatOpenAI(temperature=0.0)
agent_chain = initialize_agent(
tools,
llm,
agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION,
handle_parsing_errors=True,
verbose=True,
)
agent_result = agent_chain.run("Microsoftの企業概要について教えて。")
print(agent_result)
agent_result = agent_chain.run("Microsoftのファイナンスニュースについて教えて。")
print(agent_result)
出力結果
コードを実行するとWikipediaの検索とYahoo Finance Newsの検索が行われました。
Wikipedia
1つ目の「Microsoftの企業概要について教えて。」という質問に対して行われたWikipedia検索の出力結果です。
> Entering new AgentExecutor chain…
I should search for the company information of Microsoft.
Action: Wikipedia Search
Action Input: Microsoft
Observation:
Page: Microsoft
Summary: Microsoft Corporation is an American multinational technology corporation headquartered in Redmond, Washington. Microsoft’s best-known software products are the Windows line of operating systems, the Microsoft 365 suite of productivity applications, and the Edge web browser. Its flagship hardware products are the Xbox video game consoles and the Microsoft Surface lineup of touchscreen personal computers. Microsoft ranked No. 14 in the 2022 Fortune 500 rankings of the largest United States corporations by total revenue; it was the world’s largest software maker by revenue as of 2022. It is considered one of the Big Five American information technology companies, alongside Alphabet (parent company of Google), Amazon, Apple, and Meta Platforms.
Microsoft was founded by Bill Gates and Paul Allen on April 4, 1975, to develop and sell BASIC interpreters for the Altair 8800. It rose to dominate the personal computer operating system market with MS-DOS in the mid-1980s, followed by Windows. The company’s 1986 initial public offering (IPO) and subsequent rise in its share price created three billionaires and an estimated 12,000 millionaires among Microsoft employees. Since the 1990s, it has increasingly diversified from the operating system market and has made several corporate acquisitions, the largest being the acquisition of LinkedIn for $26.2 billion in December 2016, followed by its acquisition of Skype Technologies for $8.5 billion in May 2011.As of 2015, Microsoft is market-dominant in the IBM PC compatible operating system market and the office software suite market, although it has lost the majority of the overall operating system market to Android. The company also produces a wide range of other consumer and enterprise software for desktops, laptops, tabs, gadgets, and servers, including Internet search (with Bing), the digital services market (through MSN), mixed reality (HoloLens), cloud computing (Azure), and software development (Visual Studio).
Steve Ballmer replaced Gates as CEO in 2000 and later envisioned a “devices and services” strategy. This unfolded with Microsoft acquiring Danger Inc. in 2008, entering the personal computer production market for the first time in June 2012 with the launch of the Microsoft Surface line of tablet computers, and later forming Microsoft Mobile through the acquisition of Nokia’s devices and services division. Since Satya Nadella took over as CEO in 2014, the company has scaled back on hardware and instead focused on cloud computing, a move that helped the company’s shares reach their highest value since December 1999.Earlier dethroned by Apple in 2010, in 2018, Microsoft reclaimed its position as the most valuable publicly traded company in the world. In April 2019, Microsoft reached a trillion-dollar market cap, becoming the third U.S. public company to be valued at over $1 trillion after Apple and Amazon, respectively. As of 2022, Microsoft has the fourth-highest global brand valuation.
Microsoft has been criticized for its monopolistic practices and the company’s software has been criticized for problems with ease of use, robustness, and security.
Page: Microsoft Office
Summary: Microsoft Office, or simply Office, is a discontinued family of client software, server software, and services developed by Microsoft. It was first announced by Bill Gates on August 1, 1988, at COMDEX in Las Vegas. Initially a marketing term for an office suite (bundled set of productivity applications), the first version of Office contained Microsoft Word, Microsoft Excel, and Microsoft PowerPoint. Over the years, Office applications have grown substantially closer with shared features such as a common spell checker, Object Linking and Embedding data integration and Visual Basic for Applications scripting language. Microsoft also positions Office as a development platform for line-of-business software under the Office Business Applications brand.
It contains a word processor (Wor
Thought:I now know the company information of Microsoft.
Final Answer: Microsoft Corporation is an American multinational technology corporation headquartered in Redmond, Washington. It is known for its software products such as the Windows line of operating systems, Microsoft 365 suite of productivity applications, and the Edge web browser. It also produces hardware products like Xbox video game consoles and the Microsoft Surface lineup of touchscreen personal computers. Microsoft is one of the Big Five American information technology companies and is considered the world’s largest software maker by revenue. It was founded by Bill Gates and Paul Allen in 1975 and has diversified its offerings beyond operating systems, including acquisitions of LinkedIn and Skype Technologies. The company is market-dominant in the IBM PC compatible operating system market and the office software suite market.
> Finished chain.
GPT-4によるFinal Answerの日本語訳は以下のとおりです。
Microsoft Corporationは、アメリカの多国籍テクノロジー企業で、ワシントン州レドモンドに本社を置いています。Windowsのオペレーティングシステム、Microsoft 365の生産性アプリケーションスイート、Edgeウェブブラウザなどのソフトウェア製品で知られています。また、XboxのビデオゲームコンソールやMicrosoft Surfaceのタッチスクリーンパーソナルコンピュータのラインナップなどのハードウェア製品も製造しています。Microsoftは、アメリカの大手5社の情報技術企業の一つであり、収益によっては世界最大のソフトウェアメーカーと見なされています。1975年にBill GatesとPaul Allenによって設立され、オペレーティングシステムを超えた多岐にわたる提供をしています。これには、LinkedInやSkype Technologiesの買収も含まれます。同社は、IBM PC互換のオペレーティングシステム市場やオフィスソフトウェアスイート市場で市場を支配しています。
問題なく取得できていそうです。
Yahoo Finance News
2つ目の「Microsoftの企業概要について教えて。」という質問に対して行われたYahoo Finance News検索の出力結果です。
> Entering new AgentExecutor chain…
I need to find recent finance news about Microsoft.
Action: Yahoo Finance News Search
Action Input: Microsoft
Observation: UPDATE 1-OpenAI in talks to sell shares at $86 billion valuation – Bloomberg News
ChatGPT creator OpenAI is in talks to sell existing employees’ shares at an $86 billion valuation, Bloomberg News reported on Wednesday, citing people with knowledge of the matter. Last month, the Wall Street Journal had said that OpenAI, which is backed by Microsoft, was seeking a valuation of up to $90 billion for a sale of shares. ChatGPT, a chatbot that can generate human-like responses based on user prompts, has helped AI’s popularity erupt and has fueled a meteoric rise in the valuation of San Francisco-based OpenAI.
Microsoft Stock Is Setting Up With Earnings Due. What Does An Amazon Deal Mean For Investors?
Microsoft stock is holding firm despite market volatility as investors look ahead to Microsoft earnings next week. Investors are digesting the potential impact of its $1 billion deal with cloud-computing giant Amazon. Microsoft, set to report its fiscal Q1 earnings on Oct. 24, is currently forming a consolidation pattern, according to data on MarketSmith.
Analyst Report: Microsoft Corporation
Microsoft is the world’s largest independent software developer. The company was founded on the MS Windows operating system and MS Office business applications suite for PCs. As it has grown, Microsoft has expanded into enterprise software with Windows Server, SQL Server, Dynamics CRM, SharePoint, Azure, and Lync; hardware with the Xbox gaming/media platform and the Surface tablet; and online services through MSN and Bing. Microsoft acquired Skype, the internet VoIP communications service, in October 2011. More than 50% of revenue is generated outside the U.S.
Thought:I have found recent finance news about Microsoft.
Thought: I now know the recent finance news about Microsoft.
Final Answer: Recent finance news about Microsoft includes OpenAI in talks to sell shares at an $86 billion valuation and Microsoft stock holding firm despite market volatility as investors look ahead to Microsoft earnings next week.
> Finished chain.
GPT-4によるFinal Answerの日本語訳は以下のとおりです。
最近のMicrosoftに関する財務ニュースには、OpenAIが860億ドルの評価で株式を売却する交渉中であること、そして市場の変動にもかかわらずMicrosoftの株価が堅調に推移していることが含まれています。投資家たちは来週のMicrosoftの収益を楽しみにしています。
取得されたニュースは、現在閲覧できなくなっていますが、Yahooニュースで確認できました。
おわりに
企業研究に使えるアプリに組み込めそうです。