public class ChatSessionRepresents a conversation between the user and the model
Constructors
ChatSession(GenerativeModel model)
public ChatSession(GenerativeModel model)| Parameter | |
|---|---|
| Name | Description |
model |
GenerativeModel |
Methods
getHistory()
public List<Content> getHistory()Returns the history of the conversation.
| Returns | |
|---|---|
| Type | Description |
List<Content> |
an unmodifiable history of the conversation. |
sendMessage(Content content)
public GenerateContentResponse sendMessage(Content content)Sends a message to the model and returns a response.
| Parameter | |
|---|---|
| Name | Description |
content |
Contentthe content to be sent. |
| Returns | |
|---|---|
| Type | Description |
GenerateContentResponse |
a response. |
| Exceptions | |
|---|---|
| Type | Description |
IOException |
|
sendMessage(Content content, GenerationConfig generationConfig) (deprecated)
public GenerateContentResponse sendMessage(Content content, GenerationConfig generationConfig)Deprecated. use #sendMessage(Content, GenerateContentConfig) instead
Sends a message to the model and returns a response.
| Parameters | |
|---|---|
| Name | Description |
content |
Contentthe content to be sent. |
generationConfig |
GenerationConfigthe generation config. |
| Returns | |
|---|---|
| Type | Description |
GenerateContentResponse |
a response. |
| Exceptions | |
|---|---|
| Type | Description |
IOException |
|
sendMessage(Content content, GenerationConfig generationConfig, List<SafetySetting> safetySettings) (deprecated)
public GenerateContentResponse sendMessage(Content content, GenerationConfig generationConfig, List<SafetySetting> safetySettings)Deprecated. use #sendMessage(Content, GenerateContentConfig) instead
Sends a message to the model and returns a response.
| Parameters | |
|---|---|
| Name | Description |
content |
Contentthe content to be sent. |
generationConfig |
GenerationConfigthe generation config. |
safetySettings |
List<SafetySetting>the safety settings. |
| Returns | |
|---|---|
| Type | Description |
GenerateContentResponse |
a response. |
| Exceptions | |
|---|---|
| Type | Description |
IOException |
|
sendMessage(Content content, GenerateContentConfig config)
public GenerateContentResponse sendMessage(Content content, GenerateContentConfig config)Sends a message to the model and returns a response.
| Parameters | |
|---|---|
| Name | Description |
content |
Contentthe content to be sent. |
config |
GenerateContentConfiga GenerateContentConfig that contains all the configs for sending message in a chat session. |
| Returns | |
|---|---|
| Type | Description |
GenerateContentResponse |
a response. |
| Exceptions | |
|---|---|
| Type | Description |
IOException |
|
sendMessage(Content content, List<SafetySetting> safetySettings) (deprecated)
public GenerateContentResponse sendMessage(Content content, List<SafetySetting> safetySettings)Deprecated. use #sendMessage(Content, GenerateContentConfig) instead
Sends a message to the model and returns a response.
| Parameters | |
|---|---|
| Name | Description |
content |
Contentthe content to be sent. |
safetySettings |
List<SafetySetting>the safety settings. |
| Returns | |
|---|---|
| Type | Description |
GenerateContentResponse |
a response. |
| Exceptions | |
|---|---|
| Type | Description |
IOException |
|
sendMessage(String text)
public GenerateContentResponse sendMessage(String text)Sends a message to the model and returns a response.
| Parameter | |
|---|---|
| Name | Description |
text |
Stringthe message to be sent. |
| Returns | |
|---|---|
| Type | Description |
GenerateContentResponse |
a response. |
| Exceptions | |
|---|---|
| Type | Description |
IOException |
|
sendMessage(String text, GenerationConfig generationConfig) (deprecated)
public GenerateContentResponse sendMessage(String text, GenerationConfig generationConfig)Deprecated. use #sendMessage(Content, GenerateContentConfig) instead
Sends a message to the model and returns a response.
| Parameters | |
|---|---|
| Name | Description |
text |
Stringthe message to be sent. |
generationConfig |
GenerationConfigthe generation config. |
| Returns | |
|---|---|
| Type | Description |
GenerateContentResponse |
a response. |
| Exceptions | |
|---|---|
| Type | Description |
IOException |
|
sendMessage(String text, GenerationConfig generationConfig, List<SafetySetting> safetySettings) (deprecated)
public GenerateContentResponse sendMessage(String text, GenerationConfig generationConfig, List<SafetySetting> safetySettings)Deprecated. use #sendMessage(String, GenerateContentConfig) instead
Sends a message to the model and returns a response.
| Parameters | |
|---|---|
| Name | Description |
text |
Stringthe message to be sent. |
generationConfig |
GenerationConfigthe generation config. |
safetySettings |
List<SafetySetting>the safety settings. |
| Returns | |
|---|---|
| Type | Description |
GenerateContentResponse |
a response. |
| Exceptions | |
|---|---|
| Type | Description |
IOException |
|
sendMessage(String text, GenerateContentConfig config)
public GenerateContentResponse sendMessage(String text, GenerateContentConfig config)Sends a message to the model and returns a response.
| Parameters | |
|---|---|
| Name | Description |
text |
Stringthe message to be sent. |
config |
GenerateContentConfiga GenerateContentConfig that contains all the configs for sending message in a chat session. |
| Returns | |
|---|---|
| Type | Description |
GenerateContentResponse |
a response. |
| Exceptions | |
|---|---|
| Type | Description |
IOException |
|
sendMessage(String text, List<SafetySetting> safetySettings) (deprecated)
public GenerateContentResponse sendMessage(String text, List<SafetySetting> safetySettings)Deprecated. use #sendMessage(String, GenerateContentConfig) instead
Sends a message to the model and returns a response.
| Parameters | |
|---|---|
| Name | Description |
text |
Stringthe message to be sent. |
safetySettings |
List<SafetySetting>the safety settings. |
| Returns | |
|---|---|
| Type | Description |
GenerateContentResponse |
a response. |
| Exceptions | |
|---|---|
| Type | Description |
IOException |
|
sendMessageStream(Content content)
public ResponseStream<GenerateContentResponse> sendMessageStream(Content content)Sends a message to the model and returns a stream of responses.
| Parameter | |
|---|---|
| Name | Description |
content |
Contentthe content to be sent. |
| Returns | |
|---|---|
| Type | Description |
ResponseStream<GenerateContentResponse> |
an iterable in which each element is a GenerateContentResponse. Can be converted to stream by stream() method. |
| Exceptions | |
|---|---|
| Type | Description |
IOException |
|
IllegalArgumentException |
|
sendMessageStream(Content content, GenerationConfig generationConfig) (deprecated)
public ResponseStream<GenerateContentResponse> sendMessageStream(Content content, GenerationConfig generationConfig)Deprecated. use #sendMessageStream(Content, GenerateContentConfig) instead
Sends a message to the model and returns a stream of responses.
| Parameters | |
|---|---|
| Name | Description |
content |
Contentthe content to be sent. |
generationConfig |
GenerationConfigthe generation config. |
| Returns | |
|---|---|
| Type | Description |
ResponseStream<GenerateContentResponse> |
an iterable in which each element is a GenerateContentResponse. Can be converted to stream by stream() method. |
| Exceptions | |
|---|---|
| Type | Description |
IOException |
|
IllegalArgumentException |
|
sendMessageStream(Content content, GenerationConfig generationConfig, List<SafetySetting> safetySettings) (deprecated)
public ResponseStream<GenerateContentResponse> sendMessageStream(Content content, GenerationConfig generationConfig, List<SafetySetting> safetySettings)Deprecated. use #sendMessageStream(Content, GenerateContentConfig) instead
Sends a message to the model and returns a stream of responses.
| Parameters | |
|---|---|
| Name | Description |
content |
Contentthe content to be sent. |
generationConfig |
GenerationConfigthe generation config. |
safetySettings |
List<SafetySetting>the safety settings. |
| Returns | |
|---|---|
| Type | Description |
ResponseStream<GenerateContentResponse> |
an iterable in which each element is a GenerateContentResponse. Can be converted to stream by stream() method. |
| Exceptions | |
|---|---|
| Type | Description |
IOException |
|
sendMessageStream(Content content, GenerateContentConfig config)
public ResponseStream<GenerateContentResponse> sendMessageStream(Content content, GenerateContentConfig config)Sends a message to the model and returns a stream of responses.
| Parameters | |
|---|---|
| Name | Description |
content |
Contentthe content to be sent. |
config |
GenerateContentConfiga GenerateContentConfig that contains all the configs for sending message in a chat session. |
| Returns | |
|---|---|
| Type | Description |
ResponseStream<GenerateContentResponse> |
an iterable in which each element is a GenerateContentResponse. Can be converted to stream by stream() method. |
| Exceptions | |
|---|---|
| Type | Description |
IOException |
|
sendMessageStream(Content content, List<SafetySetting> safetySettings) (deprecated)
public ResponseStream<GenerateContentResponse> sendMessageStream(Content content, List<SafetySetting> safetySettings)Deprecated. use #sendMessageStream(Content, GenerateContentConfig) instead
Sends a message to the model and returns a stream of responses.
| Parameters | |
|---|---|
| Name | Description |
content |
Contentthe content to be sent. |
safetySettings |
List<SafetySetting>the safety settings. |
| Returns | |
|---|---|
| Type | Description |
ResponseStream<GenerateContentResponse> |
an iterable in which each element is a GenerateContentResponse. Can be converted to stream by stream() method. |
| Exceptions | |
|---|---|
| Type | Description |
IOException |
|
IllegalArgumentException |
|
sendMessageStream(String text)
public ResponseStream<GenerateContentResponse> sendMessageStream(String text)Sends a message to the model and returns a stream of responses.
| Parameter | |
|---|---|
| Name | Description |
text |
Stringthe message to be sent. |
| Returns | |
|---|---|
| Type | Description |
ResponseStream<GenerateContentResponse> |
an iterable in which each element is a GenerateContentResponse. Can be converted to stream by stream() method. |
| Exceptions | |
|---|---|
| Type | Description |
IOException |
|
sendMessageStream(String text, GenerationConfig generationConfig) (deprecated)
public ResponseStream<GenerateContentResponse> sendMessageStream(String text, GenerationConfig generationConfig)Deprecated. use #sendMessageStream(String, GenerateContentConfig) instead
Sends a message to the model and returns a stream of responses.
| Parameters | |
|---|---|
| Name | Description |
text |
Stringthe message to be sent. |
generationConfig |
GenerationConfigthe generation config. |
| Returns | |
|---|---|
| Type | Description |
ResponseStream<GenerateContentResponse> |
an iterable in which each element is a GenerateContentResponse. Can be converted to stream by stream() method. |
| Exceptions | |
|---|---|
| Type | Description |
IOException |
|
sendMessageStream(String text, GenerationConfig generationConfig, List<SafetySetting> safetySettings) (deprecated)
public ResponseStream<GenerateContentResponse> sendMessageStream(String text, GenerationConfig generationConfig, List<SafetySetting> safetySettings)Deprecated. use #sendMessageStream(String, GenerateContentConfig) instead
Sends a message to the model and returns a stream of responses.
| Parameters | |
|---|---|
| Name | Description |
text |
Stringthe message to be sent. |
generationConfig |
GenerationConfigthe generation config. |
safetySettings |
List<SafetySetting>the safety settings. |
| Returns | |
|---|---|
| Type | Description |
ResponseStream<GenerateContentResponse> |
an iterable in which each element is a GenerateContentResponse. Can be converted to stream by stream() method. |
| Exceptions | |
|---|---|
| Type | Description |
IOException |
|
sendMessageStream(String text, GenerateContentConfig config)
public ResponseStream<GenerateContentResponse> sendMessageStream(String text, GenerateContentConfig config)Sends a message to the model and returns a stream of responses.
| Parameters | |
|---|---|
| Name | Description |
text |
Stringthe message to be sent. |
config |
GenerateContentConfiga GenerateContentConfig that contains all the configs for sending message in a chat session. |
| Returns | |
|---|---|
| Type | Description |
ResponseStream<GenerateContentResponse> |
an iterable in which each element is a GenerateContentResponse. Can be converted to stream by stream() method. |
| Exceptions | |
|---|---|
| Type | Description |
IOException |
|
sendMessageStream(String text, List<SafetySetting> safetySettings) (deprecated)
public ResponseStream<GenerateContentResponse> sendMessageStream(String text, List<SafetySetting> safetySettings)Deprecated. use #sendMessageStream(String, GenerateContentConfig) instead
Sends a message to the model and returns a stream of responses.
| Parameters | |
|---|---|
| Name | Description |
text |
Stringthe message to be sent. |
safetySettings |
List<SafetySetting>the safety settings. |
| Returns | |
|---|---|
| Type | Description |
ResponseStream<GenerateContentResponse> |
an iterable in which each element is a GenerateContentResponse. Can be converted to stream by stream() method. |
| Exceptions | |
|---|---|
| Type | Description |
IOException |
|
setHistory(List<Content> history)
public void setHistory(List<Content> history)Set the history to a list of Content
| Parameter | |
|---|---|
| Name | Description |
history |
List<Content> |