Skip to content
This repository was archived by the owner on Dec 3, 2023. It is now read-only.

Commit fca7bfa

Browse files
feat: add GetValidationResult to AgentClient, outputAudioConfigMask to DetectIntentResult (#101)
1 parent a650f81 commit fca7bfa

40 files changed

+5566
-961
lines changed

google-cloud-dialogflow/src/main/java/com/google/cloud/dialogflow/v2/AgentsClient.java

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1036,6 +1036,48 @@ public final UnaryCallable<RestoreAgentRequest, Operation> restoreAgentCallable(
10361036
return stub.restoreAgentCallable();
10371037
}
10381038

1039+
// AUTO-GENERATED DOCUMENTATION AND METHOD
1040+
/**
1041+
* Gets agent validation result. Agent validation is performed during training time and is updated
1042+
* automatically when training is completed.
1043+
*
1044+
* <p>Sample code:
1045+
*
1046+
* <pre><code>
1047+
* try (AgentsClient agentsClient = AgentsClient.create()) {
1048+
* GetValidationResultRequest request = GetValidationResultRequest.newBuilder().build();
1049+
* ValidationResult response = agentsClient.getValidationResult(request);
1050+
* }
1051+
* </code></pre>
1052+
*
1053+
* @param request The request object containing all of the parameters for the API call.
1054+
* @throws com.google.api.gax.rpc.ApiException if the remote call fails
1055+
*/
1056+
public final ValidationResult getValidationResult(GetValidationResultRequest request) {
1057+
return getValidationResultCallable().call(request);
1058+
}
1059+
1060+
// AUTO-GENERATED DOCUMENTATION AND METHOD
1061+
/**
1062+
* Gets agent validation result. Agent validation is performed during training time and is updated
1063+
* automatically when training is completed.
1064+
*
1065+
* <p>Sample code:
1066+
*
1067+
* <pre><code>
1068+
* try (AgentsClient agentsClient = AgentsClient.create()) {
1069+
* GetValidationResultRequest request = GetValidationResultRequest.newBuilder().build();
1070+
* ApiFuture&lt;ValidationResult&gt; future = agentsClient.getValidationResultCallable().futureCall(request);
1071+
* // Do something
1072+
* ValidationResult response = future.get();
1073+
* }
1074+
* </code></pre>
1075+
*/
1076+
public final UnaryCallable<GetValidationResultRequest, ValidationResult>
1077+
getValidationResultCallable() {
1078+
return stub.getValidationResultCallable();
1079+
}
1080+
10391081
@Override
10401082
public final void close() {
10411083
stub.close();

google-cloud-dialogflow/src/main/java/com/google/cloud/dialogflow/v2/AgentsSettings.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,12 @@ public OperationCallSettings<RestoreAgentRequest, Empty, Struct> restoreAgentOpe
141141
return ((AgentsStubSettings) getStubSettings()).restoreAgentOperationSettings();
142142
}
143143

144+
/** Returns the object with the settings used for calls to getValidationResult. */
145+
public UnaryCallSettings<GetValidationResultRequest, ValidationResult>
146+
getValidationResultSettings() {
147+
return ((AgentsStubSettings) getStubSettings()).getValidationResultSettings();
148+
}
149+
144150
public static final AgentsSettings create(AgentsStubSettings stub) throws IOException {
145151
return new AgentsSettings.Builder(stub.toBuilder()).build();
146152
}
@@ -311,6 +317,12 @@ public UnaryCallSettings.Builder<RestoreAgentRequest, Operation> restoreAgentSet
311317
return getStubSettingsBuilder().restoreAgentOperationSettings();
312318
}
313319

320+
/** Returns the builder for the settings used for calls to getValidationResult. */
321+
public UnaryCallSettings.Builder<GetValidationResultRequest, ValidationResult>
322+
getValidationResultSettings() {
323+
return getStubSettingsBuilder().getValidationResultSettings();
324+
}
325+
314326
@Override
315327
public AgentsSettings build() throws IOException {
316328
return new AgentsSettings(this);

google-cloud-dialogflow/src/main/java/com/google/cloud/dialogflow/v2/stub/AgentsStub.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,14 @@
2626
import com.google.cloud.dialogflow.v2.ExportAgentRequest;
2727
import com.google.cloud.dialogflow.v2.ExportAgentResponse;
2828
import com.google.cloud.dialogflow.v2.GetAgentRequest;
29+
import com.google.cloud.dialogflow.v2.GetValidationResultRequest;
2930
import com.google.cloud.dialogflow.v2.ImportAgentRequest;
3031
import com.google.cloud.dialogflow.v2.RestoreAgentRequest;
3132
import com.google.cloud.dialogflow.v2.SearchAgentsRequest;
3233
import com.google.cloud.dialogflow.v2.SearchAgentsResponse;
3334
import com.google.cloud.dialogflow.v2.SetAgentRequest;
3435
import com.google.cloud.dialogflow.v2.TrainAgentRequest;
36+
import com.google.cloud.dialogflow.v2.ValidationResult;
3537
import com.google.longrunning.Operation;
3638
import com.google.longrunning.stub.OperationsStub;
3739
import com.google.protobuf.Empty;
@@ -110,6 +112,10 @@ public UnaryCallable<RestoreAgentRequest, Operation> restoreAgentCallable() {
110112
throw new UnsupportedOperationException("Not implemented: restoreAgentCallable()");
111113
}
112114

115+
public UnaryCallable<GetValidationResultRequest, ValidationResult> getValidationResultCallable() {
116+
throw new UnsupportedOperationException("Not implemented: getValidationResultCallable()");
117+
}
118+
113119
@Override
114120
public abstract void close();
115121
}

google-cloud-dialogflow/src/main/java/com/google/cloud/dialogflow/v2/stub/AgentsStubSettings.java

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,14 @@
4848
import com.google.cloud.dialogflow.v2.ExportAgentRequest;
4949
import com.google.cloud.dialogflow.v2.ExportAgentResponse;
5050
import com.google.cloud.dialogflow.v2.GetAgentRequest;
51+
import com.google.cloud.dialogflow.v2.GetValidationResultRequest;
5152
import com.google.cloud.dialogflow.v2.ImportAgentRequest;
5253
import com.google.cloud.dialogflow.v2.RestoreAgentRequest;
5354
import com.google.cloud.dialogflow.v2.SearchAgentsRequest;
5455
import com.google.cloud.dialogflow.v2.SearchAgentsResponse;
5556
import com.google.cloud.dialogflow.v2.SetAgentRequest;
5657
import com.google.cloud.dialogflow.v2.TrainAgentRequest;
58+
import com.google.cloud.dialogflow.v2.ValidationResult;
5759
import com.google.common.collect.ImmutableList;
5860
import com.google.common.collect.ImmutableMap;
5961
import com.google.common.collect.ImmutableSet;
@@ -124,6 +126,8 @@ public class AgentsStubSettings extends StubSettings<AgentsStubSettings> {
124126
private final UnaryCallSettings<RestoreAgentRequest, Operation> restoreAgentSettings;
125127
private final OperationCallSettings<RestoreAgentRequest, Empty, Struct>
126128
restoreAgentOperationSettings;
129+
private final UnaryCallSettings<GetValidationResultRequest, ValidationResult>
130+
getValidationResultSettings;
127131

128132
/** Returns the object with the settings used for calls to setAgent. */
129133
public UnaryCallSettings<SetAgentRequest, Agent> setAgentSettings() {
@@ -191,6 +195,12 @@ public OperationCallSettings<RestoreAgentRequest, Empty, Struct> restoreAgentOpe
191195
return restoreAgentOperationSettings;
192196
}
193197

198+
/** Returns the object with the settings used for calls to getValidationResult. */
199+
public UnaryCallSettings<GetValidationResultRequest, ValidationResult>
200+
getValidationResultSettings() {
201+
return getValidationResultSettings;
202+
}
203+
194204
@BetaApi("A restructuring of stub classes is planned, so this may break in the future")
195205
public AgentsStub createStub() throws IOException {
196206
if (getTransportChannelProvider()
@@ -271,6 +281,7 @@ protected AgentsStubSettings(Builder settingsBuilder) throws IOException {
271281
importAgentOperationSettings = settingsBuilder.importAgentOperationSettings().build();
272282
restoreAgentSettings = settingsBuilder.restoreAgentSettings().build();
273283
restoreAgentOperationSettings = settingsBuilder.restoreAgentOperationSettings().build();
284+
getValidationResultSettings = settingsBuilder.getValidationResultSettings().build();
274285
}
275286

276287
private static final PagedListDescriptor<SearchAgentsRequest, SearchAgentsResponse, Agent>
@@ -348,6 +359,8 @@ public static class Builder extends StubSettings.Builder<AgentsStubSettings, Bui
348359
private final UnaryCallSettings.Builder<RestoreAgentRequest, Operation> restoreAgentSettings;
349360
private final OperationCallSettings.Builder<RestoreAgentRequest, Empty, Struct>
350361
restoreAgentOperationSettings;
362+
private final UnaryCallSettings.Builder<GetValidationResultRequest, ValidationResult>
363+
getValidationResultSettings;
351364

352365
private static final ImmutableMap<String, ImmutableSet<StatusCode.Code>>
353366
RETRYABLE_CODE_DEFINITIONS;
@@ -414,6 +427,8 @@ protected Builder(ClientContext clientContext) {
414427

415428
restoreAgentOperationSettings = OperationCallSettings.newBuilder();
416429

430+
getValidationResultSettings = UnaryCallSettings.newUnaryCallSettingsBuilder();
431+
417432
unaryMethodSettingsBuilders =
418433
ImmutableList.<UnaryCallSettings.Builder<?, ?>>of(
419434
setAgentSettings,
@@ -423,7 +438,8 @@ protected Builder(ClientContext clientContext) {
423438
trainAgentSettings,
424439
exportAgentSettings,
425440
importAgentSettings,
426-
restoreAgentSettings);
441+
restoreAgentSettings,
442+
getValidationResultSettings);
427443

428444
initDefaults(this);
429445
}
@@ -478,6 +494,11 @@ private static Builder initDefaults(Builder builder) {
478494
.restoreAgentSettings()
479495
.setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("idempotent"))
480496
.setRetrySettings(RETRY_PARAM_DEFINITIONS.get("default"));
497+
498+
builder
499+
.getValidationResultSettings()
500+
.setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("idempotent"))
501+
.setRetrySettings(RETRY_PARAM_DEFINITIONS.get("default"));
481502
builder
482503
.trainAgentOperationSettings()
483504
.setInitialCallSettings(
@@ -586,6 +607,7 @@ protected Builder(AgentsStubSettings settings) {
586607
importAgentOperationSettings = settings.importAgentOperationSettings.toBuilder();
587608
restoreAgentSettings = settings.restoreAgentSettings.toBuilder();
588609
restoreAgentOperationSettings = settings.restoreAgentOperationSettings.toBuilder();
610+
getValidationResultSettings = settings.getValidationResultSettings.toBuilder();
589611

590612
unaryMethodSettingsBuilders =
591613
ImmutableList.<UnaryCallSettings.Builder<?, ?>>of(
@@ -596,7 +618,8 @@ protected Builder(AgentsStubSettings settings) {
596618
trainAgentSettings,
597619
exportAgentSettings,
598620
importAgentSettings,
599-
restoreAgentSettings);
621+
restoreAgentSettings,
622+
getValidationResultSettings);
600623
}
601624

602625
// NEXT_MAJOR_VER: remove 'throws Exception'
@@ -689,6 +712,12 @@ public UnaryCallSettings.Builder<RestoreAgentRequest, Operation> restoreAgentSet
689712
return restoreAgentOperationSettings;
690713
}
691714

715+
/** Returns the builder for the settings used for calls to getValidationResult. */
716+
public UnaryCallSettings.Builder<GetValidationResultRequest, ValidationResult>
717+
getValidationResultSettings() {
718+
return getValidationResultSettings;
719+
}
720+
692721
@Override
693722
public AgentsStubSettings build() throws IOException {
694723
return new AgentsStubSettings(this);

google-cloud-dialogflow/src/main/java/com/google/cloud/dialogflow/v2/stub/GrpcAgentsStub.java

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,14 @@
3131
import com.google.cloud.dialogflow.v2.ExportAgentRequest;
3232
import com.google.cloud.dialogflow.v2.ExportAgentResponse;
3333
import com.google.cloud.dialogflow.v2.GetAgentRequest;
34+
import com.google.cloud.dialogflow.v2.GetValidationResultRequest;
3435
import com.google.cloud.dialogflow.v2.ImportAgentRequest;
3536
import com.google.cloud.dialogflow.v2.RestoreAgentRequest;
3637
import com.google.cloud.dialogflow.v2.SearchAgentsRequest;
3738
import com.google.cloud.dialogflow.v2.SearchAgentsResponse;
3839
import com.google.cloud.dialogflow.v2.SetAgentRequest;
3940
import com.google.cloud.dialogflow.v2.TrainAgentRequest;
41+
import com.google.cloud.dialogflow.v2.ValidationResult;
4042
import com.google.common.collect.ImmutableMap;
4143
import com.google.longrunning.Operation;
4244
import com.google.longrunning.stub.GrpcOperationsStub;
@@ -118,6 +120,15 @@ public class GrpcAgentsStub extends AgentsStub {
118120
.setRequestMarshaller(ProtoUtils.marshaller(RestoreAgentRequest.getDefaultInstance()))
119121
.setResponseMarshaller(ProtoUtils.marshaller(Operation.getDefaultInstance()))
120122
.build();
123+
private static final MethodDescriptor<GetValidationResultRequest, ValidationResult>
124+
getValidationResultMethodDescriptor =
125+
MethodDescriptor.<GetValidationResultRequest, ValidationResult>newBuilder()
126+
.setType(MethodDescriptor.MethodType.UNARY)
127+
.setFullMethodName("google.cloud.dialogflow.v2.Agents/GetValidationResult")
128+
.setRequestMarshaller(
129+
ProtoUtils.marshaller(GetValidationResultRequest.getDefaultInstance()))
130+
.setResponseMarshaller(ProtoUtils.marshaller(ValidationResult.getDefaultInstance()))
131+
.build();
121132

122133
private final BackgroundResource backgroundResources;
123134
private final GrpcOperationsStub operationsStub;
@@ -137,6 +148,8 @@ public class GrpcAgentsStub extends AgentsStub {
137148
private final OperationCallable<ImportAgentRequest, Empty, Struct> importAgentOperationCallable;
138149
private final UnaryCallable<RestoreAgentRequest, Operation> restoreAgentCallable;
139150
private final OperationCallable<RestoreAgentRequest, Empty, Struct> restoreAgentOperationCallable;
151+
private final UnaryCallable<GetValidationResultRequest, ValidationResult>
152+
getValidationResultCallable;
140153

141154
private final GrpcStubCallableFactory callableFactory;
142155

@@ -279,6 +292,20 @@ public Map<String, String> extract(RestoreAgentRequest request) {
279292
}
280293
})
281294
.build();
295+
GrpcCallSettings<GetValidationResultRequest, ValidationResult>
296+
getValidationResultTransportSettings =
297+
GrpcCallSettings.<GetValidationResultRequest, ValidationResult>newBuilder()
298+
.setMethodDescriptor(getValidationResultMethodDescriptor)
299+
.setParamsExtractor(
300+
new RequestParamsExtractor<GetValidationResultRequest>() {
301+
@Override
302+
public Map<String, String> extract(GetValidationResultRequest request) {
303+
ImmutableMap.Builder<String, String> params = ImmutableMap.builder();
304+
params.put("parent", String.valueOf(request.getParent()));
305+
return params.build();
306+
}
307+
})
308+
.build();
282309

283310
this.setAgentCallable =
284311
callableFactory.createUnaryCallable(
@@ -331,6 +358,11 @@ public Map<String, String> extract(RestoreAgentRequest request) {
331358
settings.restoreAgentOperationSettings(),
332359
clientContext,
333360
this.operationsStub);
361+
this.getValidationResultCallable =
362+
callableFactory.createUnaryCallable(
363+
getValidationResultTransportSettings,
364+
settings.getValidationResultSettings(),
365+
clientContext);
334366

335367
backgroundResources = new BackgroundResourceAggregation(clientContext.getBackgroundResources());
336368
}
@@ -397,6 +429,10 @@ public UnaryCallable<RestoreAgentRequest, Operation> restoreAgentCallable() {
397429
return restoreAgentCallable;
398430
}
399431

432+
public UnaryCallable<GetValidationResultRequest, ValidationResult> getValidationResultCallable() {
433+
return getValidationResultCallable;
434+
}
435+
400436
@Override
401437
public final void close() {
402438
shutdown();

google-cloud-dialogflow/src/test/java/com/google/cloud/dialogflow/v2/AgentsClientTest.java

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -489,4 +489,41 @@ public void restoreAgentExceptionTest() throws Exception {
489489
Assert.assertEquals(StatusCode.Code.INVALID_ARGUMENT, apiException.getStatusCode().getCode());
490490
}
491491
}
492+
493+
@Test
494+
@SuppressWarnings("all")
495+
public void getValidationResultTest() {
496+
ValidationResult expectedResponse = ValidationResult.newBuilder().build();
497+
mockAgents.addResponse(expectedResponse);
498+
499+
GetValidationResultRequest request = GetValidationResultRequest.newBuilder().build();
500+
501+
ValidationResult actualResponse = client.getValidationResult(request);
502+
Assert.assertEquals(expectedResponse, actualResponse);
503+
504+
List<AbstractMessage> actualRequests = mockAgents.getRequests();
505+
Assert.assertEquals(1, actualRequests.size());
506+
GetValidationResultRequest actualRequest = (GetValidationResultRequest) actualRequests.get(0);
507+
508+
Assert.assertTrue(
509+
channelProvider.isHeaderSent(
510+
ApiClientHeaderProvider.getDefaultApiClientHeaderKey(),
511+
GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
512+
}
513+
514+
@Test
515+
@SuppressWarnings("all")
516+
public void getValidationResultExceptionTest() throws Exception {
517+
StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT);
518+
mockAgents.addException(exception);
519+
520+
try {
521+
GetValidationResultRequest request = GetValidationResultRequest.newBuilder().build();
522+
523+
client.getValidationResult(request);
524+
Assert.fail("No exception raised");
525+
} catch (InvalidArgumentException e) {
526+
// Expected exception
527+
}
528+
}
492529
}

google-cloud-dialogflow/src/test/java/com/google/cloud/dialogflow/v2/MockAgentsImpl.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,4 +171,19 @@ public void restoreAgent(
171171
responseObserver.onError(new IllegalArgumentException("Unrecognized response type"));
172172
}
173173
}
174+
175+
@Override
176+
public void getValidationResult(
177+
GetValidationResultRequest request, StreamObserver<ValidationResult> responseObserver) {
178+
Object response = responses.remove();
179+
if (response instanceof ValidationResult) {
180+
requests.add(request);
181+
responseObserver.onNext((ValidationResult) response);
182+
responseObserver.onCompleted();
183+
} else if (response instanceof Exception) {
184+
responseObserver.onError((Exception) response);
185+
} else {
186+
responseObserver.onError(new IllegalArgumentException("Unrecognized response type"));
187+
}
188+
}
174189
}

0 commit comments

Comments
 (0)