I’m just getting started here.
I generated the key form AI Studio and typed in a question at the prompt (the Monty Hall problem). Got an answer. Then clicked on “Get SDK Code”. This gave me Python code. So far, so good.
But, the generated code is:
def generate():
client = genai.Client(
api_key=os.environ.get("GEMINI_API_KEY"),
)
model = "gemini-2.0-flash-lite"
contents = [
types.Content(
role="user",
parts=[
types.Part.from_text(text="""There is a game show where there are three closed doors. <snip>
"""),
],
),
types.Content(
role="model",
parts=[
types.Part.from_text(text="""The best choice is to **swap doors**. Here's why: <snip>
"""),
],
),
types.Content(
role="user",
parts=[
types.Part.from_text(text="""INSERT_INPUT_HERE"""),
],
),
]
generate_content_config = types.GenerateContentConfig(
)
for chunk in client.models.generate_content_stream(
model=model,
contents=contents,
config=generate_content_config,
):
print(chunk.text, end="")
The second types.Content element contains the answer. Why? Isn’t there supposed to be a requests.get(url) call to fetch the answer using a REST call? Is the client.models.generate_content_stream() call meant for the actual fetch?
What is the third types.Content doing? Seems to be empty.