11#!/usr/bin/env python
22
3- # Copyright 2021 Google LLC
3+ # Copyright 2023 Google LLC
44#
55# Licensed under the Apache License, Version 2.0 (the "License");
66# you may not use this file except in compliance with the License.
@@ -68,60 +68,59 @@ def analyze_content_text(project_id, conversation_id, participant_id, text):
6868 participant = participant_path , text_input = text_input
6969 )
7070 print ("AnalyzeContent Response:" )
71- print (f"Reply Text: { response .reply_text } " )
72- print (f"Response: { response .human_agent_suggestion_results } " )
73- # assert response.human_agent_suggestion_results=="test"
71+ print ("Reply Text: {}" .format (response .reply_text ))
72+
7473 for suggestion_result in response .human_agent_suggestion_results :
7574 if suggestion_result .error is not None :
76- print (f "Error: { suggestion_result .error .message } " )
75+ print ("Error: {}" . format ( suggestion_result .error .message ) )
7776 if suggestion_result .suggest_articles_response :
7877 for answer in suggestion_result .suggest_articles_response .article_answers :
79- print (f "Article Suggestion Answer: { answer .title } " )
80- print (f "Answer Record: { answer .answer_record } " )
78+ print ("Article Suggestion Answer: {}" . format ( answer .title ) )
79+ print ("Answer Record: {}" . format ( answer .answer_record ) )
8180 if suggestion_result .suggest_faq_answers_response :
8281 for answer in suggestion_result .suggest_faq_answers_response .faq_answers :
83- print (f "Faq Answer: { answer .answer } " )
84- print (f "Answer Record: { answer .answer_record } " )
82+ print ("Faq Answer: {}" . format ( answer .answer ) )
83+ print ("Answer Record: {}" . format ( answer .answer_record ) )
8584 if suggestion_result .suggest_smart_replies_response :
8685 for (
8786 answer
8887 ) in suggestion_result .suggest_smart_replies_response .smart_reply_answers :
89- print (f "Smart Reply: { answer .reply } " )
90- print (f "Answer Record: { answer .answer_record } " )
88+ print ("Smart Reply: {}" . format ( answer .reply ) )
89+ print ("Answer Record: {}" . format ( answer .answer_record ) )
9190
9291 for suggestion_result in response .end_user_suggestion_results :
9392 if suggestion_result .error :
9493 print ("Error: {}" .format (suggestion_result .error .message ))
9594 if suggestion_result .suggest_articles_response :
9695 for answer in suggestion_result .suggest_articles_response .article_answers :
97- print (f "Article Suggestion Answer: { answer .title } " )
98- print (f "Answer Record: { answer .answer_record } " )
96+ print ("Article Suggestion Answer: {}" . format ( answer .title ) )
97+ print ("Answer Record: {}" . format ( answer .answer_record ) )
9998 if suggestion_result .suggest_faq_answers_response :
10099 for answer in suggestion_result .suggest_faq_answers_response .faq_answers :
101- print (f "Faq Answer: { answer .answer } " )
102- print (f "Answer Record: { answer .answer_record } " )
100+ print ("Faq Answer: {}" . format ( answer .answer ) )
101+ print ("Answer Record: {}" . format ( answer .answer_record ) )
103102 if suggestion_result .suggest_smart_replies_response :
104103 for (
105104 answer
106105 ) in suggestion_result .suggest_smart_replies_response .smart_reply_answers :
107- print (f "Smart Reply: { answer .reply } " )
108- print (f "Answer Record: { answer .answer_record } " )
106+ print ("Smart Reply: {}" . format ( answer .reply ) )
107+ print ("Answer Record: {}" . format ( answer .answer_record ) )
109108
110109 return response
111110
112111
113112# [END dialogflow_analyze_content_text]
114113
115-
116- # [START dialogflow_analyze_content_audio_stream]
117- def analyze_content_audio_stream (conversation_id , participant_id , audio_file_path ):
114+ # [START dialogflow_analyze_content_audio]
115+ def analyze_content_audio (
116+ conversation_id , participant_id , audio_file_path
117+ ):
118118 """Analyze audio content for END_USER with audio files.
119119
120120 Args:
121121 conversation_id: Id of the conversation.
122122 participant_id: Id of the participant.
123- audio_file_path: audio file in wav/mp3 format contains utterances of END_USER.
124- """
123+ audio_file_path: audio file in wav/mp3 format contains utterances of END_USER."""
125124
126125 # Initialize client that will be used to send requests across threads. This
127126 # client only needs to be created once, and can be reused for multiple requests.
@@ -141,6 +140,7 @@ def analyze_content_audio_stream(conversation_id, participant_id, audio_file_pat
141140 # Generates requests based on the audio files. Will by default use the first channel as
142141 # END_USER, and second channel as HUMAN_AGENT.
143142 def request_generator (audio_config , audio_file_path ):
143+
144144 # The first request contains the configuration.
145145 yield dialogflow .StreamingAnalyzeContentRequest (
146146 participant = participant_path , audio_config = audio_config
0 commit comments