- 0.64.0 (latest)
- 0.63.0
- 0.62.0
- 0.60.0
- 0.59.0
- 0.58.0
- 0.57.0
- 0.56.0
- 0.55.0
- 0.54.0
- 0.53.0
- 0.52.0
- 0.51.0
- 0.50.0
- 0.48.0
- 0.47.0
- 0.46.0
- 0.45.0
- 0.44.0
- 0.43.0
- 0.42.0
- 0.41.0
- 0.40.0
- 0.39.0
- 0.38.0
- 0.35.0
- 0.34.0
- 0.33.0
- 0.32.0
- 0.31.0
- 0.30.0
- 0.29.0
- 0.28.0
- 0.27.0
- 0.26.0
- 0.25.0
- 0.24.0
- 0.23.0
- 0.22.0
- 0.20.0
- 0.19.0
- 0.18.0
- 0.17.0
- 0.16.0
- 0.15.0
- 0.14.7
- 0.13.1
- 0.12.1
- 0.11.5
public class SessionsClient implements BackgroundResource
Service Description: A session represents an interaction with a user. You retrieve user input and pass it to the DetectIntent method to determine user intent and respond.
This class provides the ability to make remote calls to the backing service through method calls that map to API methods. Sample code to get started:
try (SessionsClient sessionsClient = SessionsClient.create()) {
DetectIntentRequest request =
DetectIntentRequest.newBuilder()
.setSession(
SessionName.ofProjectLocationAgentSessionName(
"[PROJECT]", "[LOCATION]", "[AGENT]", "[SESSION]")
.toString())
.setQueryParams(QueryParameters.newBuilder().build())
.setQueryInput(QueryInput.newBuilder().build())
.setOutputAudioConfig(OutputAudioConfig.newBuilder().build())
.build();
DetectIntentResponse response = sessionsClient.detectIntent(request);
}
Note: close() needs to be called on the SessionsClient object to clean up resources such as threads. In the example above, try-with-resources is used, which automatically calls close().
The surface of this class includes several types of Java methods for each of the API's methods:
- A "flattened" method. With this type of method, the fields of the request type have been converted into function parameters. It may be the case that not all fields are available as parameters, and not every API method will have a flattened method entry point.
- A "request object" method. This type of method only takes one parameter, a request object, which must be constructed before the call. Not every API method will have a request object method.
- A "callable" method. This type of method takes no parameters and returns an immutable API callable object, which can be used to initiate calls to the service.
See the individual methods for example code.
Many parameters require resource names to be formatted in a particular way. To assist with these names, this class includes a format method for each type of name, and additionally a parse method to extract the individual identifiers contained within names that are returned.
This class can be customized by passing in a custom instance of SessionsSettings to create(). For example:
To customize credentials:
SessionsSettings sessionsSettings =
SessionsSettings.newBuilder()
.setCredentialsProvider(FixedCredentialsProvider.create(myCredentials))
.build();
SessionsClient sessionsClient = SessionsClient.create(sessionsSettings);
To customize the endpoint:
SessionsSettings sessionsSettings =
SessionsSettings.newBuilder().setEndpoint(myEndpoint).build();
SessionsClient sessionsClient = SessionsClient.create(sessionsSettings);
Please refer to the GitHub repository's samples for more quickstart code snippets.
Implements
BackgroundResourceStatic Methods
create()
public static final SessionsClient create()
Constructs an instance of SessionsClient with default settings.
Type | Description |
SessionsClient |
Type | Description |
IOException |
create(SessionsSettings settings)
public static final SessionsClient create(SessionsSettings settings)
Constructs an instance of SessionsClient, using the given settings. The channels are created based on the settings passed in, or defaults for any settings that are not set.
Name | Description |
settings | SessionsSettings |
Type | Description |
SessionsClient |
Type | Description |
IOException |
create(SessionsStub stub)
public static final SessionsClient create(SessionsStub stub)
Constructs an instance of SessionsClient, using the given stub for making calls. This is for advanced usage - prefer using create(SessionsSettings).
Name | Description |
stub | SessionsStub |
Type | Description |
SessionsClient |
Constructors
SessionsClient(SessionsSettings settings)
protected SessionsClient(SessionsSettings settings)
Constructs an instance of SessionsClient, using the given settings. This is protected so that it is easy to make a subclass, but otherwise, the static factory methods should be preferred.
Name | Description |
settings | SessionsSettings |
SessionsClient(SessionsStub stub)
protected SessionsClient(SessionsStub stub)
Name | Description |
stub | SessionsStub |
Methods
awaitTermination(long duration, TimeUnit unit)
public boolean awaitTermination(long duration, TimeUnit unit)
Name | Description |
duration | long |
unit | TimeUnit |
Type | Description |
boolean |
Type | Description |
InterruptedException |
close()
public final void close()
detectIntent(DetectIntentRequest request)
public final DetectIntentResponse detectIntent(DetectIntentRequest request)
Processes a natural language query and returns structured, actionable data as a result. This method is not idempotent, because it may cause session entity types to be updated, which in turn might affect results of future queries.
Note: Always use agent versions for production traffic. See Versions and environments.
Sample code:
try (SessionsClient sessionsClient = SessionsClient.create()) {
DetectIntentRequest request =
DetectIntentRequest.newBuilder()
.setSession(
SessionName.ofProjectLocationAgentSessionName(
"[PROJECT]", "[LOCATION]", "[AGENT]", "[SESSION]")
.toString())
.setQueryParams(QueryParameters.newBuilder().build())
.setQueryInput(QueryInput.newBuilder().build())
.setOutputAudioConfig(OutputAudioConfig.newBuilder().build())
.build();
DetectIntentResponse response = sessionsClient.detectIntent(request);
}
Name | Description |
request | DetectIntentRequest The request object containing all of the parameters for the API call. |
Type | Description |
DetectIntentResponse |
detectIntentCallable()
public final UnaryCallable<DetectIntentRequest,DetectIntentResponse> detectIntentCallable()
Processes a natural language query and returns structured, actionable data as a result. This method is not idempotent, because it may cause session entity types to be updated, which in turn might affect results of future queries.
Note: Always use agent versions for production traffic. See Versions and environments.
Sample code:
try (SessionsClient sessionsClient = SessionsClient.create()) {
DetectIntentRequest request =
DetectIntentRequest.newBuilder()
.setSession(
SessionName.ofProjectLocationAgentSessionName(
"[PROJECT]", "[LOCATION]", "[AGENT]", "[SESSION]")
.toString())
.setQueryParams(QueryParameters.newBuilder().build())
.setQueryInput(QueryInput.newBuilder().build())
.setOutputAudioConfig(OutputAudioConfig.newBuilder().build())
.build();
ApiFuture<DetectIntentResponse> future =
sessionsClient.detectIntentCallable().futureCall(request);
// Do something.
DetectIntentResponse response = future.get();
}
Type | Description |
UnaryCallable<DetectIntentRequest,DetectIntentResponse> |
fulfillIntent(FulfillIntentRequest request)
public final FulfillIntentResponse fulfillIntent(FulfillIntentRequest request)
Fulfills a matched intent returned by MatchIntent. Must be called after MatchIntent, with input from MatchIntentResponse. Otherwise, the behavior is undefined.
Sample code:
try (SessionsClient sessionsClient = SessionsClient.create()) {
FulfillIntentRequest request =
FulfillIntentRequest.newBuilder()
.setMatchIntentRequest(MatchIntentRequest.newBuilder().build())
.setMatch(Match.newBuilder().build())
.setOutputAudioConfig(OutputAudioConfig.newBuilder().build())
.build();
FulfillIntentResponse response = sessionsClient.fulfillIntent(request);
}
Name | Description |
request | FulfillIntentRequest The request object containing all of the parameters for the API call. |
Type | Description |
FulfillIntentResponse |
fulfillIntentCallable()
public final UnaryCallable<FulfillIntentRequest,FulfillIntentResponse> fulfillIntentCallable()
Fulfills a matched intent returned by MatchIntent. Must be called after MatchIntent, with input from MatchIntentResponse. Otherwise, the behavior is undefined.
Sample code:
try (SessionsClient sessionsClient = SessionsClient.create()) {
FulfillIntentRequest request =
FulfillIntentRequest.newBuilder()
.setMatchIntentRequest(MatchIntentRequest.newBuilder().build())
.setMatch(Match.newBuilder().build())
.setOutputAudioConfig(OutputAudioConfig.newBuilder().build())
.build();
ApiFuture<FulfillIntentResponse> future =
sessionsClient.fulfillIntentCallable().futureCall(request);
// Do something.
FulfillIntentResponse response = future.get();
}
Type | Description |
UnaryCallable<FulfillIntentRequest,FulfillIntentResponse> |
getSettings()
public final SessionsSettings getSettings()
Type | Description |
SessionsSettings |
getStub()
public SessionsStub getStub()
Type | Description |
SessionsStub |
isShutdown()
public boolean isShutdown()
Type | Description |
boolean |
isTerminated()
public boolean isTerminated()
Type | Description |
boolean |
matchIntent(MatchIntentRequest request)
public final MatchIntentResponse matchIntent(MatchIntentRequest request)
Returns preliminary intent match results, doesn't change the session status.
Sample code:
try (SessionsClient sessionsClient = SessionsClient.create()) {
MatchIntentRequest request =
MatchIntentRequest.newBuilder()
.setSession(
SessionName.ofProjectLocationAgentSessionName(
"[PROJECT]", "[LOCATION]", "[AGENT]", "[SESSION]")
.toString())
.setQueryParams(QueryParameters.newBuilder().build())
.setQueryInput(QueryInput.newBuilder().build())
.build();
MatchIntentResponse response = sessionsClient.matchIntent(request);
}
Name | Description |
request | MatchIntentRequest The request object containing all of the parameters for the API call. |
Type | Description |
MatchIntentResponse |
matchIntentCallable()
public final UnaryCallable<MatchIntentRequest,MatchIntentResponse> matchIntentCallable()
Returns preliminary intent match results, doesn't change the session status.
Sample code:
try (SessionsClient sessionsClient = SessionsClient.create()) {
MatchIntentRequest request =
MatchIntentRequest.newBuilder()
.setSession(
SessionName.ofProjectLocationAgentSessionName(
"[PROJECT]", "[LOCATION]", "[AGENT]", "[SESSION]")
.toString())
.setQueryParams(QueryParameters.newBuilder().build())
.setQueryInput(QueryInput.newBuilder().build())
.build();
ApiFuture<MatchIntentResponse> future =
sessionsClient.matchIntentCallable().futureCall(request);
// Do something.
MatchIntentResponse response = future.get();
}
Type | Description |
UnaryCallable<MatchIntentRequest,MatchIntentResponse> |
shutdown()
public void shutdown()
shutdownNow()
public void shutdownNow()
streamingDetectIntentCallable()
public final BidiStreamingCallable<StreamingDetectIntentRequest,StreamingDetectIntentResponse> streamingDetectIntentCallable()
Processes a natural language query in audio format in a streaming fashion and returns structured, actionable data as a result. This method is only available via the gRPC API (not REST).
Note: Always use agent versions for production traffic. See Versions and environments.
Sample code:
try (SessionsClient sessionsClient = SessionsClient.create()) {
BidiStream<StreamingDetectIntentRequest, StreamingDetectIntentResponse> bidiStream =
sessionsClient.streamingDetectIntentCallable().call();
StreamingDetectIntentRequest request =
StreamingDetectIntentRequest.newBuilder()
.setSession(
SessionName.ofProjectLocationAgentSessionName(
"[PROJECT]", "[LOCATION]", "[AGENT]", "[SESSION]")
.toString())
.setQueryParams(QueryParameters.newBuilder().build())
.setQueryInput(QueryInput.newBuilder().build())
.setOutputAudioConfig(OutputAudioConfig.newBuilder().build())
.setEnablePartialResponse(true)
.build();
bidiStream.send(request);
for (StreamingDetectIntentResponse response : bidiStream) {
// Do something when a response is received.
}
}
Type | Description |
BidiStreamingCallable<StreamingDetectIntentRequest,StreamingDetectIntentResponse> |