Class AsyncChat
-
- All Implemented Interfaces:
public class AsyncChat extends ChatBaseAn async chat session with a generative model.
This class provides a way to interact with a generative model in an async multi-turn chat session. It keeps track of the chat history and uses it to provide context for subsequent messages.
-
-
Method Summary
Modifier and Type Method Description CompletableFuture<GenerateContentResponse>sendMessage(String text, GenerateContentConfig config)Asynchronously sends a message to the model in the current multi-turn chat session and returns the model's response. CompletableFuture<GenerateContentResponse>sendMessage(String text)Asynchronously sends a message to the model in the current multi-turn chat session and returns the model's response. CompletableFuture<GenerateContentResponse>sendMessage(Content content, GenerateContentConfig config)Asynchronously sends a message to the model in the current multi-turn chat session and returns the model's response. CompletableFuture<GenerateContentResponse>sendMessage(Content content)Asynchronously sends a message to the model in the current multi-turn chat session and returns the model's response. CompletableFuture<GenerateContentResponse>sendMessage(List<Content> contents, GenerateContentConfig config)Asynchronously sends a message to the model in the current multi-turn chat session and returns the model's response. CompletableFuture<GenerateContentResponse>sendMessage(List<Content> contents)Asynchronously sends a message to the model in the current multi-turn chat session and returns the model's response. CompletableFuture<ResponseStream<GenerateContentResponse>>sendMessageStream(String text, GenerateContentConfig config)Asynchronously sends a message to the model in the current multi-turn chat session and returns a stream of responses. CompletableFuture<ResponseStream<GenerateContentResponse>>sendMessageStream(String text)Asynchronously sends a message to the model in the current multi-turn chat session and returns a stream of responses. CompletableFuture<ResponseStream<GenerateContentResponse>>sendMessageStream(Content content, GenerateContentConfig config)Asynchronously sends a message to the model in the current multi-turn chat session and returns a stream of responses. CompletableFuture<ResponseStream<GenerateContentResponse>>sendMessageStream(Content content)Asynchronously sends a message to the model in the current multi-turn chat session and returns a stream of responses. CompletableFuture<ResponseStream<GenerateContentResponse>>sendMessageStream(List<Content> contents, GenerateContentConfig config)Asynchronously sends a message to the model in the current multi-turn chat session and returns a stream of responses. CompletableFuture<ResponseStream<GenerateContentResponse>>sendMessageStream(List<Content> contents)Sends a message to the model in the current multi-turn chat session and returns the model's response. -
-
Method Detail
-
sendMessage
CompletableFuture<GenerateContentResponse> sendMessage(String text, GenerateContentConfig config)
Asynchronously sends a message to the model in the current multi-turn chat session and returns the model's response.
This appends the message and the model's response to the chat history, which is sent back to the model in subsequent calls to sendMessage. Be sure to initialize a chat session using client.async.chats.create() before calling sendMessage.
- Parameters:
text- the text to send to the generative modelconfig- a com.google.genai.types.GenerateContentConfig instance that specifies the optional configurations
-
sendMessage
CompletableFuture<GenerateContentResponse> sendMessage(String text)
Asynchronously sends a message to the model in the current multi-turn chat session and returns the model's response.
This appends the message and the model's response to the chat history, which is sent back to the model in subsequent calls to sendMessage. Be sure to initialize a chat session using client.async.chats.create() before calling sendMessage.
- Parameters:
text- the text to send to the generative model
-
sendMessage
CompletableFuture<GenerateContentResponse> sendMessage(Content content, GenerateContentConfig config)
Asynchronously sends a message to the model in the current multi-turn chat session and returns the model's response.
This appends the message and the model's response to the chat history, which is sent back to the model in subsequent calls to sendMessage. Be sure to initialize a chat session using cilent.async.chats.create() before calling sendMessage.
- Parameters:
content- a com.google.genai.types.Content to send to the generative modelconfig- a com.google.genai.types.GenerateContentConfig instance that specifies the optional configurations
-
sendMessage
CompletableFuture<GenerateContentResponse> sendMessage(Content content)
Asynchronously sends a message to the model in the current multi-turn chat session and returns the model's response.
This appends the message and the model's response to the chat history, which is sent back to the model in subsequent calls to sendMessage. Be sure to initialize a chat session using client.async.chats.create() before calling sendMessage.
- Parameters:
content- a com.google.genai.types.Content to send to the generative model
-
sendMessage
CompletableFuture<GenerateContentResponse> sendMessage(List<Content> contents, GenerateContentConfig config)
Asynchronously sends a message to the model in the current multi-turn chat session and returns the model's response.
This appends the message and the model's response to the chat history, which is sent back to the model in subsequent calls to sendMessage. Be sure to initialize a chat session using client.async.chats.create() before calling sendMessage.
- Parameters:
contents- a < to send to the generative modelconfig- a com.google.genai.types.GenerateContentConfig instance that specifies the optional configurations
-
sendMessage
CompletableFuture<GenerateContentResponse> sendMessage(List<Content> contents)
Asynchronously sends a message to the model in the current multi-turn chat session and returns the model's response.
This appends the message and the model's response to the chat history, which is sent back to the model in subsequent calls to sendMessage. Be sure to initialize a chat session using client.async.chats.create() before calling sendMessage.
- Parameters:
contents- a < to send to the generative model
-
sendMessageStream
CompletableFuture<ResponseStream<GenerateContentResponse>> sendMessageStream(String text, GenerateContentConfig config)
Asynchronously sends a message to the model in the current multi-turn chat session and returns a stream of responses.
This appends the message and the model's response to the chat history after the stream is consumed. Be sure to initialize a chat session using client.async.chats.create() before calling sendMessageStream.
- Parameters:
text- the text to send to the generative modelconfig- a com.google.genai.types.GenerateContentConfig instance that specifies the optional configurations *
-
sendMessageStream
CompletableFuture<ResponseStream<GenerateContentResponse>> sendMessageStream(String text)
Asynchronously sends a message to the model in the current multi-turn chat session and returns a stream of responses.
This appends the message and the model's response to the chat history after the stream is consumed. Be sure to initialize a chat session using client.async.chats.create() before calling sendMessageStream.
- Parameters:
text- the text to send to the generative model
-
sendMessageStream
CompletableFuture<ResponseStream<GenerateContentResponse>> sendMessageStream(Content content, GenerateContentConfig config)
Asynchronously sends a message to the model in the current multi-turn chat session and returns a stream of responses.
This appends the message and the model's response to the chat history after the stream is consumed. Be sure to initialize a chat session using client.async.chats.create() before calling sendMessageStream.
- Parameters:
content- a com.google.genai.types.Content to send to the generative modelconfig- a com.google.genai.types.GenerateContentConfig instance that specifies the optional configurations *
-
sendMessageStream
CompletableFuture<ResponseStream<GenerateContentResponse>> sendMessageStream(Content content)
Asynchronously sends a message to the model in the current multi-turn chat session and returns a stream of responses.
This appends the message and the model's response to the chat history after the stream is consumed. Be sure to initialize a chat session using client.async.chats.create() before calling sendMessageStream.
- Parameters:
content- a com.google.genai.types.Content to send to the generative model
-
sendMessageStream
CompletableFuture<ResponseStream<GenerateContentResponse>> sendMessageStream(List<Content> contents, GenerateContentConfig config)
Asynchronously sends a message to the model in the current multi-turn chat session and returns a stream of responses.
This appends the message and the model's response to the chat history after the stream is consumed. Be sure to initialize a chat session using client.async.chats.create() before calling sendMessageStream.
- Parameters:
contents- a < to send to the generative modelconfig- a com.google.genai.types.GenerateContentConfig instance that specifies the optional configurations
-
sendMessageStream
CompletableFuture<ResponseStream<GenerateContentResponse>> sendMessageStream(List<Content> contents)
Sends a message to the model in the current multi-turn chat session and returns the model's response.
This appends the message and the model's response to the chat history after the stream is consumed. Be sure to initialize a chat session using client.async.chats.create() before calling sendMessage.
- Parameters:
contents- a < to send to the generative model the optional configurations
-
-
-
-