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

feat: support document metadata filter in article suggestion #442

Merged
merged 2 commits into from
Nov 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions google/cloud/dialogflow_v2beta1/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@
from .types.participant import AnalyzeContentResponse
from .types.participant import AnnotatedMessagePart
from .types.participant import ArticleAnswer
from .types.participant import AssistQueryParameters
from .types.participant import AutomatedAgentReply
from .types.participant import CompileSuggestionRequest
from .types.participant import CompileSuggestionResponse
Expand Down Expand Up @@ -265,6 +266,7 @@
"AnswerRecord",
"AnswerRecordsClient",
"ArticleAnswer",
"AssistQueryParameters",
"AudioEncoding",
"AutomatedAgentConfig",
"AutomatedAgentReply",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ async def list_participants(
Returns:
google.cloud.dialogflow_v2beta1.services.participants.pagers.ListParticipantsAsyncPager:
The response message for
[Participants.ListParticipants][google.cloud.dialogflow.v2beta1.Participants.ListParticipants].
[Participants.ListParticipants][google.cloud.dialogflow.v2beta1.Participants.ListParticipants].

Iterating over this object will yield results and
resolve additional pages automatically.
Expand Down Expand Up @@ -545,7 +545,7 @@ async def analyze_content(
Returns:
google.cloud.dialogflow_v2beta1.types.AnalyzeContentResponse:
The response message for
[Participants.AnalyzeContent][google.cloud.dialogflow.v2beta1.Participants.AnalyzeContent].
[Participants.AnalyzeContent][google.cloud.dialogflow.v2beta1.Participants.AnalyzeContent].

"""
# Create or coerce a protobuf request object.
Expand Down Expand Up @@ -640,7 +640,7 @@ async def suggest_articles(
Returns:
google.cloud.dialogflow_v2beta1.types.SuggestArticlesResponse:
The response message for
[Participants.SuggestArticles][google.cloud.dialogflow.v2beta1.Participants.SuggestArticles].
[Participants.SuggestArticles][google.cloud.dialogflow.v2beta1.Participants.SuggestArticles].

"""
# Create or coerce a protobuf request object.
Expand Down Expand Up @@ -713,7 +713,7 @@ async def suggest_faq_answers(
Returns:
google.cloud.dialogflow_v2beta1.types.SuggestFaqAnswersResponse:
The request message for
[Participants.SuggestFaqAnswers][google.cloud.dialogflow.v2beta1.Participants.SuggestFaqAnswers].
[Participants.SuggestFaqAnswers][google.cloud.dialogflow.v2beta1.Participants.SuggestFaqAnswers].

"""
# Create or coerce a protobuf request object.
Expand Down Expand Up @@ -786,7 +786,7 @@ async def suggest_smart_replies(
Returns:
google.cloud.dialogflow_v2beta1.types.SuggestSmartRepliesResponse:
The response message for
[Participants.SuggestSmartReplies][google.cloud.dialogflow.v2beta1.Participants.SuggestSmartReplies].
[Participants.SuggestSmartReplies][google.cloud.dialogflow.v2beta1.Participants.SuggestSmartReplies].

"""
# Create or coerce a protobuf request object.
Expand Down Expand Up @@ -868,7 +868,7 @@ async def list_suggestions(
Returns:
google.cloud.dialogflow_v2beta1.services.participants.pagers.ListSuggestionsAsyncPager:
The response message for
[Participants.ListSuggestions][google.cloud.dialogflow.v2beta1.Participants.ListSuggestions].
[Participants.ListSuggestions][google.cloud.dialogflow.v2beta1.Participants.ListSuggestions].

Iterating over this object will yield results and
resolve additional pages automatically.
Expand Down Expand Up @@ -944,7 +944,7 @@ async def compile_suggestion(
Returns:
google.cloud.dialogflow_v2beta1.types.CompileSuggestionResponse:
The response message for
[Participants.CompileSuggestion][google.cloud.dialogflow.v2beta1.Participants.CompileSuggestion].
[Participants.CompileSuggestion][google.cloud.dialogflow.v2beta1.Participants.CompileSuggestion].

"""
warnings.warn(
Expand Down
14 changes: 7 additions & 7 deletions google/cloud/dialogflow_v2beta1/services/participants/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -623,7 +623,7 @@ def list_participants(
Returns:
google.cloud.dialogflow_v2beta1.services.participants.pagers.ListParticipantsPager:
The response message for
[Participants.ListParticipants][google.cloud.dialogflow.v2beta1.Participants.ListParticipants].
[Participants.ListParticipants][google.cloud.dialogflow.v2beta1.Participants.ListParticipants].

Iterating over this object will yield results and
resolve additional pages automatically.
Expand Down Expand Up @@ -804,7 +804,7 @@ def analyze_content(
Returns:
google.cloud.dialogflow_v2beta1.types.AnalyzeContentResponse:
The response message for
[Participants.AnalyzeContent][google.cloud.dialogflow.v2beta1.Participants.AnalyzeContent].
[Participants.AnalyzeContent][google.cloud.dialogflow.v2beta1.Participants.AnalyzeContent].

"""
# Create or coerce a protobuf request object.
Expand Down Expand Up @@ -890,7 +890,7 @@ def suggest_articles(
Returns:
google.cloud.dialogflow_v2beta1.types.SuggestArticlesResponse:
The response message for
[Participants.SuggestArticles][google.cloud.dialogflow.v2beta1.Participants.SuggestArticles].
[Participants.SuggestArticles][google.cloud.dialogflow.v2beta1.Participants.SuggestArticles].

"""
# Create or coerce a protobuf request object.
Expand Down Expand Up @@ -963,7 +963,7 @@ def suggest_faq_answers(
Returns:
google.cloud.dialogflow_v2beta1.types.SuggestFaqAnswersResponse:
The request message for
[Participants.SuggestFaqAnswers][google.cloud.dialogflow.v2beta1.Participants.SuggestFaqAnswers].
[Participants.SuggestFaqAnswers][google.cloud.dialogflow.v2beta1.Participants.SuggestFaqAnswers].

"""
# Create or coerce a protobuf request object.
Expand Down Expand Up @@ -1036,7 +1036,7 @@ def suggest_smart_replies(
Returns:
google.cloud.dialogflow_v2beta1.types.SuggestSmartRepliesResponse:
The response message for
[Participants.SuggestSmartReplies][google.cloud.dialogflow.v2beta1.Participants.SuggestSmartReplies].
[Participants.SuggestSmartReplies][google.cloud.dialogflow.v2beta1.Participants.SuggestSmartReplies].

"""
# Create or coerce a protobuf request object.
Expand Down Expand Up @@ -1118,7 +1118,7 @@ def list_suggestions(
Returns:
google.cloud.dialogflow_v2beta1.services.participants.pagers.ListSuggestionsPager:
The response message for
[Participants.ListSuggestions][google.cloud.dialogflow.v2beta1.Participants.ListSuggestions].
[Participants.ListSuggestions][google.cloud.dialogflow.v2beta1.Participants.ListSuggestions].

Iterating over this object will yield results and
resolve additional pages automatically.
Expand Down Expand Up @@ -1195,7 +1195,7 @@ def compile_suggestion(
Returns:
google.cloud.dialogflow_v2beta1.types.CompileSuggestionResponse:
The response message for
[Participants.CompileSuggestion][google.cloud.dialogflow.v2beta1.Participants.CompileSuggestion].
[Participants.CompileSuggestion][google.cloud.dialogflow.v2beta1.Participants.CompileSuggestion].

"""
warnings.warn(
Expand Down
2 changes: 2 additions & 0 deletions google/cloud/dialogflow_v2beta1/types/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@
AnalyzeContentResponse,
AnnotatedMessagePart,
ArticleAnswer,
AssistQueryParameters,
AutomatedAgentReply,
CompileSuggestionRequest,
CompileSuggestionResponse,
Expand Down Expand Up @@ -377,6 +378,7 @@
"AnalyzeContentResponse",
"AnnotatedMessagePart",
"ArticleAnswer",
"AssistQueryParameters",
"AutomatedAgentReply",
"CompileSuggestionRequest",
"CompileSuggestionResponse",
Expand Down
69 changes: 69 additions & 0 deletions google/cloud/dialogflow_v2beta1/types/participant.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"OutputAudio",
"AutomatedAgentReply",
"SuggestionFeature",
"AssistQueryParameters",
"AnalyzeContentRequest",
"DtmfParameters",
"AnalyzeContentResponse",
Expand Down Expand Up @@ -109,6 +110,27 @@ class Participant(proto.Message):
- Dialogflow only accepts a UTF-8 encoded string, e.g., a
hex digest of a hash function like SHA-512.
- The length of the user id must be <= 256 characters.
documents_metadata_filters (Sequence[google.cloud.dialogflow_v2beta1.types.Participant.DocumentsMetadataFiltersEntry]):
Optional. Key-value filters on the metadata of documents
returned by article suggestion. If specified, article
suggestion only returns suggested documents that match all
filters in their
[Document.metadata][google.cloud.dialogflow.v2beta1.Document.metadata].
Multiple values for a metadata key should be concatenated by
comma. For example, filters to match all documents that have
'US' or 'CA' in their market metadata values and 'agent' in
their user metadata values will be

::

documents_metadata_filters {
key: "market"
value: "US,CA"
}
documents_metadata_filters {
key: "user"
value: "agent"
}
"""

class Role(proto.Enum):
Expand All @@ -123,6 +145,7 @@ class Role(proto.Enum):
name = proto.Field(proto.STRING, number=1,)
role = proto.Field(proto.ENUM, number=2, enum=Role,)
obfuscated_external_user_id = proto.Field(proto.STRING, number=7,)
documents_metadata_filters = proto.MapField(proto.STRING, proto.STRING, number=8,)


class Message(proto.Message):
Expand Down Expand Up @@ -385,6 +408,35 @@ class Type(proto.Enum):
type_ = proto.Field(proto.ENUM, number=1, enum=Type,)


class AssistQueryParameters(proto.Message):
r"""Represents the parameters of human assist query.

Attributes:
documents_metadata_filters (Sequence[google.cloud.dialogflow_v2beta1.types.AssistQueryParameters.DocumentsMetadataFiltersEntry]):
Key-value filters on the metadata of documents returned by
article suggestion. If specified, article suggestion only
returns suggested documents that match all filters in their
[Document.metadata][google.cloud.dialogflow.v2beta1.Document.metadata].
Multiple values for a metadata key should be concatenated by
comma. For example, filters to match all documents that have
'US' or 'CA' in their market metadata values and 'agent' in
their user metadata values will be

::

documents_metadata_filters {
key: "market"
value: "US,CA"
}
documents_metadata_filters {
key: "user"
value: "agent"
}
"""

documents_metadata_filters = proto.MapField(proto.STRING, proto.STRING, number=1,)


class AnalyzeContentRequest(proto.Message):
r"""The request message for
[Participants.AnalyzeContent][google.cloud.dialogflow.v2beta1.Participants.AnalyzeContent].
Expand Down Expand Up @@ -419,6 +471,8 @@ class AnalyzeContentRequest(proto.Message):
query_params (google.cloud.dialogflow_v2beta1.types.QueryParameters):
Parameters for a Dialogflow virtual-agent
query.
assist_query_params (google.cloud.dialogflow_v2beta1.types.AssistQueryParameters):
Parameters for a human assist query.
message_send_time (google.protobuf.timestamp_pb2.Timestamp):
Optional. The send time of the message from
end user or human agent's perspective. It is
Expand Down Expand Up @@ -456,6 +510,9 @@ class AnalyzeContentRequest(proto.Message):
query_params = proto.Field(
proto.MESSAGE, number=9, message=session.QueryParameters,
)
assist_query_params = proto.Field(
proto.MESSAGE, number=14, message="AssistQueryParameters",
)
message_send_time = proto.Field(
proto.MESSAGE, number=10, message=timestamp_pb2.Timestamp,
)
Expand Down Expand Up @@ -756,11 +813,17 @@ class SuggestArticlesRequest(proto.Message):
[latest_message][google.cloud.dialogflow.v2beta1.SuggestArticlesRequest.latest_message]
to use as context when compiling the suggestion. By default
20 and at most 50.
assist_query_params (google.cloud.dialogflow_v2beta1.types.AssistQueryParameters):
Optional. Parameters for a human assist
query.
"""

parent = proto.Field(proto.STRING, number=1,)
latest_message = proto.Field(proto.STRING, number=2,)
context_size = proto.Field(proto.INT32, number=3,)
assist_query_params = proto.Field(
proto.MESSAGE, number=4, message="AssistQueryParameters",
)


class SuggestArticlesResponse(proto.Message):
Expand Down Expand Up @@ -813,11 +876,17 @@ class SuggestFaqAnswersRequest(proto.Message):
Optional. Max number of messages prior to and including
[latest_message] to use as context when compiling the
suggestion. By default 20 and at most 50.
assist_query_params (google.cloud.dialogflow_v2beta1.types.AssistQueryParameters):
Optional. Parameters for a human assist
query.
"""

parent = proto.Field(proto.STRING, number=1,)
latest_message = proto.Field(proto.STRING, number=2,)
context_size = proto.Field(proto.INT32, number=3,)
assist_query_params = proto.Field(
proto.MESSAGE, number=4, message="AssistQueryParameters",
)


class SuggestFaqAnswersResponse(proto.Message):
Expand Down
6 changes: 3 additions & 3 deletions scripts/fixup_dialogflow_v2beta1_keywords.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def partition(
class dialogflowCallTransformer(cst.CSTTransformer):
CTRL_PARAMS: Tuple[str] = ('retry', 'timeout', 'metadata')
METHOD_TO_PARAMS: Dict[str, Tuple[str]] = {
'analyze_content': ('participant', 'text_input', 'event_input', 'reply_audio_config', 'query_params', 'message_send_time', 'request_id', ),
'analyze_content': ('participant', 'text_input', 'event_input', 'reply_audio_config', 'query_params', 'assist_query_params', 'message_send_time', 'request_id', ),
'batch_create_entities': ('parent', 'entities', 'language_code', ),
'batch_create_messages': ('parent', 'requests', ),
'batch_delete_entities': ('parent', 'entity_values', 'language_code', ),
Expand Down Expand Up @@ -111,8 +111,8 @@ class dialogflowCallTransformer(cst.CSTTransformer):
'search_agents': ('parent', 'page_size', 'page_token', ),
'set_agent': ('agent', 'update_mask', ),
'streaming_detect_intent': ('session', 'query_input', 'query_params', 'single_utterance', 'output_audio_config', 'output_audio_config_mask', 'input_audio', ),
'suggest_articles': ('parent', 'latest_message', 'context_size', ),
'suggest_faq_answers': ('parent', 'latest_message', 'context_size', ),
'suggest_articles': ('parent', 'latest_message', 'context_size', 'assist_query_params', ),
'suggest_faq_answers': ('parent', 'latest_message', 'context_size', 'assist_query_params', ),
'suggest_smart_replies': ('parent', 'current_text_input', 'latest_message', 'context_size', ),
'train_agent': ('parent', ),
'update_answer_record': ('answer_record', 'update_mask', ),
Expand Down