View source on GitHub |
A chat response from the model.
- Use
response.last
(settable) for easy access to the text of the last response. (messages[-1]['content']
) - Use
response.messages
to access the message history (including.last
). - Use
response.candidates
to access all the responses generated by the model.
Other attributes are just saved from the arguments to genai.chat
, so you
can easily continue a conversation:
import google.generativeai as genai
genai.configure(api_key=os.environ['GOOGLE_API_KEY'])
response = genai.chat(messages=["Hello."])
print(response.last) # 'Hello! What can I help you with?'
response.reply("Can you tell me a joke?")
See genai.chat
for more details.
Attributes | |
---|---|
candidates
|
A list of candidate responses from the model.
The top candidate is appended to the This list will contain a maximum of |
filters
|
This indicates which types.SafetyCategory (s) blocked a
candidate from this response, the lowest types.HarmProbability
that triggered a block, and the types.HarmThreshold setting for that category.
This indicates the smallest change to the types.SafetySettings that would be
necessary to unblock at least 1 response.
The blocking is configured by the |
messages
|
A snapshot of the conversation history sorted chronologically. |
model
|
The model name. |
context
|
Text that should be provided to the model first, to ground the response. |
examples
|
Examples of what the model should generate. |
temperature
|
Controls the randomness of the output. Must be positive. |
candidate_count
|
The maximum number of generated response messages to return. |
top_k
|
The maximum number of tokens to consider when sampling. |
top_p
|
The maximum cumulative probability of tokens to consider when sampling. |
last
|
A settable property that provides simple access to the last response string
A shortcut for |
Methods
reply
@abc.abstractmethod
reply( message:
google.generativeai.types.MessageOptions
) -> 'ChatResponse'
Add a message to the conversation, and get the model's response.
to_dict
to_dict() -> Dict[str, Any]
__eq__
__eq__(
other
)
Class Variables | |
---|---|
top_k |
None
|
top_p |
None
|