public final class ChatSession extends Object
Note: this class is NOT thread-safe.
| 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 |
withAutomaticFunctionCallingResponder(AutomaticFunctionCallingResponder automaticFunctionCallingResponder)
Creates a copy of the current ChatSession with updated AutomaticFunctionCallingResponder.
|
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 |
withSystemInstruction(Content systemInstruction)
Creates a copy of the current ChatSession with updated SystemInstruction.
|
ChatSession |
withToolConfig(ToolConfig toolConfig)
Creates a copy of the current ChatSession with updated ToolConfig.
|
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 ChatSession withToolConfig(ToolConfig toolConfig)
toolConfig - a ToolConfig that will be used in the
new ChatSession.ChatSession instance with the specified ToolConfigs.public ChatSession withSystemInstruction(Content systemInstruction)
systemInstruction - a Content containing system
instructions.ChatSession instance with the specified ToolConfigs.public ChatSession withAutomaticFunctionCallingResponder(AutomaticFunctionCallingResponder automaticFunctionCallingResponder)
automaticFunctionCallingResponder - an AutomaticFunctionCallingResponder instance
that will be used in the new ChatSession.ChatSession instance with the specified
AutomaticFunctionCallingResponder.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.