0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

LangChain(Vertex AI Gemini-2.5モデル)の回答生成に失敗する

Last updated at Posted at 2025-06-25

はじめに

LangChainを用いた生成AIのサービスを開発していて、Gemini 1.5から2.5へバージョンアップしたところ、回答が空で返ってくる不具合が発生し対処したので備忘録として残します。

やったこと

max_output_tokensを除外したら動くようになりました。

from langchain_google_vertexai import VertexAI

llm = VertexAI(
    model_name="gemini-2.5-flash",
-   max_output_tokens=1000
)

おそらく2.5特有の思考プロセスが原因だと思われるので、
他の対処法として、上限値を多めに設定する、思考を切るなどが考えられます。

from langchain_google_vertexai import VertexAI

llm = VertexAI(
    model_name="gemini-2.5-flash",
+   max_output_tokens=4096
)
from langchain_google_vertexai import VertexAI

llm = VertexAI(
    model_name="gemini-2.5-flash",  
    max_output_tokens=1000,
+   thinking_budget=0
)

以上になります。

さいごに

誰かの参考になれば幸いです。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?