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

Commit

Permalink
feat: add GetValidationResult to AgentClient, outputAudioConfigMask t…
Browse files Browse the repository at this point in the history
…o DetectIntentResult (#101)
  • Loading branch information
yoshi-automation committed Mar 2, 2020
1 parent a650f81 commit fca7bfa
Show file tree
Hide file tree
Showing 40 changed files with 5,566 additions and 961 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1036,6 +1036,48 @@ public final UnaryCallable<RestoreAgentRequest, Operation> restoreAgentCallable(
return stub.restoreAgentCallable();
}

// AUTO-GENERATED DOCUMENTATION AND METHOD
/**
* Gets agent validation result. Agent validation is performed during training time and is updated
* automatically when training is completed.
*
* <p>Sample code:
*
* <pre><code>
* try (AgentsClient agentsClient = AgentsClient.create()) {
* GetValidationResultRequest request = GetValidationResultRequest.newBuilder().build();
* ValidationResult response = agentsClient.getValidationResult(request);
* }
* </code></pre>
*
* @param request The request object containing all of the parameters for the API call.
* @throws com.google.api.gax.rpc.ApiException if the remote call fails
*/
public final ValidationResult getValidationResult(GetValidationResultRequest request) {
return getValidationResultCallable().call(request);
}

// AUTO-GENERATED DOCUMENTATION AND METHOD
/**
* Gets agent validation result. Agent validation is performed during training time and is updated
* automatically when training is completed.
*
* <p>Sample code:
*
* <pre><code>
* try (AgentsClient agentsClient = AgentsClient.create()) {
* GetValidationResultRequest request = GetValidationResultRequest.newBuilder().build();
* ApiFuture&lt;ValidationResult&gt; future = agentsClient.getValidationResultCallable().futureCall(request);
* // Do something
* ValidationResult response = future.get();
* }
* </code></pre>
*/
public final UnaryCallable<GetValidationResultRequest, ValidationResult>
getValidationResultCallable() {
return stub.getValidationResultCallable();
}

@Override
public final void close() {
stub.close();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,12 @@ public OperationCallSettings<RestoreAgentRequest, Empty, Struct> restoreAgentOpe
return ((AgentsStubSettings) getStubSettings()).restoreAgentOperationSettings();
}

/** Returns the object with the settings used for calls to getValidationResult. */
public UnaryCallSettings<GetValidationResultRequest, ValidationResult>
getValidationResultSettings() {
return ((AgentsStubSettings) getStubSettings()).getValidationResultSettings();
}

public static final AgentsSettings create(AgentsStubSettings stub) throws IOException {
return new AgentsSettings.Builder(stub.toBuilder()).build();
}
Expand Down Expand Up @@ -311,6 +317,12 @@ public UnaryCallSettings.Builder<RestoreAgentRequest, Operation> restoreAgentSet
return getStubSettingsBuilder().restoreAgentOperationSettings();
}

/** Returns the builder for the settings used for calls to getValidationResult. */
public UnaryCallSettings.Builder<GetValidationResultRequest, ValidationResult>
getValidationResultSettings() {
return getStubSettingsBuilder().getValidationResultSettings();
}

@Override
public AgentsSettings build() throws IOException {
return new AgentsSettings(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,14 @@
import com.google.cloud.dialogflow.v2.ExportAgentRequest;
import com.google.cloud.dialogflow.v2.ExportAgentResponse;
import com.google.cloud.dialogflow.v2.GetAgentRequest;
import com.google.cloud.dialogflow.v2.GetValidationResultRequest;
import com.google.cloud.dialogflow.v2.ImportAgentRequest;
import com.google.cloud.dialogflow.v2.RestoreAgentRequest;
import com.google.cloud.dialogflow.v2.SearchAgentsRequest;
import com.google.cloud.dialogflow.v2.SearchAgentsResponse;
import com.google.cloud.dialogflow.v2.SetAgentRequest;
import com.google.cloud.dialogflow.v2.TrainAgentRequest;
import com.google.cloud.dialogflow.v2.ValidationResult;
import com.google.longrunning.Operation;
import com.google.longrunning.stub.OperationsStub;
import com.google.protobuf.Empty;
Expand Down Expand Up @@ -110,6 +112,10 @@ public UnaryCallable<RestoreAgentRequest, Operation> restoreAgentCallable() {
throw new UnsupportedOperationException("Not implemented: restoreAgentCallable()");
}

public UnaryCallable<GetValidationResultRequest, ValidationResult> getValidationResultCallable() {
throw new UnsupportedOperationException("Not implemented: getValidationResultCallable()");
}

@Override
public abstract void close();
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,14 @@
import com.google.cloud.dialogflow.v2.ExportAgentRequest;
import com.google.cloud.dialogflow.v2.ExportAgentResponse;
import com.google.cloud.dialogflow.v2.GetAgentRequest;
import com.google.cloud.dialogflow.v2.GetValidationResultRequest;
import com.google.cloud.dialogflow.v2.ImportAgentRequest;
import com.google.cloud.dialogflow.v2.RestoreAgentRequest;
import com.google.cloud.dialogflow.v2.SearchAgentsRequest;
import com.google.cloud.dialogflow.v2.SearchAgentsResponse;
import com.google.cloud.dialogflow.v2.SetAgentRequest;
import com.google.cloud.dialogflow.v2.TrainAgentRequest;
import com.google.cloud.dialogflow.v2.ValidationResult;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
Expand Down Expand Up @@ -124,6 +126,8 @@ public class AgentsStubSettings extends StubSettings<AgentsStubSettings> {
private final UnaryCallSettings<RestoreAgentRequest, Operation> restoreAgentSettings;
private final OperationCallSettings<RestoreAgentRequest, Empty, Struct>
restoreAgentOperationSettings;
private final UnaryCallSettings<GetValidationResultRequest, ValidationResult>
getValidationResultSettings;

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

/** Returns the object with the settings used for calls to getValidationResult. */
public UnaryCallSettings<GetValidationResultRequest, ValidationResult>
getValidationResultSettings() {
return getValidationResultSettings;
}

@BetaApi("A restructuring of stub classes is planned, so this may break in the future")
public AgentsStub createStub() throws IOException {
if (getTransportChannelProvider()
Expand Down Expand Up @@ -271,6 +281,7 @@ protected AgentsStubSettings(Builder settingsBuilder) throws IOException {
importAgentOperationSettings = settingsBuilder.importAgentOperationSettings().build();
restoreAgentSettings = settingsBuilder.restoreAgentSettings().build();
restoreAgentOperationSettings = settingsBuilder.restoreAgentOperationSettings().build();
getValidationResultSettings = settingsBuilder.getValidationResultSettings().build();
}

private static final PagedListDescriptor<SearchAgentsRequest, SearchAgentsResponse, Agent>
Expand Down Expand Up @@ -348,6 +359,8 @@ public static class Builder extends StubSettings.Builder<AgentsStubSettings, Bui
private final UnaryCallSettings.Builder<RestoreAgentRequest, Operation> restoreAgentSettings;
private final OperationCallSettings.Builder<RestoreAgentRequest, Empty, Struct>
restoreAgentOperationSettings;
private final UnaryCallSettings.Builder<GetValidationResultRequest, ValidationResult>
getValidationResultSettings;

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

restoreAgentOperationSettings = OperationCallSettings.newBuilder();

getValidationResultSettings = UnaryCallSettings.newUnaryCallSettingsBuilder();

unaryMethodSettingsBuilders =
ImmutableList.<UnaryCallSettings.Builder<?, ?>>of(
setAgentSettings,
Expand All @@ -423,7 +438,8 @@ protected Builder(ClientContext clientContext) {
trainAgentSettings,
exportAgentSettings,
importAgentSettings,
restoreAgentSettings);
restoreAgentSettings,
getValidationResultSettings);

initDefaults(this);
}
Expand Down Expand Up @@ -478,6 +494,11 @@ private static Builder initDefaults(Builder builder) {
.restoreAgentSettings()
.setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("idempotent"))
.setRetrySettings(RETRY_PARAM_DEFINITIONS.get("default"));

builder
.getValidationResultSettings()
.setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("idempotent"))
.setRetrySettings(RETRY_PARAM_DEFINITIONS.get("default"));
builder
.trainAgentOperationSettings()
.setInitialCallSettings(
Expand Down Expand Up @@ -586,6 +607,7 @@ protected Builder(AgentsStubSettings settings) {
importAgentOperationSettings = settings.importAgentOperationSettings.toBuilder();
restoreAgentSettings = settings.restoreAgentSettings.toBuilder();
restoreAgentOperationSettings = settings.restoreAgentOperationSettings.toBuilder();
getValidationResultSettings = settings.getValidationResultSettings.toBuilder();

unaryMethodSettingsBuilders =
ImmutableList.<UnaryCallSettings.Builder<?, ?>>of(
Expand All @@ -596,7 +618,8 @@ protected Builder(AgentsStubSettings settings) {
trainAgentSettings,
exportAgentSettings,
importAgentSettings,
restoreAgentSettings);
restoreAgentSettings,
getValidationResultSettings);
}

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

/** Returns the builder for the settings used for calls to getValidationResult. */
public UnaryCallSettings.Builder<GetValidationResultRequest, ValidationResult>
getValidationResultSettings() {
return getValidationResultSettings;
}

@Override
public AgentsStubSettings build() throws IOException {
return new AgentsStubSettings(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,14 @@
import com.google.cloud.dialogflow.v2.ExportAgentRequest;
import com.google.cloud.dialogflow.v2.ExportAgentResponse;
import com.google.cloud.dialogflow.v2.GetAgentRequest;
import com.google.cloud.dialogflow.v2.GetValidationResultRequest;
import com.google.cloud.dialogflow.v2.ImportAgentRequest;
import com.google.cloud.dialogflow.v2.RestoreAgentRequest;
import com.google.cloud.dialogflow.v2.SearchAgentsRequest;
import com.google.cloud.dialogflow.v2.SearchAgentsResponse;
import com.google.cloud.dialogflow.v2.SetAgentRequest;
import com.google.cloud.dialogflow.v2.TrainAgentRequest;
import com.google.cloud.dialogflow.v2.ValidationResult;
import com.google.common.collect.ImmutableMap;
import com.google.longrunning.Operation;
import com.google.longrunning.stub.GrpcOperationsStub;
Expand Down Expand Up @@ -118,6 +120,15 @@ public class GrpcAgentsStub extends AgentsStub {
.setRequestMarshaller(ProtoUtils.marshaller(RestoreAgentRequest.getDefaultInstance()))
.setResponseMarshaller(ProtoUtils.marshaller(Operation.getDefaultInstance()))
.build();
private static final MethodDescriptor<GetValidationResultRequest, ValidationResult>
getValidationResultMethodDescriptor =
MethodDescriptor.<GetValidationResultRequest, ValidationResult>newBuilder()
.setType(MethodDescriptor.MethodType.UNARY)
.setFullMethodName("google.cloud.dialogflow.v2.Agents/GetValidationResult")
.setRequestMarshaller(
ProtoUtils.marshaller(GetValidationResultRequest.getDefaultInstance()))
.setResponseMarshaller(ProtoUtils.marshaller(ValidationResult.getDefaultInstance()))
.build();

private final BackgroundResource backgroundResources;
private final GrpcOperationsStub operationsStub;
Expand All @@ -137,6 +148,8 @@ public class GrpcAgentsStub extends AgentsStub {
private final OperationCallable<ImportAgentRequest, Empty, Struct> importAgentOperationCallable;
private final UnaryCallable<RestoreAgentRequest, Operation> restoreAgentCallable;
private final OperationCallable<RestoreAgentRequest, Empty, Struct> restoreAgentOperationCallable;
private final UnaryCallable<GetValidationResultRequest, ValidationResult>
getValidationResultCallable;

private final GrpcStubCallableFactory callableFactory;

Expand Down Expand Up @@ -279,6 +292,20 @@ public Map<String, String> extract(RestoreAgentRequest request) {
}
})
.build();
GrpcCallSettings<GetValidationResultRequest, ValidationResult>
getValidationResultTransportSettings =
GrpcCallSettings.<GetValidationResultRequest, ValidationResult>newBuilder()
.setMethodDescriptor(getValidationResultMethodDescriptor)
.setParamsExtractor(
new RequestParamsExtractor<GetValidationResultRequest>() {
@Override
public Map<String, String> extract(GetValidationResultRequest request) {
ImmutableMap.Builder<String, String> params = ImmutableMap.builder();
params.put("parent", String.valueOf(request.getParent()));
return params.build();
}
})
.build();

this.setAgentCallable =
callableFactory.createUnaryCallable(
Expand Down Expand Up @@ -331,6 +358,11 @@ public Map<String, String> extract(RestoreAgentRequest request) {
settings.restoreAgentOperationSettings(),
clientContext,
this.operationsStub);
this.getValidationResultCallable =
callableFactory.createUnaryCallable(
getValidationResultTransportSettings,
settings.getValidationResultSettings(),
clientContext);

backgroundResources = new BackgroundResourceAggregation(clientContext.getBackgroundResources());
}
Expand Down Expand Up @@ -397,6 +429,10 @@ public UnaryCallable<RestoreAgentRequest, Operation> restoreAgentCallable() {
return restoreAgentCallable;
}

public UnaryCallable<GetValidationResultRequest, ValidationResult> getValidationResultCallable() {
return getValidationResultCallable;
}

@Override
public final void close() {
shutdown();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -489,4 +489,41 @@ public void restoreAgentExceptionTest() throws Exception {
Assert.assertEquals(StatusCode.Code.INVALID_ARGUMENT, apiException.getStatusCode().getCode());
}
}

@Test
@SuppressWarnings("all")
public void getValidationResultTest() {
ValidationResult expectedResponse = ValidationResult.newBuilder().build();
mockAgents.addResponse(expectedResponse);

GetValidationResultRequest request = GetValidationResultRequest.newBuilder().build();

ValidationResult actualResponse = client.getValidationResult(request);
Assert.assertEquals(expectedResponse, actualResponse);

List<AbstractMessage> actualRequests = mockAgents.getRequests();
Assert.assertEquals(1, actualRequests.size());
GetValidationResultRequest actualRequest = (GetValidationResultRequest) actualRequests.get(0);

Assert.assertTrue(
channelProvider.isHeaderSent(
ApiClientHeaderProvider.getDefaultApiClientHeaderKey(),
GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}

@Test
@SuppressWarnings("all")
public void getValidationResultExceptionTest() throws Exception {
StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT);
mockAgents.addException(exception);

try {
GetValidationResultRequest request = GetValidationResultRequest.newBuilder().build();

client.getValidationResult(request);
Assert.fail("No exception raised");
} catch (InvalidArgumentException e) {
// Expected exception
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -171,4 +171,19 @@ public void restoreAgent(
responseObserver.onError(new IllegalArgumentException("Unrecognized response type"));
}
}

@Override
public void getValidationResult(
GetValidationResultRequest request, StreamObserver<ValidationResult> responseObserver) {
Object response = responses.remove();
if (response instanceof ValidationResult) {
requests.add(request);
responseObserver.onNext((ValidationResult) response);
responseObserver.onCompleted();
} else if (response instanceof Exception) {
responseObserver.onError((Exception) response);
} else {
responseObserver.onError(new IllegalArgumentException("Unrecognized response type"));
}
}
}
Loading

0 comments on commit fca7bfa

Please sign in to comment.