はじめに
必ず、かの邪智暴虐の1
( ゚д゚)ハッ!
気を取り直して素振り、いってみたいと思います。
目次
- はじめに
- 目次
- ChatGPT search
- Web search(を含むtool)のlaunch
- Web search する Chat completions のサンプルスクリプト
- 今回触りきれていない点(Future works)
- 終わりに
ChatGPT search
私は完全に見逃していたのですが、ChatGPTはWebを検索できます(deep researchまではいかない検索です)。
🌐 Introducing ChatGPT search 🌐
— OpenAI (@OpenAI) 2024年10月31日
ChatGPT can now search the web in a much better way than before so you get fast, timely answers with links to relevant web sources.https://t.co/7yilNgqH9T pic.twitter.com/z8mJWS8J9c
The search model is a fine-tuned version of GPT‑4o, post-trained using novel synthetic data generation techniques, including distilling outputs from OpenAI o1‑preview.
これがWeb APIとしてこのたび提供されたと認識しました。
Web search(を含むtool)のlaunch
このたびlaunchされました!
We're launching new tools to help developers build reliable and powerful AI agents. 🤖🔧
— OpenAI Developers (@OpenAIDevs) 2025年3月11日
Timestamps:
01:54 Web search
02:41 File search
03:22 Computer use
04:07 Responses API
10:17 Agents SDK pic.twitter.com/vY514tdmDz
Web search toolは、既存のChat Completions APIでも、このたび追加されたResponses APIでも使えます。
今回はChat Completions APIで使いました。
Chat Completions APIでWeb searchをするとき、指定するモデルは以下2つのどちらかとありました。
- gpt-4o-search-preview
- https://platform.openai.com/docs/models/gpt-4o-search-preview
- 入力 2.5$/1Mトークン
- 出力 10$/1Mトークン
- gpt-4o-mini-search-preview
- https://platform.openai.com/docs/models/gpt-4o-mini-search-preview
- 入力 0.15$/1Mトークン
- 出力 0.6$/1Mトークン
Web search する Chat completions のサンプルスクリプト
- 上述のモデルの指定
web_search_options- User location
- 日本と指定
countryはISO 3166-1のAlpha-2 codetimezoneはIANA timezone2- フリーテキストで
cityとregionも指定できるが、今回は省略
- Search context size
- デフォルトの
medium指定で highにするとcontextが大きくゆえに時間がかかるようになり、lowにするとcontextは小さくゆえに速くなる
- デフォルトの
- User location
環境変数OPENAI_API_KEYを設定して実行しています。
uv run web_search.py
レスポンス
(annotationsのURLは本文と同じなので、省略します)
outputが1.5Kトークンあり、0.03$消費しています
Brave SearchのMCPと同じ質問をしたのですが、
(聖地巡礼コース紹介のサイトではなく)Google mapのURLが並ぶという、全然異なる体験となりました。
裏側でどんな検索をしたらこんなレスポンスを返せるんでしょう?(聖地の一覧を得ていそうですが、それは最終出力にはないですね)
今回触りきれていない点(Future works)
Web search toolはResponses APIからも使えます!
https://platform.openai.com/docs/guides/tools-web-search?api-mode=responses&lang=python
Responses APIでは、gpt-4oにweb_search_previewというツールを渡すようです。
またChat completionsと違って、複数のツールを渡せるように思われます。
Responses APIと同時に発表されたopenai-agentsからも使えますね。
https://openai.github.io/openai-agents-python/tools/#hosted-tools
簡単なコードで済むようです
agent = Agent(
name="Assistant",
tools=[
WebSearchTool(),
],
)
終わりに
ChatGPTのWeb UIで使えるWeb searchをAPIからも使いました。
Web search toolを使う専用のモデルを指定して、Chat Completionsします。
(N=1の偏りも全然ありえますが)検索エンジンによる結果とは全然異なる体験をしました