【Fate・東方ネタで学ぶ】日本語版Tavily APIの完全ガイド

未分類
~シリーズ情報~

Introduction

Introduction | Tavily
Tavily Search API is a search engine optimized for LLMs and RAG, aimed at efficient, quick and persistent search results. Unlike other search APIs such as Serp ...

Tavily Search APIの特徴

  • 目的と特徴 : Tavily Search APIは、LLM(大規模言語モデル: Large Language Models)やRAG(検索強化生成: Retrieval-Augmented Generation)に特化した検索エンジンです。SerpやGoogleなどの他の検索APIとは異なり、AI開発者や自動AIエージェント向けに特化した検索を提供します。
  • 機能 : 検索、スクレイピング、フィルタリング、オンラインソースからの関連情報の抽出を一つのAPI呼び出しで処理します。
  • 使用例 : このAPIは、質問への回答や、複雑な研究タスクを数秒で完了させるために使用できます。

Tavily Search APIを選ぶ理由

  • 目的に合わせた設計 : LLMエージェントに特化した設計で、RAGに最適化された検索結果を提供します。
  • 多様性 : 検索の深さ、ドメイン管理、HTMLコンテンツの解析など、カスタマイズ可能な機能が豊富です。
  • パフォーマンス : 速度と効率を重視し、リアルタイムで信頼性の高い情報を提供します。
  • 統合のしやすさ : Pythonライブラリや簡単なAPI呼び出し、LangchainやLLamaIndexなどのパートナーとの統合が容易です。
  • 透明性と情報提供 : 詳細なドキュメンテーションで、基本から高度な機能まで理解をサポートします。

Tavily Search APIの動作方法

  • 従来のAPIとの違い : GoogleやSerp、Bingなどの既存の検索APIは、ユーザーのクエリに基づいて検索結果を返しますが、関連性の低い結果が含まれることがあります。Tavilyは、20以上のサイトからの検索結果を集約し、AIを用いて関連性の高いソースとコンテンツを選定、フィルタリングし、ランキングします。
  • 開発者向けカスタマイズ : 開発者はコンテキストやレスポンスのトークン上限など、カスタムフィールドを追加し、LLM向けの最適な検索体験を実現できます。

使い始める方法

  • サインアップ : Tavilyのプラットフォームでサインアップします。
  • ユニークキーの取得 : 登録後、Tavily APIキーが生成され、サービスとの接続が容易になります。
  • API Playgroundでのテスト : インタラクティブなAPI Playgroundで機能を試してみてください。
  • 探索と学習 : Python SDKやREST APIのドキュメンテーションを通じて、様々な機能に慣れ親しむことができます。
  • 実用例 : Research Assistantの機能を試し、APIがAIコンテンツ生成をどのように最適化するかを確認してください。
Tavily AI

コミュニティとサポート

  • 最新情報の入手 : コミュニティに参加し、継続的な改善と開発の最新情報を得ることができます。
  • 質問とサポート : 問題や質問がある場合、いつでもサポートチームが対応します。

Python SDKの簡単な使い方

Pythonライブラリを使えば、Tavily APIとのやり取りが簡単になります。基本的な検索機能から高度な検索機能まで、Pythonプログラムから直接アクセスできます。

📦 インストール方法

TavilyのPythonライブラリは、以下のコマンドで簡単にインストールできます。

pip install tavily-python

🛠️ 使い方

Tavily APIには、基本と高度の2種類の検索深度があります。基本検索はパフォーマンスに最適化されており、応答時間が速いです。一方、高度検索は品質を最適化するため、応答に5~10秒かかることがあります。

重要なのは、'advanced'検索深度を使用すると、各サイトから関連性の高いコンテンツのみが取得される点です。以下のように主要な検索メソッドを使用できます。


from tavily import TavilyClient
tavily = TavilyClient(api_key="YOUR_API_KEY")

# 基本検索の例
# 2024年にAppleに投資すべきでしょうか?
response = tavily.search(query="Should I invest in Apple in 2024?")

# 高度検索の例
response = tavily.search(query="Should I invest in Apple in 2024?", search_depth="advanced")

# LLMに渡す検索結果のコンテキストを取得
context = [{"url": obj["url"], "content": obj["content"]} for obj in response.results]
基本検索の結果

{'query': 'Should I invest in Apple in 2024?',
 'follow_up_questions': None,
 'answer': None,
 'images': None,
 'results': [{'title': 'Should You Buy Apple Stock in 2024? | The Motley Fool',
   'url': 'https://www.fool.com/investing/2023/12/26/should-you-buy-apple-stock-in-2024/',
   'content': '"\nThe massive number of installed devices worldwide helps Apple make more money through its services, such as the App Store, Apple Music, and Apple Pay. He has said that the introduction of the product "marks the beginning of a new era for computing" and that Vision Pro is "unlike anything created before. The Motley Fool reaches millions of people every month through our premium investing solutions, free guidance and market analysis on Fool.com, top-rated podcasts, and non-profit The Motley Fool Foundation.\n The Motley Fool reaches millions of people every month through our premium investing solutions, free guidance and market analysis on Fool.com, top-rated podcasts, and non-profit The Motley Fool Foundation.\n "\nApple\'s downsides\nAs great as Apple is, the company and its stock have some downsides.',
   'score': 0.95568,
   'raw_content': None},
  {'title': 'Should You Buy Apple Stock in 2024? - Yahoo Finance',
   'url': 'https://finance.yahoo.com/news/buy-apple-stock-2024-105200222.html',
   'content': 'S&P Futures\nDow Futures\nNasdaq Futures\nRussell 2000 Futures\nCrude Oil\nGold\nSilver\nEUR/USD\n10-Yr Bond\nVix\nGBP/USD\nUSD/JPY\nBitcoin USD\nCMC Crypto 200\nFTSE 100\nNikkei 225\nShould You Buy Apple Stock in 2024?\n Before you buy stock in Apple, consider this:\nThe Motley Fool Stock Advisor analyst team just identified what they believe are the 10 best stocks for investors to buy now... and Apple wasn\'t one of them. "\nThe massive number of installed devices worldwide helps Apple make more money through its services, such as the App Store, Apple Music, and Apple Pay. "\nApple\'s downsides\nAs great as Apple is, the company and its stock have some downsides. He has said that the introduction of the product "marks the beginning of a new era for computing" and that Vision Pro is "unlike anything created before.',
   'score': 0.95494,
   'raw_content': None},
  {'title': "Buying Apple Stock in 2024 and Expecting It to 2X by 2029? Here's What ...",
   'url': 'https://www.fool.com/investing/2023/12/20/buying-apple-stock-2024-expecting-double-2029/',
   'content': "Here's What Has to Happen\nKey Points\nNASDAQ: AAPL\nApple\nYou’re reading a free article with opinions that may differ from The Motley Fool’s Premium Investing Services. The Motley Fool reaches millions of people every month through our premium investing solutions, free guidance and market analysis on Fool.com, top-rated podcasts, and non-profit The Motley Fool Foundation.\n The Motley Fool reaches millions of people every month through our premium investing solutions, free guidance and market analysis on Fool.com, top-rated podcasts, and non-profit The Motley Fool Foundation.\n Some bullish investors on the sidelines might be looking to buy shares in the new year with the expectation that Apple could double by 2029. About The Motley Fool\nOur Services\nAround the Globe\nFree Tools\nOur Affiliates",
   'score': 0.93291,
   'raw_content': None},
  {'title': "Here's What to Expect From Apple Stock in 2024 | InvestorPlace",
   'url': 'https://investorplace.com/market360/2023/12/heres-what-to-expect-from-apple-stock-in-2024/',
   'content': "Article printed from InvestorPlace Media, https://investorplace.com/market360/2023/12/heres-what-to-expect-from-apple-stock-in-2024/.\n©2023 InvestorPlace Media, LLC\nMore from Louis Navellier\nMarket Analysis\nInflation and Retail Sales Reports Are Out – Here’s What You Need to Know\nMarket Analysis\nA New AI Powerhouse Enters the Fray\nStocks to Sell\n7 F-Rated Consumer Discretionary Stocks to Ditch in December\nLouis's Most Popular\nStocks to Sell\n7 F-Rated Consumer Discretionary Stocks to Ditch in December\nStocks to Sell\nAvoid NIO Stock: Here’s What to Expect From Apple Stock in 2024\nAAPL stock investors should temper their optimism with a healthy dose of skepticism\nAdvertisement\nSource: sylv1rob1 / Shutterstock.com\nAs a member of the “Magnificent Seven,” Apple\xa0(NASDAQ:AAPL) earned the market’s favor throughout 2023.\xa0 The Struggling EV Maker Is Grasping at Straws\nStocks to Sell\nThe Latest Bad News Is More Reason to Steer Clear of Lucid Stock\nStocks to Buy\nMETA Stock Outlook: Here's What Could Really Move the Needle for Meta Platforms\nHot Stocks\n According to The Wall Street Journal, Apple “and its suppliers aim to build over 50 million iPhones in India annually within the next two to three years,” followed by an “additional tens of millions of units after that.”\n Going forward, investors should keep tabs on Apple’s production costs to see if the company’s operational shifts have a positive long-term impact on Apple’s financials.\n",
   'score': 0.92592,
   'raw_content': None},
  {'title': '4 Things You Need to Know Before You Rush to Buy Apple Stock in 2024',
   'url': 'https://www.fool.com/investing/2024/01/21/4-things-to-know-before-rush-buy-apple-stock-2024/',
   'content': '4 Things You Need to Know Before You Rush to Buy Apple Stock in 2024 By Neil Patel - Jan 21, 2024 at 12:15PM Key Points More than half of its sales are from the iPhone, but revenue from...',
   'score': 0.90272,
   'raw_content': None}],
 'response_time': 1.39}
高度検索の結果
{'query': 'Should I invest in Apple in 2024?',
 'follow_up_questions': ['What are the latest financial reports of Apple?',
  'What are the projected future growth prospects for Apple?',
  'What are the risks associated with investing in Apple in 2024?'],
 'answer': None,
 'images': None,
 'results': [{'content': "Should you buy Apple stock in 2024?  buy Apple stock in 2024?  Should You Buy Apple Stock in 2024? Key Points NASDAQ: AAPL Apple  Why consider Apple stock?Collapse NASDAQ: AAPL Apple Today's Change (-0.17%) -$0.33 Current Price $194.17 Key Data Points Market Cap $3,002B Day's Range $193.11 - $196.27 52wk Range $141.32 - $199.62 Volume 55,550 Avg...",
   'url': 'https://www.fool.com/investing/2023/12/26/should-you-buy-apple-stock-in-2024/',
   'score': 0.92822,
   'title': 'Should You Buy Apple Stock in 2024? | The Motley Fool',
   'raw_content': None},
  {'content': 'Should you buy Apple stock in 2024?  buy Apple stock in 2024?  Should You Buy Apple Stock in 2024? was originally published by The Motley Fool Related Quotes TRENDING  Why consider Apple stock?U.S. markets closed Should You Buy Apple Stock in 2024? Keith Speights, The Motley Fool December 26, 2023 at 2:52 AM · 5 min read Apple iPhone - Getty Apple (NASDAQ: AAPL) is truly in a...',
   'url': 'https://finance.yahoo.com/news/buy-apple-stock-2024-105200222.html',
   'score': 0.92718,
   'title': 'Should You Buy Apple Stock in 2024? - Yahoo Finance',
   'raw_content': None},
  {'content': "How Will Apple (AAPL) Perform Over the Next Few Years?  AAPL Stock Returns for 2022  Before investing your money in Apple, here is what you should know about the company’s past performance and future  whether Apple is a solid investment choice depends upon your portfolio’s mix.Experts generally regard Apple as a blue chip stock —investments with proven histories of steady growth and returns. But in 2022, its stock price dropped from a high of $182.88 on the year's...",
   'url': 'https://www.forbes.com/advisor/investing/apple-stock-forecast/',
   'score': 0.86612,
   'title': 'Apple Stock Forecast - Forbes Advisor',
   'raw_content': None},
  {'content': 'Strengths Weaknesses What can we expect from Apple in 2024?  Investing Apple stock forecast and price prediction for 2023 Wayne Duggan Farran Powell  Apple is well positioned to continue outperforming but also faces several potential stumbling blocks ahead.  $5.72 in 2023. In addition, Apple analysts are calling for $382.24 billion in revenue in 2024, up 5.9% year over year.Apple stock forecast and price prediction for 2024 Wayne Duggan Farran Powell Farran Powell Verified by an expert "Verified by an expert" means that this article has been thoroughly reviewed...',
   'url': 'https://www.usatoday.com/money/blueprint/investing/stock-forecast-apple/',
   'score': 0.85916,
   'title': 'Apple stock forecast and price prediction for 2024 - USA TODAY',
   'raw_content': None},
  {'content': 'Get guidance Investing in Apple Stock in 2023 Advertiser Disclosure  2. Does Apple make sense in your portfolio?  Here’s what else you should know about investing in Apple and how to buy shares in the tech giant.  5. Buy Apple stockJuly 28, 2022: Apple releases its fiscal third-quarter financial results, showing record revenue of $83.0 billion and generating nearly $23 billion in operating cash flow. July 12, 2022: Apple TV+ ...',
   'url': 'https://www.bankrate.com/investing/how-to-buy-apple-stock/',
   'score': 0.85545,
   'title': 'Investing In Apple Stock In 2024 | Bankrate',
   'raw_content': None}],
 'response_time': 3.54}

日本語検索の結果

response = tavily.search(query="2024年にAppleに投資すべきでしょうか?")
{'query': '2024年にAppleに投資すべきでしょうか?',
 'follow_up_questions': None,
 'answer': None,
 'images': None,
 'results': [{'url': 'https://tw.news.yahoo.com/%E8%98%8B%E6%9E%9C2024-%E6%9C%80%E9%87%8D%E8%A6%81%E5%95%86%E5%93%81-%E6%98%AF%E5%AE%83-%E9%83%AD%E6%98%8E%E9%8C%A4%E6%9B%9D%E6%B6%88%E8%B2%BB%E9%9B%BB%E5%AD%903%E5%A4%A7%E6%8A%95%E8%B3%87%E8%B6%A8%E5%8B%A2-043517479.html',
   'title': '蘋果2024「最重要商品」是它!郭明錤曝消費電子3大投資趨勢',
   'content': 'Dec 25, 2023 — Dec 25, 2023... 入尾聲,有「最強蘋果分析師」之稱的天風國際證券分析師郭明錤預測2024年消費電子產業的「3大關鍵投資趨勢」,包括Android庫存回補、蘋果頭戴式裝.',
   'score': 0.96655,
   'raw_content': None},
  {'url': 'https://www.stcn.com/article/detail/1082996.html',
   'title': '如果失去创新力,2024年将是苹果的转折年',
   'content': 'Jan 4, 2024 — Jan 4, 2024苹果的投资价值,取决于它的长期增长和盈利能力。如果苹果失去了创新能力,那么它也将失去了长期增长和盈利能力。 2024年伊始,苹果就被市场看空\xa0...',
   'score': 0.95254,
   'raw_content': None},
  {'url': 'https://finance.sina.cn/usstock/mggd/2024-01-03/detail-inaaewnk4780227.d.html?vt=4',
   'title': '苹果2024年遭“当头一棒” 策略师发出卖出信号',
   'content': 'Jan 3, 2024 — Jan 3, 20242024美股第一个交易日,苹果(AAPL.US)股价创下去年至今最大单日跌幅之一,原因是投资者对接连不断的评级下调感到担忧。 智通财经APP了解到,以Tim\xa0...',
   'score': 0.91492,
   'raw_content': None},
  {'url': 'https://hk.finance.yahoo.com/news/%E8%98%8B%E6%9E%9C%E5%85%AC%E5%8F%B82023%E5%B9%B4%E5%B8%82%E5%80%BC%E6%9A%B4%E5%A2%9E%E8%BF%91%E8%90%AC%E5%84%84%E7%BE%8E%E5%85%83-2024%E5%B9%B4%E5%86%8D%E7%BA%8C%E8%BC%9D%E7%85%8C%E6%9C%89%E9%BB%9E%E9%9B%A3-140206865.html',
   'title': '蘋果公司2023年市值暴增近萬億美元2024年再續輝煌有點難',
   'content': 'Dec 21, 2023 — Dec 21, 2023【彭博】-- 蘋果公司今年的市值增加了近1萬億美元,如此暴增2024年將難以重演。這家全球市值最高的公司正在努力止住收入連續四個季度下滑的局面,\xa0...',
   'score': 0.91072,
   'raw_content': None}],
 'response_time': 5.11}
response = tavily.search(query="2024年にAppleに投資すべきでしょうか?", search_depth="advanced")
{'query': '2024年にAppleに投資すべきでしょうか?',
 'follow_up_questions': ['What are the projected earnings for Apple in 2024?',
  'What are the potential risks of investing in Apple in 2024?',
  'Are there any other tech companies that are recommended for investment in 2024?'],
 'answer': None,
 'images': None,
 'results': [{'content': "Should you buy Apple stock in 2024?  buy Apple stock in 2024?  Should You Buy Apple Stock in 2024? Key Points NASDAQ: AAPL Apple  Why consider Apple stock?Collapse NASDAQ: AAPL Apple Today's Change (-0.17%) -$0.33 Current Price $194.17 Key Data Points Market Cap $3,002B Day's Range $193.11 - $196.27 52wk Range $141.32 - $199.62 Volume 55,550 Avg...",
   'url': 'https://www.fool.com/investing/2023/12/26/should-you-buy-apple-stock-in-2024/',
   'score': 0.92822,
   'title': 'Should You Buy Apple Stock in 2024? | The Motley Fool',
   'raw_content': None},
  {'content': 'Should you buy Apple stock in 2024?  buy Apple stock in 2024?  Should You Buy Apple Stock in 2024? was originally published by The Motley Fool Related Quotes TRENDING  Why consider Apple stock?U.S. markets closed Should You Buy Apple Stock in 2024? Keith Speights, The Motley Fool December 26, 2023 at 2:52 AM · 5 min read Apple iPhone - Getty Apple (NASDAQ: AAPL) is truly in a...',
   'url': 'https://finance.yahoo.com/news/buy-apple-stock-2024-105200222.html',
   'score': 0.92718,
   'title': 'Should You Buy Apple Stock in 2024? - Yahoo Finance',
   'raw_content': None},
  {'content': "Here’s What to Expect From Apple Stock in 2024  Hot Stocks Here's What to Expect From Apple Stock in 2024  Media, https://investorplace.com/market360/2023/12/heres-what-to-expect-from-apple-stock-in-2024/.  2023.\xa0However, this doesn’t guarantee similar results for Apple’s investors in 2024. Overall, the outlook for\xa0AAPLHere's What to Expect From Apple Stock in 2024 AAPL stock investors should temper their optimism with a healthy dose of skepticism By Louis Navellier and the InvestorPlace Research Staff Dec...",
   'url': 'https://investorplace.com/market360/2023/12/heres-what-to-expect-from-apple-stock-in-2024/',
   'score': 0.87244,
   'title': "Here's What to Expect From Apple Stock in 2024 | InvestorPlace",
   'raw_content': None},
  {'content': "How Will Apple (AAPL) Perform Over the Next Few Years?  AAPL Stock Returns for 2022  Before investing your money in Apple, here is what you should know about the company’s past performance and future  whether Apple is a solid investment choice depends upon your portfolio’s mix.Before investing your money in Apple, here is what you should know about the company's past performance and future prospects. ... Apple earnings per share are seen rising 10.60% in fiscal 2024 ...",
   'url': 'https://www.forbes.com/advisor/investing/apple-stock-forecast/',
   'score': 0.86612,
   'title': 'Apple Stock Forecast - Forbes Advisor',
   'raw_content': None},
  {'content': 'Strengths Weaknesses What can we expect from Apple in 2024?  Investing Apple stock forecast and price prediction for 2023 Wayne Duggan Farran Powell  Apple is well positioned to continue outperforming but also faces several potential stumbling blocks ahead.  $5.72 in 2023. In addition, Apple analysts are calling for $382.24 billion in revenue in 2024, up 5.9% year over year.Apple stock forecast and price prediction for 2024 Wayne Duggan Farran Powell Farran Powell Verified by an expert "Verified by an expert" means that this article has been thoroughly reviewed...',
   'url': 'https://www.usatoday.com/money/blueprint/investing/stock-forecast-apple/',
   'score': 0.85916,
   'title': 'Apple stock forecast and price prediction for 2024 - USA TODAY',
   'raw_content': None}],
 'response_time': 3.31}

トカマクラブ版検索の結果

# 基本検索の例
response = tavily.search(query="トカマクラブとは?")
response
{'query': 'トカマクラブとは?',
 'follow_up_questions': None,
 'answer': None,
 'images': None,
 'results': [{'url': 'https://dic.nicovideo.jp/a/%E3%83%88%E3%82%AB%E3%83%9E%E3%83%BB%E3%82%AF%E3%83%A9%E3%83%96',
   'title': 'トカマ・クラブとは (トカマクラブとは) [単語記事]',
   'content': 'Dec 29, 2009 — Dec 29, 2009トカマ・クラブとは、「東方M-1ぐらんぷり」における漫才コンビの1つである。 第4回大会と第6回大会の2つに出場した経験がある。',
   'score': 0.97825,
   'raw_content': None},
  {'url': 'https://www.nicovideo.jp/tag/%E3%83%88%E3%82%AB%E3%83%9E%E3%82%AF%E3%83%A9%E3%83%96',
   'title': '人気の「トカマクラブ」動画 9本',
   'content': '「トカマクラブ」動画 9本 - 「トカマクラブ」で人気の動画を検索できます。たくさんの動画にコメントを付けて楽しみましょう。',
   'score': 0.9637,
   'raw_content': None},
  {'url': 'https://twitter.com/Ran__T/status/1284429049448681472',
   'title': 'らんてぃ',
   'content': '第6回東方M-1ぐらんぷり『トカマクラブ』結婚挨拶をアップしました! https://t.co/NWJDMUikul #東方M1ぐらんぷり.',
   'score': 0.93912,
   'raw_content': None}],
 'response_time': 3.34}
# 高度検索の例
response = tavily.search(query="トカマクラブとは?", search_depth="advanced")
response
{'query': 'トカマクラブとは?',
 'follow_up_questions': ['トカマクラブの活動内容は?',
  'トカマクラブの歴史は?',
  'トカマクラブのメンバーシップにはどのような要件がある?'],
 'answer': None,
 'images': None,
 'results': [{'content': 'トカマクラブ タグを含む動画 : 9件 ログインするとこのタグをフォローできます 「トカマクラブ」の記事はまだ書かれていません記事を書く 関連タグ トカマクラブ を含むタグ一覧 並び替え 再生時間 投稿日時 ジャンル 検索ヘルプ  関連するコミュニティはありません トカマクラブに関するコミュニティが件見つかりました 動画: フォロワー数: レベル: 動画: フォロワー数: レベル: 動画: フォロワー数: レベル: コミュニティを開設してみませんか?  関連チャンネル 関連するチャンネルはありません トカマクラブに関するチャンネルが件見つかりました 他のチャンネルを探してみませんか? 全ての関連チャンネルを見る 関連コミュニティ 関連するコミュニティはありません  【theme:家】「クラブ地霊殿」と書いて「クラブナイトメア」と読む。大層な言い方をしているが、実家である。mylist/18187820MMD杯公式サイト=http://mmdcup.org/公式...「トカマクラブ」動画 9本 - 「トカマクラブ」で人気の動画を検索できます。たくさんの動画にコメントを付けて楽しみましょう。',
   'url': 'https://www.nicovideo.jp/tag/%E3%83%88%E3%82%AB%E3%83%9E%E3%82%AF%E3%83%A9%E3%83%96',
   'score': 0.84771,
   'title': '人気の「トカマクラブ」動画 9本',
   'raw_content': None}],
 'response_time': 8.12}

Fate/Apocrypha版検索の結果

# 基本検索の例
response = tavily.search(query="Fate/Apocryphaとは?")
response
{'query': 'Fate/Apocryphaとは?',
 'follow_up_questions': None,
 'answer': None,
 'images': None,
 'results': [{'title': 'Fate/Apocryphaとは (フェイトアポクリファとは) [単語記事] - ニコニコ大百科',
   'url': 'https://dic.nicovideo.jp/a/fate/apocrypha',
   'content': 'Fate/Apocryphaとは、 TYPE-MOON の作品「 Fate/stay night 」を 原作 として 企画 された作品である。 概要 元々は 聖杯戦争 を 舞台 とした オンラインゲーム として 企画 されたものだったが、諸事情により 企画 自体がボツとなり、 残念 ながらFate/Apocryphaという作品は お蔵入り することになる。 しかしその後、「 Fate / complete material IV Extra material 」に サーヴァント の イラスト や設定等が、 奈須きのこ と 武内崇 の インタビュー 記事とともに 公 開された。',
   'score': 0.97068,
   'raw_content': None},
  {'title': 'Fate/Apocrypha - Wikipedia',
   'url': 'https://ja.wikipedia.org/wiki/Fate/Apocrypha',
   'content': '『 Fate/Apocrypha 』(フェイト・アポクリファ)は、 TYPE-MOON 作のビジュアルノベルゲーム『 Fate/stay night 』のスピンアウト 小説 。 著者は 東出祐一郎 、イラストは 近衛乙嗣 [注 1] 。 TYPE-MOON BOOKSより2012年12月31日から2014年12月30日まで全5巻が刊行された。 概要 [ 編集] 武内崇 によると、元々は『 Fate/EXTRA 』と同時期に、『 三国志大戦 』のような色々な英雄を複数の作家に描いてもらうところからスタートしたものの、諸般の事情で頓挫してしまった オンラインゲーム の企画を小説作品としてリメイクしたものである。',
   'score': 0.96062,
   'raw_content': None},
  {'title': 'TVアニメ「Fate/Apocrypha」公式サイト',
   'url': 'https://fate-apocrypha.com/',
   'content': '各配信プラットフォームにて本編配信スタート!. 「Fate/Apocrypha Original Soundtrack」山田有慶描き下ろしジャケットイラストを公開!. このWebサイトに記載されている一切の文言・図版・写真を、手段や形態を問わず、複製、転載することを禁じます。. 「Fate ...',
   'score': 0.95491,
   'raw_content': None},
  {'title': 'Fate/Apocrypha (ふぇいとあぽくりふぁ)とは【ピクシブ百科事典】',
   'url': 'https://dic.pixiv.net/a/Fate/Apocrypha',
   'content': '『Fate/Apocrypha』とは、Fateシリーズのひとつである聖杯大戦を描いた小説。 pixivで「Fate/Apocrypha」のイラストを見る pixivで「Fate/Apocrypha」の小説を読む pixivで「Fate/Apocrypha」のイラストを投稿する pixivで「Fate/Apocrypha」の小説を投稿する 目次 [ 非表示 ] 1 概要 1.1 小説版発売までの経緯 2 ストーリー 3 登場キャラクター 3.1 ルーラー陣営 3.2 黒陣営 3.2.1 サーヴァント 3.2.2 マスター 3.3 赤陣営 3.3.1 サーヴァント 3.3.2 マスター 3.4 魔術協会 3.5 ユグドミレニア 3.6 その他 3.6.1 過去の人物',
   'score': 0.9505,
   'raw_content': None},
  {'title': 'Fate/Apocrypha | TYPE-MOON Wiki | Fandom',
   'url': 'https://typemoon.fandom.com/wiki/Fate/Apocrypha',
   'content': 'Novel Promotion Poster, featuring Ruler, Saber of Black and Assassin of Red.. The setting of Fate/Apocrypha is a parallel world to Fate/stay night and its prequel Fate/Zero where the Greater Grail was removed from Fuyuki after the Third Holy Grail War and disappeared for many years. Around the 2000s, around the same time as the Fifth Holy Grail War would have happened, the group that plundered ...',
   'score': 0.93087,
   'raw_content': None}],
 'response_time': 0.89}
# 高度検索の例
response = tavily.search(query="Fate/Apocryphaとは?", search_depth="advanced")
response
{'query': 'Fate/Apocryphaとは?',
 'follow_up_questions': ['What are the main characters in Fate/Apocrypha?',
  'What is the plot of Fate/Apocrypha?',
  'Is there a sequel to Fate/Apocrypha?'],
 'answer': None,
 'images': None,
 'results': [],
 'response_time': 6.61}

さらに、アプリケーションのユースケースに応じて、以下のような強力なメソッドも使用できます。

  • RAGに直接検索結果のコンテキストを取得することができます。
  • 最大トークン数内でコンテキストを文字列として取得できます。

tavily.get_search_context(query="What happened in the burning man floods?", search_depth="advanced", max_tokens=1500)

QNA Search

  • 簡単な関数呼び出しで、質問へのシンプルな回答と関連ソースを取得することも可能です。

tavily.qna_search(query="Where does Messi play right now?")

Lionel Messi currently plays for Inter Miami CF in the MLS (Major League Soccer). He joined the team after his contract with PSG expired in the summer. Inter Miami CF will begin their regular season on February 21, 2024, with a home match against an opponent yet to be determined. Messi and Inter Miami CF will visit various cities across the United States as part of their 2024 MLS schedule, including a marquee showdown at the LA Galaxy.

リオネル・メッシは現在、MLS(メジャーリーグサッカー)のインテル・マイアミCFでプレーしている。夏にPSGとの契約が満了した後、チームに加入した。インテル・マイアミCFは2024年2月21日にレギュラーシーズンを開始し、ホームでの対戦相手は未定。メッシとインテル・マイアミCFは、LAギャラクシーでの有力対決を含む2024年のMLSスケジュールの一環として、全米のさまざまな都市を訪問する予定だ。



tavily.qna_search(query="トカマクラブとは?")

トカマクラブは、「東方M-1ぐらんぷり」における漫才コンビの1つです。第4回大会と第6回大会の2つに出場した経験があります。具体的なメンバー名は提供されていません。



tavily.qna_search(query="Fate/Apocryphaとは?")

"Fate/Apocrypha" is a spin-off novel of the visual novel game "Fate/stay night" created by TYPE-MOON. The novel is written by Yūichirō Higashide and illustrated by Ototsugu Konoe. It was published in Japan by TYPE-MOON BOOKS from December 31, 2012, to December 30, 2014. The story of "Fate/Apocrypha" takes place in an alternate timeline from "Fate/stay night" and features a variation of the Holy Grail War known as the Great Holy Grail War.

『Fate/Apocrypha』は、TYPE-MOON制作のビジュアルノベルゲーム『Fate/stay night』のスピンオフノベルです。この小説は東出祐一郎によって書かれ、近衛音継によってイラストが描かれています。日本では、TYPE-MOON BOOKSより2012年12月31日から2014年12月30日まで刊行された。『Fate/Apocrypha』の物語は、『Fate/stay night』とは別の時間軸で展開され、聖杯戦争、通称聖杯戦争。

📚 APIメソッド

Clientクラス

Clientクラスは、Tavily APIとのやり取りの入り口です。APIキーを使ってインスタンスを生成し、旅を始めましょう。

メソッド

  • search(query, **kwargs):
    • 検索深度は「basic」または「advanced」が選べます。基本タイプは迅速な応答を、高度タイプは詳細で品質の高い結果を提供します。
    • 追加のパラメータはキーワード引数として提供できます。
    • 関連するすべての応答フィールドを含むJSONを返します。
  • get_search_context(query, search_depth [任意], max_tokens [任意], **kwargs):
    • 検索を実行し、トークン制限内のコンテンツとソースの文字列を返します。
    • 関連コンテンツのみを取得するのに便利です。
    • 最大トークン数はデフォルトで4,000です。検索深度はデフォルトで基本です。
  • qna_search(query, search_depth [任意], **kwargs):
    • 検索を実行し、元のクエリに対する回答と関連ソースを含む文字列を返します。
    • AIエージェントのツールとして最適です。
    • 検索深度はデフォルトで高度です。

🖊️ キーワード引数

  • search_depth (str): 検索の深さ。"basic"または"advanced"が選べます。デフォルトは"basic"です。
  • max_results (int): 返す最大検索結果数。デフォルトは5です。
  • include_images (bool): クエリに関連する画像のリストを応答に含めます。デフォルトはFalseです。
  • include_answer (bool): 検索結果に元のクエリへの短い回答を含めます。デフォルトはFalseです。
  • include_raw_content (bool): 各サイト検索結果のクリーンで解析されたHTMLを含めます。デフォルトはFalseです。
  • include_domains (list): 検索結果に特に含めるドメインのリスト。デフォルトはNoneで、すべてのドメインが含まれます。
  • exclude_domains (list): 検索結果から特に除外するドメインのリスト。デフォルトはNoneで、どのドメインも除外されません。

Langchainとの連携

より詳しい情報はLangchainのブログをご覧ください。

Building (and Breaking) WebLangChain
Important Links: * Hosted WebLangChain * Open-source code for WebLangChainIntroductionOne of the big shortcomings of LLMs is that they can only answer questions...

これにより、Tavily APIは、リアルタイムのオンライン情報をLangchainアプリケーションに最適化して提供できるようになりました。RAG(検索強化生成)に対応することで、より効果的な結果を得ることが可能です。

Tavily APIをLangchainで使う方法

Tavily APIとLangchainの連携は、以下の手順で簡単に設定できます。

まず、LangchainのTavily Search APIラッパーをインポートし、Langchainエージェントを初期化します。

import os
from langchain.utilities.tavily_search import TavilySearchAPIWrapper
from langchain.agents import initialize_agent, AgentType
from langchain.chat_models import ChatOpenAI
from langchain.tools.tavily_search import TavilySearchResults

# エージェントの設定
llm = ChatOpenAI(model_name="gpt-4", temperature=0.7)
search = TavilySearchAPIWrapper()
tavily_tool = TavilySearchResults(api_wrapper=search)

# エージェントの初期化
agent_chain = initialize_agent(
    [tavily_tool],
    llm,
    agent=AgentType.STRUCTURED_CHAT_ZERO_SHOT_REACT_DESCRIPTION,
    verbose=True,
)

# エージェントの実行
agent_chain.run(
    "トカマクラブのメンバーは誰?",
)

> Entering new AgentExecutor chain...
この質問に関しては、特定の情報が必要です。"トカマクラブ"という名前の団体、バンド、クラブなどを私が検索することで答えを見つけることができます。
Action:

{
  "action": "tavily_search_results_json",
  "action_input": {
    "query": "トカマクラブ メンバー"
  }
}

Observation: [{'url': 'https://www.digicert.com/kb/digicert-root-certificates.htm', 'content': 'MPKI-footer Contact a PKI Specialist 1.801.701.9600 Panasonic Trusts DigiCert for IoT Solutions Submenu Footer – IoT  Additional Information  +44.203.788.7741 Account Login  Identity on the brink Submenu Footer – Buttons BuyRenewCOMPAREWHAT ARE SSL, TLS & HTTPS? It’s time to redefine PKIDigiCert root certificates are widely trusted and used for issuing TLS Certificates to DigiCert customers—including educational, financial institutions,\xa0...'}, {'url': 'https://community.jmp.com/t5/Discussions/Error-importing-Excel-97-2003-files/td-p/231280/lang/code/ja-JP', 'content': "JMP Alert window:  Thanks!, DS  it afterall, but we can't track down what that problem is.  Issues: 1) I can't go in an re-save the file to a new format, have to use the existing one; 2) the format is 92-2003Dear JMP Community, (Windows 10 Enterprise, 64-bit, JMP 14.0.0 and JMP Pro 14.1.0.) I have hundreds of Excel files that I need to import into JMP."}]
Thought:The search results do not seem to provide any information about "トカマクラブ" or its members. It's possible that the search engine is not providing relevant results due to language or regional differences. Let's try adding more context to the search query to see if we can return more relevant results.
Action:

{
  "action": "tavily_search_results_json",
  "action_input": {
    "query": "トカマクラブ メンバー バンド"
  }
}

Observation: []
Thought:The search results are still not providing any information about "トカマクラブ" or its members. It's possible that this group or band is not well-known or does not have much presence online. At this point, I'm unable to provide the requested information based on the available search results. I'll let the user know that I'm unable to find this information at the moment.
Action:

{
  "action": "Final Answer",
  "action_input": "申し訳ありませんが、'トカマクラブ'やそのメンバーについての情報を見つけることができませんでした。このグループやバンドがあまり知られていない、またはオンライン上にあまり情報がない可能性があります。他にご質問がありましたら、お知らせください。"
}

> Finished chain.
申し訳ありませんが、'トカマクラブ'やそのメンバーについての情報を見つけることができませんでした。このグループやバンドがあまり知られていない、またはオンライン上にあまり情報がない可能性があります。他にご質問がありましたら、お知らせください。

# エージェントの実行
agent_chain.run(
    "Fate/Apocryphaとは?",
)

> Entering new AgentExecutor chain...
"Fate/Apocrypha"は一体何でしょうか、という質問に対して、私はすでにその情報を持っていると思います。それは人気のあるアニメとライトノベルシリーズで、Fateステイナイトという元のシリーズから派生したものです。しかし、最新かつ詳細な情報を提供するために、検索エンジンを利用して確認します。

Action:

{
  "action": "tavily_search_results_json",
  "action_input": {
    "query": "Fate/Apocrypha"
  }
}

Observation: [{'url': 'https://www.siliconera.com/fate-grand-order-apocrypha-rerun-event-begins-inheritance-of-glory/', 'content': 'March 23, 2022. The\xa0Fate/Apocrypha anime series can be viewed on Netflix.  Fate/Grand Order Apocrypha Rerun Event Begins  Fate/Grand Order is available on Android and iOS. The\xa0Fate/Apocrypha\xa0crossover runs until March 23, 2022.  The Fate/Grand Order\xa0Apocrypha rerun begins on March 10, 2022 and continues through March 23, 2022.The Fate/Grand Order Apocrypha rerun begins on March 10, 2022 and continues through March 23, 2022. Check out an animated promo for the event. Inheritance of Glory is based on Fate/Apocrypha , a ...'}, {'url': 'https://typemoon.fandom.com/wiki/Fate/Apocrypha', 'content': 'Fate/Apocrypha Fate/Apocrypha Information Title Author Illustrator Japanese publisher Original run Contents Story[]  The setting of Fate/Apocrypha is a parallel world to Fate/stay night  transition from the proto-version of Apocrypha featured in Fate/complete material IV to the official light novels.[5]  novella epilogue following Astolfo interviewing the survivors of the Great Holy Grail War, released on March 28,Fate/Apocrypha (フェイト/アポクリファ, Feito/Apokurifa?) is a light novel written by Yuuichirou Higashide with illustrations by Ototsugu Konoe and supervised by Kinoko Nasu who planned and wrote majority of the story elements for Apocrypha characters and the plot. The first volume was released on December 29, 2012 at Comiket 83.'}, {'url': 'https://gamerant.com/fate-series-understanding-different-timelines-alternate-universes/', 'content': 'Fate/Apocrypha’s Parallel World  The Fate/stay Night Timelines  Though Apocrypha might have the Fate prefix attached, it serves as its own standalone story. It’s one of many Nasuverse  The Alternate Fate/kaleid liner Prisma Illya TimelineThe Fate/Apocrypha light novel takes place in a parallel world, focusing on an entirely new set of characters with little to nothing to do with the main stay night narrative.In Apocrypha the ...'}, {'url': 'https://en.wikipedia.org/wiki/Fate/Apocrypha', 'content': "Contents Fate/Apocrypha  Fate/Apocrypha takes place in an alternate timeline from Fate/stay night. In the Third Holy Grail War that happened  Fate/Apocrypha is written by Yūichirō Higashide and illustrated by Ototsugu Konoe. Fate/Apocrypha was originally  Fate/Apocrypha is a Japanese light novel series in Type-Moon's Fate franchise, written by Yūichirō Higashide andFate/Apocrypha is a Japanese light novel series in Type-Moon 's Fate franchise, written by Yūichirō Higashide and illustrated by Ototsugu Konoe. Type-Moon published five volumes from December 2012 to December 2014. A manga adaptation illustrated by Akira Ishida is serialized in Kadokawa Shoten 's Comp Ace magazine."}, {'url': 'https://www.thepopverse.com/fate-anime-watch-order-how-to-stay-night-grand-order-chronological-release', 'content': "Fate/EXTRA and Fate/Apocrypha are available on Netflix. If you want to watch these N Series you can sign-up to Netflix  as a prequel to the second arc of Fate/Grand Order.  get into the Fate universe is to go back to where it all started with Fate/stay night.  recent Fate anime. There's also the comedy spinoff shows Carnival Phantasm and Fate/Grand Carnival.Crunchyroll has a number of Fate boxsets in its library, including Fate/stay night: Unlimited Blade Works, Fate/Zero, and a number of Fate/Grand Order titles. To watch these boxsets, you will need to sign up to a Crunchyroll Premium plan which is priced from $7.99. Fate/EXTRA and Fate/Apocrypha are available on Netflix."}]
Thought:The search results provide a good amount of information about Fate/Apocrypha. It is a light novel series written by Yuuichirou Higashide with illustrations by Ototsugu Konoe. It is part of the Fate franchise from Type-Moon. The setting of Fate/Apocrypha is a parallel world to Fate/stay night and it serves as its own standalone story focusing on an entirely new set of characters. The anime series can be viewed on Netflix.

Action:

{
  "action": "Final Answer",
  "action_input": "Fate/ApocryphaはType-MoonのFateフランチャイズの一部で、著者はYuuichirou Higashide、イラストはOtotsugu Konoeによるライトノベルシリーズです。Fate/Apocryphaの舞台はFate/stay nightとは平行世界で、全く新しいキャラクターセットに焦点を当てた独自の物語として機能します。アニメシリーズはNetflixで視聴することができます。"
}

> Finished chain.
Fate/ApocryphaはType-MoonのFateフランチャイズの一部で、著者はYuuichirou Higashide、イラストはOtotsugu Konoeによるライトノベルシリーズです。Fate/Apocryphaの舞台はFate/stay nightとは平行世界で、全く新しいキャラクターセットに焦点を当てた独自の物語として機能します。アニメシリーズはNetflixで視聴することができます。

このコードを使用することで、LangchainエージェントはTavily APIを介して情報を検索し、ユーザーの問いに対してリアルタイムで反応できるようになります。例えば、「トカマクラブのメンバーは誰?」という質問に対して、関連する最新情報を提供することが可能です。

結果の取得

上記のスクリプトを実行すると、LangchainエージェントはTavily APIを使用して、質問に関連する情報を検索し、適切な回答を生成します。この連携により、Langchainを使用する開発者は、そのアプリケーションに深い知識と情報を提供することができます。

これで、日本語版Tavily APIの完全ガイドを終わります。

ノートブック

Python SDK

Google Colaboratory

LangChain

Google Colaboratory

コメント

タイトルとURLをコピーしました