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

feat: add the API of StreamingAnalyzeContent #925

Merged
merged 8 commits into from
May 9, 2022
Original file line number Diff line number Diff line change
Expand Up @@ -801,6 +801,7 @@ public final AnalyzeContentResponse analyzeContent(String participant, TextInput
* .setReplyAudioConfig(OutputAudioConfig.newBuilder().build())
* .setQueryParams(QueryParameters.newBuilder().build())
* .setAssistQueryParams(AssistQueryParameters.newBuilder().build())
* .setCxParameters(Struct.newBuilder().build())
* .setRequestId("requestId693933066")
* .build();
* AnalyzeContentResponse response = participantsClient.analyzeContent(request);
Expand Down Expand Up @@ -837,6 +838,7 @@ public final AnalyzeContentResponse analyzeContent(AnalyzeContentRequest request
* .setReplyAudioConfig(OutputAudioConfig.newBuilder().build())
* .setQueryParams(QueryParameters.newBuilder().build())
* .setAssistQueryParams(AssistQueryParameters.newBuilder().build())
* .setCxParameters(Struct.newBuilder().build())
* .setRequestId("requestId693933066")
* .build();
* ApiFuture<AnalyzeContentResponse> future =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,9 @@ public FulfillmentsStub getStub() {
* }
* }</pre>
*
* @param name Required. The name of the fulfillment. Supported formats: - `projects/&lt;Project
* ID&gt;/agent/fulfillment` - `projects/&lt;Project ID&gt;/locations/&lt;Location
* ID&gt;/agent/fulfillment`
* @param name Required. The name of the fulfillment. Supported formats:
* <p>- `projects/&lt;Project ID&gt;/agent/fulfillment` - `projects/&lt;Project
* ID&gt;/locations/&lt;Location ID&gt;/agent/fulfillment`
* @throws com.google.api.gax.rpc.ApiException if the remote call fails
*/
public final Fulfillment getFulfillment(FulfillmentName name) {
Expand All @@ -187,9 +187,9 @@ public final Fulfillment getFulfillment(FulfillmentName name) {
* }
* }</pre>
*
* @param name Required. The name of the fulfillment. Supported formats: - `projects/&lt;Project
* ID&gt;/agent/fulfillment` - `projects/&lt;Project ID&gt;/locations/&lt;Location
* ID&gt;/agent/fulfillment`
* @param name Required. The name of the fulfillment. Supported formats:
* <p>- `projects/&lt;Project ID&gt;/agent/fulfillment` - `projects/&lt;Project
* ID&gt;/locations/&lt;Location ID&gt;/agent/fulfillment`
* @throws com.google.api.gax.rpc.ApiException if the remote call fails
*/
public final Fulfillment getFulfillment(String name) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import com.google.api.gax.paging.AbstractFixedSizeCollection;
import com.google.api.gax.paging.AbstractPage;
import com.google.api.gax.paging.AbstractPagedListResponse;
import com.google.api.gax.rpc.BidiStreamingCallable;
import com.google.api.gax.rpc.PageContext;
import com.google.api.gax.rpc.UnaryCallable;
import com.google.cloud.dialogflow.v2beta1.stub.ParticipantsStub;
Expand Down Expand Up @@ -803,6 +804,7 @@ public final AnalyzeContentResponse analyzeContent(String participant, TextInput
* .setReplyAudioConfig(OutputAudioConfig.newBuilder().build())
* .setQueryParams(QueryParameters.newBuilder().build())
* .setAssistQueryParams(AssistQueryParameters.newBuilder().build())
* .setCxParameters(Struct.newBuilder().build())
* .setMessageSendTime(Timestamp.newBuilder().build())
* .setRequestId("requestId693933066")
* .build();
Expand Down Expand Up @@ -840,6 +842,7 @@ public final AnalyzeContentResponse analyzeContent(AnalyzeContentRequest request
* .setReplyAudioConfig(OutputAudioConfig.newBuilder().build())
* .setQueryParams(QueryParameters.newBuilder().build())
* .setAssistQueryParams(AssistQueryParameters.newBuilder().build())
* .setCxParameters(Struct.newBuilder().build())
* .setMessageSendTime(Timestamp.newBuilder().build())
* .setRequestId("requestId693933066")
* .build();
Expand All @@ -855,6 +858,53 @@ public final AnalyzeContentResponse analyzeContent(AnalyzeContentRequest request
return stub.analyzeContentCallable();
}

// AUTO-GENERATED DOCUMENTATION AND METHOD.
/**
* Adds a text (e.g., chat) or audio (e.g., phone recording) message from a participant into the
* conversation. Note: This method is only available through the gRPC API (not REST).
*
* <p>The top-level message sent to the client by the server is `StreamingAnalyzeContentResponse`.
* Multiple response messages can be returned in order. The first one or more messages contain the
* `recognition_result` field. Each result represents a more complete transcript of what the user
* said. The next message contains the `reply_text` field, and potentially the `reply_audio`
* and/or the `automated_agent_reply` fields.
*
* <p>Note: Always use agent versions for production traffic sent to virtual agents. See [Versions
* and environments](https://cloud.google.com/dialogflow/es/docs/agents-versions).
*
* <p>Sample code:
*
* <pre>{@code
* // This snippet has been automatically generated for illustrative purposes only.
* // It may require modifications to work in your environment.
* try (ParticipantsClient participantsClient = ParticipantsClient.create()) {
* BidiStream<StreamingAnalyzeContentRequest, StreamingAnalyzeContentResponse> bidiStream =
* participantsClient.streamingAnalyzeContentCallable().call();
* StreamingAnalyzeContentRequest request =
* StreamingAnalyzeContentRequest.newBuilder()
* .setParticipant(
* ParticipantName.ofProjectConversationParticipantName(
* "[PROJECT]", "[CONVERSATION]", "[PARTICIPANT]")
* .toString())
* .setReplyAudioConfig(OutputAudioConfig.newBuilder().build())
* .setQueryParams(QueryParameters.newBuilder().build())
* .setAssistQueryParams(AssistQueryParameters.newBuilder().build())
* .setCxParameters(Struct.newBuilder().build())
* .setEnablePartialAutomatedAgentReply(true)
* .build();
* bidiStream.send(request);
* for (StreamingAnalyzeContentResponse response : bidiStream) {
* // Do something when a response is received.
* }
* }
* }</pre>
*/
public final BidiStreamingCallable<
StreamingAnalyzeContentRequest, StreamingAnalyzeContentResponse>
streamingAnalyzeContentCallable() {
return stub.streamingAnalyzeContentCallable();
}

// AUTO-GENERATED DOCUMENTATION AND METHOD.
/**
* Gets suggested articles for a participant based on specific historical messages.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import com.google.api.gax.rpc.ClientContext;
import com.google.api.gax.rpc.ClientSettings;
import com.google.api.gax.rpc.PagedCallSettings;
import com.google.api.gax.rpc.StreamingCallSettings;
import com.google.api.gax.rpc.TransportChannelProvider;
import com.google.api.gax.rpc.UnaryCallSettings;
import com.google.cloud.dialogflow.v2beta1.stub.ParticipantsStubSettings;
Expand Down Expand Up @@ -99,6 +100,12 @@ public UnaryCallSettings<AnalyzeContentRequest, AnalyzeContentResponse> analyzeC
return ((ParticipantsStubSettings) getStubSettings()).analyzeContentSettings();
}

/** Returns the object with the settings used for calls to streamingAnalyzeContent. */
public StreamingCallSettings<StreamingAnalyzeContentRequest, StreamingAnalyzeContentResponse>
streamingAnalyzeContentSettings() {
return ((ParticipantsStubSettings) getStubSettings()).streamingAnalyzeContentSettings();
}

/** Returns the object with the settings used for calls to suggestArticles. */
public UnaryCallSettings<SuggestArticlesRequest, SuggestArticlesResponse>
suggestArticlesSettings() {
Expand Down Expand Up @@ -267,6 +274,13 @@ public UnaryCallSettings.Builder<GetParticipantRequest, Participant> getParticip
return getStubSettingsBuilder().analyzeContentSettings();
}

/** Returns the builder for the settings used for calls to streamingAnalyzeContent. */
public StreamingCallSettings.Builder<
StreamingAnalyzeContentRequest, StreamingAnalyzeContentResponse>
streamingAnalyzeContentSettings() {
return getStubSettingsBuilder().streamingAnalyzeContentSettings();
}

/** Returns the builder for the settings used for calls to suggestArticles. */
public UnaryCallSettings.Builder<SuggestArticlesRequest, SuggestArticlesResponse>
suggestArticlesSettings() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,9 @@
"ListSuggestions": {
"methods": ["listSuggestions", "listSuggestionsPagedCallable", "listSuggestionsCallable"]
},
"StreamingAnalyzeContent": {
"methods": ["streamingAnalyzeContentCallable"]
},
"SuggestArticles": {
"methods": ["suggestArticles", "suggestArticles", "suggestArticles", "suggestArticlesCallable"]
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import com.google.api.gax.core.BackgroundResourceAggregation;
import com.google.api.gax.grpc.GrpcCallSettings;
import com.google.api.gax.grpc.GrpcStubCallableFactory;
import com.google.api.gax.rpc.BidiStreamingCallable;
import com.google.api.gax.rpc.ClientContext;
import com.google.api.gax.rpc.UnaryCallable;
import com.google.cloud.dialogflow.v2beta1.AnalyzeContentRequest;
Expand All @@ -37,6 +38,8 @@
import com.google.cloud.dialogflow.v2beta1.ListSuggestionsRequest;
import com.google.cloud.dialogflow.v2beta1.ListSuggestionsResponse;
import com.google.cloud.dialogflow.v2beta1.Participant;
import com.google.cloud.dialogflow.v2beta1.StreamingAnalyzeContentRequest;
import com.google.cloud.dialogflow.v2beta1.StreamingAnalyzeContentResponse;
import com.google.cloud.dialogflow.v2beta1.SuggestArticlesRequest;
import com.google.cloud.dialogflow.v2beta1.SuggestArticlesResponse;
import com.google.cloud.dialogflow.v2beta1.SuggestFaqAnswersRequest;
Expand Down Expand Up @@ -113,6 +116,20 @@ public class GrpcParticipantsStub extends ParticipantsStub {
ProtoUtils.marshaller(AnalyzeContentResponse.getDefaultInstance()))
.build();

private static final MethodDescriptor<
StreamingAnalyzeContentRequest, StreamingAnalyzeContentResponse>
streamingAnalyzeContentMethodDescriptor =
MethodDescriptor
.<StreamingAnalyzeContentRequest, StreamingAnalyzeContentResponse>newBuilder()
.setType(MethodDescriptor.MethodType.BIDI_STREAMING)
.setFullMethodName(
"google.cloud.dialogflow.v2beta1.Participants/StreamingAnalyzeContent")
.setRequestMarshaller(
ProtoUtils.marshaller(StreamingAnalyzeContentRequest.getDefaultInstance()))
.setResponseMarshaller(
ProtoUtils.marshaller(StreamingAnalyzeContentResponse.getDefaultInstance()))
.build();

private static final MethodDescriptor<SuggestArticlesRequest, SuggestArticlesResponse>
suggestArticlesMethodDescriptor =
MethodDescriptor.<SuggestArticlesRequest, SuggestArticlesResponse>newBuilder()
Expand Down Expand Up @@ -176,6 +193,9 @@ public class GrpcParticipantsStub extends ParticipantsStub {
listParticipantsPagedCallable;
private final UnaryCallable<UpdateParticipantRequest, Participant> updateParticipantCallable;
private final UnaryCallable<AnalyzeContentRequest, AnalyzeContentResponse> analyzeContentCallable;
private final BidiStreamingCallable<
StreamingAnalyzeContentRequest, StreamingAnalyzeContentResponse>
streamingAnalyzeContentCallable;
private final UnaryCallable<SuggestArticlesRequest, SuggestArticlesResponse>
suggestArticlesCallable;
private final UnaryCallable<SuggestFaqAnswersRequest, SuggestFaqAnswersResponse>
Expand Down Expand Up @@ -284,6 +304,12 @@ protected GrpcParticipantsStub(
return params.build();
})
.build();
GrpcCallSettings<StreamingAnalyzeContentRequest, StreamingAnalyzeContentResponse>
streamingAnalyzeContentTransportSettings =
GrpcCallSettings
.<StreamingAnalyzeContentRequest, StreamingAnalyzeContentResponse>newBuilder()
.setMethodDescriptor(streamingAnalyzeContentMethodDescriptor)
.build();
GrpcCallSettings<SuggestArticlesRequest, SuggestArticlesResponse>
suggestArticlesTransportSettings =
GrpcCallSettings.<SuggestArticlesRequest, SuggestArticlesResponse>newBuilder()
Expand Down Expand Up @@ -362,6 +388,11 @@ protected GrpcParticipantsStub(
this.analyzeContentCallable =
callableFactory.createUnaryCallable(
analyzeContentTransportSettings, settings.analyzeContentSettings(), clientContext);
this.streamingAnalyzeContentCallable =
callableFactory.createBidiStreamingCallable(
streamingAnalyzeContentTransportSettings,
settings.streamingAnalyzeContentSettings(),
clientContext);
this.suggestArticlesCallable =
callableFactory.createUnaryCallable(
suggestArticlesTransportSettings, settings.suggestArticlesSettings(), clientContext);
Expand Down Expand Up @@ -427,6 +458,12 @@ public UnaryCallable<AnalyzeContentRequest, AnalyzeContentResponse> analyzeConte
return analyzeContentCallable;
}

@Override
public BidiStreamingCallable<StreamingAnalyzeContentRequest, StreamingAnalyzeContentResponse>
streamingAnalyzeContentCallable() {
return streamingAnalyzeContentCallable;
}

@Override
public UnaryCallable<SuggestArticlesRequest, SuggestArticlesResponse> suggestArticlesCallable() {
return suggestArticlesCallable;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import com.google.api.core.BetaApi;
import com.google.api.gax.core.BackgroundResource;
import com.google.api.gax.rpc.BidiStreamingCallable;
import com.google.api.gax.rpc.UnaryCallable;
import com.google.cloud.dialogflow.v2beta1.AnalyzeContentRequest;
import com.google.cloud.dialogflow.v2beta1.AnalyzeContentResponse;
Expand All @@ -33,6 +34,8 @@
import com.google.cloud.dialogflow.v2beta1.ListSuggestionsRequest;
import com.google.cloud.dialogflow.v2beta1.ListSuggestionsResponse;
import com.google.cloud.dialogflow.v2beta1.Participant;
import com.google.cloud.dialogflow.v2beta1.StreamingAnalyzeContentRequest;
import com.google.cloud.dialogflow.v2beta1.StreamingAnalyzeContentResponse;
import com.google.cloud.dialogflow.v2beta1.SuggestArticlesRequest;
import com.google.cloud.dialogflow.v2beta1.SuggestArticlesResponse;
import com.google.cloud.dialogflow.v2beta1.SuggestFaqAnswersRequest;
Expand Down Expand Up @@ -78,6 +81,11 @@ public UnaryCallable<AnalyzeContentRequest, AnalyzeContentResponse> analyzeConte
throw new UnsupportedOperationException("Not implemented: analyzeContentCallable()");
}

public BidiStreamingCallable<StreamingAnalyzeContentRequest, StreamingAnalyzeContentResponse>
streamingAnalyzeContentCallable() {
throw new UnsupportedOperationException("Not implemented: streamingAnalyzeContentCallable()");
}

public UnaryCallable<SuggestArticlesRequest, SuggestArticlesResponse> suggestArticlesCallable() {
throw new UnsupportedOperationException("Not implemented: suggestArticlesCallable()");
}
Expand Down
Loading