2525import argparse
2626import uuid
2727
28+ from google .cloud .dialogflowcx_v3beta1 .services .agents import AgentsClient
2829from google .cloud .dialogflowcx_v3beta1 .services .sessions import SessionsClient
2930from google .cloud .dialogflowcx_v3beta1 .types import audio_config
3031from google .cloud .dialogflowcx_v3beta1 .types import session
3435def run_sample ():
3536 # TODO(developer): Replace these values when running the function
3637 project_id = "YOUR-PROJECT-ID"
38+ # For more information about regionalization see https://cloud.google.com/dialogflow/cx/docs/how/region
3739 location_id = "YOUR-LOCATION-ID"
3840 # For more info on agents see https://cloud.google.com/dialogflow/cx/docs/concept/agent
3941 agent_id = "YOUR-AGENT-ID"
@@ -52,9 +54,16 @@ def detect_intent_stream(agent, session_id, audio_file_path, language_code):
5254
5355 Using the same `session_id` between requests allows continuation
5456 of the conversation."""
55- session_client = SessionsClient ()
5657 session_path = f"{ agent } /sessions/{ session_id } "
5758 print (f"Session path: { session_path } \n " )
59+ client_options = None
60+ agent_components = AgentsClient .parse_agent_path (agent )
61+ location_id = agent_components ["location" ]
62+ if location_id != "global" :
63+ api_endpoint = f"{ location_id } -dialogflow.googleapis.com:443"
64+ print (f"API Endpoint: { api_endpoint } \n " )
65+ client_options = {"api_endpoint" : api_endpoint }
66+ session_client = SessionsClient (client_options = client_options )
5867
5968 input_audio_config = audio_config .InputAudioConfig (
6069 audio_encoding = audio_config .AudioEncoding .AUDIO_ENCODING_LINEAR_16 ,
0 commit comments