python API 无法在 Dialogflow v2 中显示列表意图的非英语语言 API
python API cant show non English language of list intents API in Dialogflow v2
我写了 python API 可以与 Dialogflow 引擎交互,return 我写了 Dialogflow 的意图列表。代码如下:
def get(self, intent_id=None, get_child=None):
try:
print("ManageIntents get method api is called")
global global_intent_list
global is_parent
if get_child is not None:
return jsonify(self.get_children(intent_id))
# retry: Union[google.api_core.retry.Retry,
# timeout: Optional[float] = None
i = 0
if intent_id is None and len(global_intent_list) <= 0:
intents_client = dialogflow.IntentsClient()
parent = dialogflow.AgentsClient.agent_path(project_id)
intents = intents_client.list_intents(request={"parent": parent, "intent_view": 'INTENT_VIEW_FULL'})
for intent in intents:
print(i)
i = i + 1
intent_info = self.get_intent_data(intent)
global_intent_list.append(intent_info)
json_response = jsonify(global_intent_list)
return json_response
# return "success"
elif intent_id is None and len(global_intent_list) > 0:
json_response = jsonify(global_intent_list)
return json_response
else:
intents_client = dialogflow.IntentsClient()
intent_name = intents_client.intent_path(project_id, intent_id)
intent = intents_client.get_intent(request={"name": intent_name, "intent_view": 'INTENT_VIEW_FULL'})
# response_dictionary = self.get_intent_data(intent)
return jsonify(self.get_intent_data(intent))
except Exception as e:
print(e)
return str(e)
但是当我看到非英语语言意图时,我可以发现如果请求是 "আমি কি ১০ টাকার অ্যাকাউন্ট খুলতে পারবো"
,则响应是 "0650730670"
。我怎样才能解码这个响应?请帮助我。
您的回复 "0650730670"
类似于 escape sequence in string literal (类似于 但是不是从字符串中获取的操纵):
Escape Sequence Meaning
\ooo Character with octal value ooo (up to three octal digits)
我无法从您的代码片段中重现您的响应;因此,我的回答基于 hard-coded 数据,并详细说明了 Python specific text encodings raw_unicode_escape
and unicode_escape
的工作原理:
test_string = r"065073067" # hard-coded
print('test_string ', test_string)
print('.encode("raw_unicode_escape")',
test_string.encode( 'raw_unicode_escape'))
print('.decode( "unicode_escape")',
test_string.encode( 'raw_unicode_escape').decode( 'unicode_escape'))
print('.encode("latin1").decode() ',
test_string.encode( 'raw_unicode_escape').decode( 'unicode_escape').
encode( 'latin1').decode( 'utf-8'))
输出:.\SO347302.py
test_string 065073067
.encode("raw_unicode_escape") b'\340\246\225\340\247\203\340\246\267'
.decode( "unicode_escape") à¦à§à¦·
.encode("latin1").decode() কৃষ
我写了 python API 可以与 Dialogflow 引擎交互,return 我写了 Dialogflow 的意图列表。代码如下:
def get(self, intent_id=None, get_child=None):
try:
print("ManageIntents get method api is called")
global global_intent_list
global is_parent
if get_child is not None:
return jsonify(self.get_children(intent_id))
# retry: Union[google.api_core.retry.Retry,
# timeout: Optional[float] = None
i = 0
if intent_id is None and len(global_intent_list) <= 0:
intents_client = dialogflow.IntentsClient()
parent = dialogflow.AgentsClient.agent_path(project_id)
intents = intents_client.list_intents(request={"parent": parent, "intent_view": 'INTENT_VIEW_FULL'})
for intent in intents:
print(i)
i = i + 1
intent_info = self.get_intent_data(intent)
global_intent_list.append(intent_info)
json_response = jsonify(global_intent_list)
return json_response
# return "success"
elif intent_id is None and len(global_intent_list) > 0:
json_response = jsonify(global_intent_list)
return json_response
else:
intents_client = dialogflow.IntentsClient()
intent_name = intents_client.intent_path(project_id, intent_id)
intent = intents_client.get_intent(request={"name": intent_name, "intent_view": 'INTENT_VIEW_FULL'})
# response_dictionary = self.get_intent_data(intent)
return jsonify(self.get_intent_data(intent))
except Exception as e:
print(e)
return str(e)
但是当我看到非英语语言意图时,我可以发现如果请求是 "আমি কি ১০ টাকার অ্যাকাউন্ট খুলতে পারবো"
,则响应是 "0650730670"
。我怎样才能解码这个响应?请帮助我。
您的回复 "0650730670"
类似于 escape sequence in string literal (类似于 但是不是从字符串中获取的操纵):
Escape Sequence Meaning \ooo Character with octal value ooo (up to three octal digits)
我无法从您的代码片段中重现您的响应;因此,我的回答基于 hard-coded 数据,并详细说明了 Python specific text encodings raw_unicode_escape
and unicode_escape
的工作原理:
test_string = r"065073067" # hard-coded
print('test_string ', test_string)
print('.encode("raw_unicode_escape")',
test_string.encode( 'raw_unicode_escape'))
print('.decode( "unicode_escape")',
test_string.encode( 'raw_unicode_escape').decode( 'unicode_escape'))
print('.encode("latin1").decode() ',
test_string.encode( 'raw_unicode_escape').decode( 'unicode_escape').
encode( 'latin1').decode( 'utf-8'))
输出:.\SO347302.py
test_string 065073067 .encode("raw_unicode_escape") b'\340\246\225\340\247\203\340\246\267' .decode( "unicode_escape") à¦à§à¦· .encode("latin1").decode() কৃষ