public final class ChatSession extends Object
| Constructor and Description |
|---|
ChatSession(GenerativeModel model)
Creates a new chat session given a GenerativeModel instance.
|
| Modifier and Type | Method and Description |
|---|---|
com.google.common.collect.ImmutableList<Content> |
getHistory()
Returns the history of the conversation.
|
GenerateContentResponse |
sendMessage(Content content)
Sends a message to the model and returns a response.
|
GenerateContentResponse |
sendMessage(String text)
Sends a message to the model and returns a response.
|
ResponseStream<GenerateContentResponse> |
sendMessageStream(Content content)
Sends a message to the model and returns a stream of responses.
|
ResponseStream<GenerateContentResponse> |
sendMessageStream(String text)
Sends a message to the model and returns a stream of responses.
|
void |
setHistory(List<Content> history)
Sets the history to a list of Content.
|
ChatSession |
withGenerationConfig(GenerationConfig generationConfig)
Creates a copy of the current ChatSession with updated GenerationConfig.
|
ChatSession |
withSafetySettings(List<SafetySetting> safetySettings)
Creates a copy of the current ChatSession with updated SafetySettings.
|
ChatSession |
withTools(List<Tool> tools)
Creates a copy of the current ChatSession with updated Tools.
|
public ChatSession(GenerativeModel model)
public ChatSession withGenerationConfig(GenerationConfig generationConfig)
generationConfig - a GenerationConfig that will be
used in the new ChatSession.ChatSession instance with the specified GenerationConfig.public ChatSession withSafetySettings(List<SafetySetting> safetySettings)
safetySettings - a SafetySetting that will be used
in the new ChatSession.ChatSession instance with the specified SafetySettings.public ChatSession withTools(List<Tool> tools)
tools - a Tool that will be used in the new
ChatSession.ChatSession instance with the specified Tools.public ResponseStream<GenerateContentResponse> sendMessageStream(String text) throws IOException
text - the message to be sent.IOExceptionpublic ResponseStream<GenerateContentResponse> sendMessageStream(Content content) throws IOException
content - the content to be sent.IOExceptionpublic GenerateContentResponse sendMessage(String text) throws IOException
text - the message to be sent.IOExceptionpublic GenerateContentResponse sendMessage(Content content) throws IOException
content - the content to be sent.IOExceptionpublic com.google.common.collect.ImmutableList<Content> getHistory()
Content.Copyright © 2024 Google LLC. All rights reserved.