Call Gemini to Generate an Answer
Exit

Call Gemini to Generate an Answer

Send the prompt to Gemini Flash and return the response text

💻

Writing code and entering commands is only available on desktop. Open this page on a larger screen to complete this chapter.

The generation API call

Use client.models.generate_content() with your model name and prompt.

response = client.models.generate_content(
    model="gemini-2.5-flash",
    contents=prompt
)
return response.text

gemini-2.5-flash is fast and available on the free tier. It is well-suited for document Q&A tasks.

Instructions

Complete the generate_answer function. The starter code provides the signature.

  1. Create a variable named response. Assign it client.models.generate_content(model="gemini-2.5-flash", contents=prompt).
  2. Return response.text.