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

Commit 0d3b413

Browse files
feat(v2beta1): add the API of StreamingAnalyzeContent (#520)
* feat: add the API of StreamingAnalyzeContent PiperOrigin-RevId: 446850583 Source-Link: googleapis/googleapis@b9927eb Source-Link: https://github.com/googleapis/googleapis-gen/commit/d44285499a0e757e68d39dc18f91d2800694ad90 Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiZDQ0Mjg1NDk5YTBlNzU3ZTY4ZDM5ZGMxOGY5MWQyODAwNjk0YWQ5MCJ9 * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
1 parent 347e03f commit 0d3b413

File tree

15 files changed

+1202
-10
lines changed

15 files changed

+1202
-10
lines changed

google/cloud/dialogflow_v2beta1/__init__.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@
191191
from .types.participant import DtmfParameters
192192
from .types.participant import FaqAnswer
193193
from .types.participant import GetParticipantRequest
194+
from .types.participant import InputTextConfig
194195
from .types.participant import ListParticipantsRequest
195196
from .types.participant import ListParticipantsResponse
196197
from .types.participant import ListSuggestionsRequest
@@ -201,6 +202,8 @@
201202
from .types.participant import Participant
202203
from .types.participant import ResponseMessage
203204
from .types.participant import SmartReplyAnswer
205+
from .types.participant import StreamingAnalyzeContentRequest
206+
from .types.participant import StreamingAnalyzeContentResponse
204207
from .types.participant import SuggestArticlesRequest
205208
from .types.participant import SuggestArticlesResponse
206209
from .types.participant import SuggestFaqAnswersRequest
@@ -368,6 +371,7 @@
368371
"ImportDocumentsRequest",
369372
"ImportDocumentsResponse",
370373
"InputAudioConfig",
374+
"InputTextConfig",
371375
"Intent",
372376
"IntentBatch",
373377
"IntentView",
@@ -437,6 +441,8 @@
437441
"SpeechToTextConfig",
438442
"SpeechWordInfo",
439443
"SsmlVoiceGender",
444+
"StreamingAnalyzeContentRequest",
445+
"StreamingAnalyzeContentResponse",
440446
"StreamingDetectIntentRequest",
441447
"StreamingDetectIntentResponse",
442448
"StreamingRecognitionResult",

google/cloud/dialogflow_v2beta1/gapic_metadata.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -874,6 +874,11 @@
874874
"list_suggestions"
875875
]
876876
},
877+
"StreamingAnalyzeContent": {
878+
"methods": [
879+
"streaming_analyze_content"
880+
]
881+
},
877882
"SuggestArticles": {
878883
"methods": [
879884
"suggest_articles"
@@ -929,6 +934,11 @@
929934
"list_suggestions"
930935
]
931936
},
937+
"StreamingAnalyzeContent": {
938+
"methods": [
939+
"streaming_analyze_content"
940+
]
941+
},
932942
"SuggestArticles": {
933943
"methods": [
934944
"suggest_articles"

google/cloud/dialogflow_v2beta1/services/participants/async_client.py

Lines changed: 167 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,18 @@
1616
from collections import OrderedDict
1717
import functools
1818
import re
19-
from typing import Dict, Mapping, Optional, Sequence, Tuple, Type, Union
19+
from typing import (
20+
Dict,
21+
Mapping,
22+
Optional,
23+
AsyncIterable,
24+
Awaitable,
25+
AsyncIterator,
26+
Sequence,
27+
Tuple,
28+
Type,
29+
Union,
30+
)
2031
import pkg_resources
2132
import warnings
2233

@@ -761,6 +772,161 @@ async def sample_analyze_content():
761772
# Done; return the response.
762773
return response
763774

775+
def streaming_analyze_content(
776+
self,
777+
requests: AsyncIterator[participant.StreamingAnalyzeContentRequest] = None,
778+
*,
779+
retry: OptionalRetry = gapic_v1.method.DEFAULT,
780+
timeout: float = None,
781+
metadata: Sequence[Tuple[str, str]] = (),
782+
) -> Awaitable[AsyncIterable[participant.StreamingAnalyzeContentResponse]]:
783+
r"""Adds a text (e.g., chat) or audio (e.g., phone recording)
784+
message from a participant into the conversation. Note: This
785+
method is only available through the gRPC API (not REST).
786+
787+
The top-level message sent to the client by the server is
788+
``StreamingAnalyzeContentResponse``. Multiple response messages
789+
can be returned in order. The first one or more messages contain
790+
the ``recognition_result`` field. Each result represents a more
791+
complete transcript of what the user said. The next message
792+
contains the ``reply_text`` field, and potentially the
793+
``reply_audio`` and/or the ``automated_agent_reply`` fields.
794+
795+
Note: Always use agent versions for production traffic sent to
796+
virtual agents. See `Versions and
797+
environments <https://cloud.google.com/dialogflow/es/docs/agents-versions>`__.
798+
799+
.. code-block:: python
800+
801+
from google.cloud import dialogflow_v2beta1
802+
803+
async def sample_streaming_analyze_content():
804+
# Create a client
805+
client = dialogflow_v2beta1.ParticipantsAsyncClient()
806+
807+
# Initialize request argument(s)
808+
request = dialogflow_v2beta1.StreamingAnalyzeContentRequest(
809+
input_audio=b'input_audio_blob',
810+
participant="participant_value",
811+
)
812+
813+
# This method expects an iterator which contains
814+
# 'dialogflow_v2beta1.StreamingAnalyzeContentRequest' objects
815+
# Here we create a generator that yields a single `request` for
816+
# demonstrative purposes.
817+
requests = [request]
818+
819+
def request_generator():
820+
for request in requests:
821+
yield request
822+
823+
# Make the request
824+
stream = await client.streaming_analyze_content(requests=request_generator())
825+
826+
# Handle the response
827+
async for response in stream:
828+
print(response)
829+
830+
Args:
831+
requests (AsyncIterator[`google.cloud.dialogflow_v2beta1.types.StreamingAnalyzeContentRequest`]):
832+
The request object AsyncIterator. The top-level message sent by the
833+
client to the
834+
[Participants.StreamingAnalyzeContent][google.cloud.dialogflow.v2beta1.Participants.StreamingAnalyzeContent]
835+
method.
836+
Multiple request messages should be sent in order:
837+
838+
1. The first message must contain
839+
[participant][google.cloud.dialogflow.v2beta1.StreamingAnalyzeContentRequest.participant],
840+
[config][google.cloud.dialogflow.v2beta1.StreamingAnalyzeContentRequest.config]
841+
and optionally
842+
[query_params][google.cloud.dialogflow.v2beta1.StreamingAnalyzeContentRequest.query_params].
843+
If you want to receive an audio response, it should
844+
also contain
845+
[reply_audio_config][google.cloud.dialogflow.v2beta1.StreamingAnalyzeContentRequest.reply_audio_config].
846+
The message must not contain
847+
[input][google.cloud.dialogflow.v2beta1.StreamingAnalyzeContentRequest.input].
848+
2. If
849+
[config][google.cloud.dialogflow.v2beta1.StreamingAnalyzeContentRequest.config]
850+
in the first message was set to
851+
[audio_config][google.cloud.dialogflow.v2beta1.StreamingAnalyzeContentRequest.audio_config],
852+
all subsequent messages must contain
853+
[input_audio][google.cloud.dialogflow.v2beta1.StreamingAnalyzeContentRequest.input_audio]
854+
to continue with Speech recognition.
855+
If you decide to rather analyze text input after you
856+
already started Speech recognition, please send a
857+
message with
858+
[StreamingAnalyzeContentRequest.input_text][google.cloud.dialogflow.v2beta1.StreamingAnalyzeContentRequest.input_text].
859+
However, note that:
860+
861+
* Dialogflow will bill you for the audio so far.
862+
* Dialogflow discards all Speech recognition results
863+
in favor of the text input.
864+
865+
3. If
866+
[StreamingAnalyzeContentRequest.config][google.cloud.dialogflow.v2beta1.StreamingAnalyzeContentRequest.config]
867+
in the first message was set to
868+
[StreamingAnalyzeContentRequest.text_config][google.cloud.dialogflow.v2beta1.StreamingAnalyzeContentRequest.text_config],
869+
then the second message must contain only
870+
[input_text][google.cloud.dialogflow.v2beta1.StreamingAnalyzeContentRequest.input_text].
871+
Moreover, you must not send more than two messages.
872+
After you sent all input, you must half-close or abort
873+
the request stream.
874+
retry (google.api_core.retry.Retry): Designation of what errors, if any,
875+
should be retried.
876+
timeout (float): The timeout for this request.
877+
metadata (Sequence[Tuple[str, str]]): Strings which should be
878+
sent along with the request as metadata.
879+
880+
Returns:
881+
AsyncIterable[google.cloud.dialogflow_v2beta1.types.StreamingAnalyzeContentResponse]:
882+
The top-level message returned from the
883+
StreamingAnalyzeContent method.
884+
885+
Multiple response messages can be returned in order:
886+
887+
1. If the input was set to streaming audio, the first
888+
one or more messages contain recognition_result.
889+
Each recognition_result represents a more complete
890+
transcript of what the user said. The last
891+
recognition_result has is_final set to true.
892+
2. In virtual agent stage: if
893+
enable_partial_automated_agent_reply is true, the
894+
following N (currently 1 <= N <= 4) messages
895+
contain automated_agent_reply and optionally
896+
reply_audio returned by the virtual agent. The
897+
first (N-1) automated_agent_replys will have
898+
automated_agent_reply_type set to PARTIAL. The
899+
last automated_agent_reply has
900+
automated_agent_reply_type set to FINAL. If
901+
enable_partial_automated_agent_reply is not
902+
enabled, response stream only contains the final
903+
reply.
904+
905+
In human assist stage: the following N (N >= 1)
906+
messages contain human_agent_suggestion_results,
907+
end_user_suggestion_results or message.
908+
909+
"""
910+
911+
# Wrap the RPC method; this adds retry and timeout information,
912+
# and friendly error handling.
913+
rpc = gapic_v1.method_async.wrap_method(
914+
self._client._transport.streaming_analyze_content,
915+
default_timeout=220.0,
916+
client_info=DEFAULT_CLIENT_INFO,
917+
)
918+
919+
# Send the request.
920+
response = rpc(
921+
requests,
922+
retry=retry,
923+
timeout=timeout,
924+
metadata=metadata,
925+
)
926+
927+
# Done; return the response.
928+
return response
929+
764930
async def suggest_articles(
765931
self,
766932
request: Union[participant.SuggestArticlesRequest, dict] = None,

0 commit comments

Comments
 (0)