You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fromlangchain_google_genaiimportGoogleGenerativeAIllm=GoogleGenerativeAI(model="gemini-2.0-flash", temperature=0.2, timeout=1, max_retries=1)
print(llm.invoke("Tell me a story in 1000 words."))
It fails with the expected output:
DeadlineExceeded
But if you use the following code:
fromlangchain_google_genaiimportChatGoogleGenerativeAIllm=ChatGoogleGenerativeAI(model="gemini-2.0-flash", temperature=0.2, timeout=1, max_retries=0)
print(llm.invoke("Tell me a story in 1000 words."))
It ends ok (we want to set the timeout to fail fast).
I tried using the native Google library and it respects the timeout config:
importosimportgoogle.generativeaiasgenaigenai.configure(api_key="")
# Create the modelgeneration_config= {
"temperature": 0.7,
"top_p": 0.95,
"top_k": 64,
"max_output_tokens": 65536,
"response_mime_type": "text/plain",
}
model=genai.GenerativeModel(
model_name="gemini-2.0-flash",
generation_config=generation_config,
)
chat_session=model.start_chat(
history=[
]
)
response=chat_session.send_message("tell me a story in 1000 words", request_options={"timeout": 3})
print(response.text)
Output:
DeadlineExceeded
The text was updated successfully, but these errors were encountered:
If you execute the following code:
It fails with the expected output:
But if you use the following code:
It ends ok (we want to set the timeout to fail fast).
I tried using the native Google library and it respects the timeout config:
Output:
The text was updated successfully, but these errors were encountered: