Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Timeout configuration not respected by ChatGoogleGenerativeAI #731

Open
davidvesp opened this issue Feb 12, 2025 · 0 comments
Open

Timeout configuration not respected by ChatGoogleGenerativeAI #731

davidvesp opened this issue Feb 12, 2025 · 0 comments

Comments

@davidvesp
Copy link

If you execute the following code:

from langchain_google_genai import GoogleGenerativeAI
llm = 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:

from langchain_google_genai import ChatGoogleGenerativeAI
llm = 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:

import os
import google.generativeai as genai

genai.configure(api_key="")

# Create the model
generation_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
@langcarl langcarl bot added the investigate label Feb 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant