Skip to content

docs: Correct generation_types.GenerateContentResponse documentation #140

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

Merged
merged 1 commit into from
Dec 19, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions google/generativeai/types/generation_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -351,27 +351,27 @@ def rewrite_stream_error():
)


GENERATE_CONTENT_RESPONSE_DOC = """Instances of this class manage the response of the `generate_content_async` method.
GENERATE_CONTENT_RESPONSE_DOC = """Instances of this class manage the response of the `generate_content` method.

These are returned by `GenerativeModel.generate_content_async` and `ChatSession.send_message_async`.
These are returned by `GenerativeModel.generate_content` and `ChatSession.send_message`.
This object is based on the low level `glm.GenerateContentResponse` class which just has `prompt_feedback`
and `candidates` attributes. This class adds several quick accessors for common use cases.

The same object type is returned for both `stream=True/False`.

### Streaming

When you pass `stream=True` to `GenerativeModel.generate_content_async` or `ChatSession.send_message_async`,
When you pass `stream=True` to `GenerativeModel.generate_content` or `ChatSession.send_message`,
iterate over this object to receive chunks of the response:

```
response = model.generate_content_async(..., stream=True):
async for chunk in response:
response = model.generate_content(..., stream=True):
for chunk in response:
print(chunk.text)
```

`AsyncGenerateContentResponse.prompt_feedback` is available immediately but
`AsyncGenerateContentResponse.candidates`, and all the attributes derived from them (`.text`, `.parts`),
`GenerateContentResponse.prompt_feedback` is available immediately but
`GenerateContentResponse.candidates`, and all the attributes derived from them (`.text`, `.parts`),
are only available after the iteration is complete.
"""

Expand Down