public class ChatSession
Represents 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 |
Content the content to be sent. |
Returns | |
---|---|
Type | Description |
GenerateContentResponse |
a response. |
Exceptions | |
---|---|
Type | Description |
IOException |
sendMessage(Content content, GenerationConfig generationConfig)
public GenerateContentResponse sendMessage(Content content, GenerationConfig generationConfig)
Sends a message to the model and returns a response.
Parameters | |
---|---|
Name | Description |
content |
Content the content to be sent. |
generationConfig |
GenerationConfig the generation config. |
Returns | |
---|---|
Type | Description |
GenerateContentResponse |
a response. |
Exceptions | |
---|---|
Type | Description |
IOException |
sendMessage(Content content, GenerationConfig generationConfig, List<SafetySetting> safetySettings)
public GenerateContentResponse sendMessage(Content content, GenerationConfig generationConfig, List<SafetySetting> safetySettings)
Sends a message to the model and returns a response.
Parameters | |
---|---|
Name | Description |
content |
Content the content to be sent. |
generationConfig |
GenerationConfig the generation config. |
safetySettings |
List<SafetySetting> the safety settings. |
Returns | |
---|---|
Type | Description |
GenerateContentResponse |
a response. |
Exceptions | |
---|---|
Type | Description |
IOException |
sendMessage(Content content, List<SafetySetting> safetySettings)
public GenerateContentResponse sendMessage(Content content, List<SafetySetting> safetySettings)
Sends a message to the model and returns a response.
Parameters | |
---|---|
Name | Description |
content |
Content the 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 |
String the message to be sent. |
Returns | |
---|---|
Type | Description |
GenerateContentResponse |
a response. |
Exceptions | |
---|---|
Type | Description |
IOException |
sendMessage(String text, GenerationConfig generationConfig)
public GenerateContentResponse sendMessage(String text, GenerationConfig generationConfig)
Sends a message to the model and returns a response.
Parameters | |
---|---|
Name | Description |
text |
String the message to be sent. |
generationConfig |
GenerationConfig the generation config. |
Returns | |
---|---|
Type | Description |
GenerateContentResponse |
a response. |
Exceptions | |
---|---|
Type | Description |
IOException |
sendMessage(String text, GenerationConfig generationConfig, List<SafetySetting> safetySettings)
public GenerateContentResponse sendMessage(String text, GenerationConfig generationConfig, List<SafetySetting> safetySettings)
Sends a message to the model and returns a response.
Parameters | |
---|---|
Name | Description |
text |
String the message to be sent. |
generationConfig |
GenerationConfig the generation config. |
safetySettings |
List<SafetySetting> the safety settings. |
Returns | |
---|---|
Type | Description |
GenerateContentResponse |
a response. |
Exceptions | |
---|---|
Type | Description |
IOException |
sendMessage(String text, List<SafetySetting> safetySettings)
public GenerateContentResponse sendMessage(String text, List<SafetySetting> safetySettings)
Sends a message to the model and returns a response.
Parameters | |
---|---|
Name | Description |
text |
String the 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 |
Content the 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)
public ResponseStream<GenerateContentResponse> sendMessageStream(Content content, GenerationConfig generationConfig)
Sends a message to the model and returns a stream of responses.
Parameters | |
---|---|
Name | Description |
content |
Content the content to be sent. |
generationConfig |
GenerationConfig the 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)
public ResponseStream<GenerateContentResponse> sendMessageStream(Content content, GenerationConfig generationConfig, List<SafetySetting> safetySettings)
Sends a message to the model and returns a stream of responses.
Parameters | |
---|---|
Name | Description |
content |
Content the content to be sent. |
generationConfig |
GenerationConfig the 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, List<SafetySetting> safetySettings)
public ResponseStream<GenerateContentResponse> sendMessageStream(Content content, List<SafetySetting> safetySettings)
Sends a message to the model and returns a stream of responses.
Parameters | |
---|---|
Name | Description |
content |
Content the 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 |
String the 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)
public ResponseStream<GenerateContentResponse> sendMessageStream(String text, GenerationConfig generationConfig)
Sends a message to the model and returns a stream of responses.
Parameters | |
---|---|
Name | Description |
text |
String the message to be sent. |
generationConfig |
GenerationConfig the 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)
public ResponseStream<GenerateContentResponse> sendMessageStream(String text, GenerationConfig generationConfig, List<SafetySetting> safetySettings)
Sends a message to the model and returns a stream of responses.
Parameters | |
---|---|
Name | Description |
text |
String the message to be sent. |
generationConfig |
GenerationConfig the 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, List<SafetySetting> safetySettings)
public ResponseStream<GenerateContentResponse> sendMessageStream(String text, List<SafetySetting> safetySettings)
Sends a message to the model and returns a stream of responses.
Parameters | |
---|---|
Name | Description |
text |
String the 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> |