Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/api/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python中的Dialogflow API访问后续意图_Python_Api_Dialogflow Es - Fatal编程技术网

Python中的Dialogflow API访问后续意图

Python中的Dialogflow API访问后续意图,python,api,dialogflow-es,Python,Api,Dialogflow Es,我遵循以下教程来理解Dialogflow Python API 以下是我的改编作品: import dialogflow_v2 as dialogflow import json from google.api_core.exceptions import InvalidArgument from google.oauth2 import service_account dialogflow_key = json.load(open(r'path_to_json_file.json')) cr

我遵循以下教程来理解Dialogflow Python API

以下是我的改编作品:

import dialogflow_v2 as dialogflow
import json
from google.api_core.exceptions import InvalidArgument
from google.oauth2 import service_account

dialogflow_key = json.load(open(r'path_to_json_file.json'))
credentials = (service_account.Credentials.from_service_account_info(dialogflow_key))
session_client = dialogflow.SessionsClient(credentials=credentials)


DIALOGFLOW_LANGUAGE_CODE = 'en-US'
DIALOGFLOW_PROJECT_ID = 'some_project_id'
SESSION_ID = 'current-user-id'
session = session_client.session_path(DIALOGFLOW_PROJECT_ID, SESSION_ID)

text_to_be_analyzed =  "mobile data"
text_input = dialogflow.types.TextInput(text=text_to_be_analyzed, language_code=DIALOGFLOW_LANGUAGE_CODE)
query_input = dialogflow.types.QueryInput(text=text_input)
try:
    response = session_client.detect_intent(session=session, query_input=query_input)
except InvalidArgument:
    raise

print("Query text:", response.query_result.query_text)
print("Detected intent:", response.query_result.intent.display_name)
print("Detected intent confidence:", response.query_result.intent_detection_confidence)
print("Fulfillment text:", response.query_result.fulfillment_text)
以下是程序输出:

Query text: mobile data
Detected intent: support.problem
Detected intent confidence: 0.41999998688697815
Fulfillment text: Make sure mobile data is enabled and Wi-Fi is turned off.
现在我的意向
支持。问题
有后续意向
支持。问题是
,客户回复
完成了
并得到另一个回复
让我们尝试另一个步骤


如何将文本/查询传递给后续意图,以及如何在Python中获得响应?

响应。查询结果对象还应包含一个
输出上下文
字段,该字段应为上下文对象数组。这个数组应该在您传递到
detect\u intent()
时传入


您应该能够创建一个带有查询参数字段的字典(包括传递给
会话\u客户端的
上下文字段)。detect\u intent
会话\u客户端。detect\u intent
接受
查询参数
,但是如何访问
query\u parameters.context
以传递
响应。query\u结果。output\u context
?您应该能够使用字典。回答清楚了,谢谢!以下是我最后所做的:
qp=dialogflow.types.QueryParameters(context=response.query\u result.output\u context)
,然后是
response\u 1=session\u client.detect\u intent(session=session,query\u params=qp,query\u input=query\u input\u 1)
,其中
query\u input\u 1
是一个新的查询,其中
完成了它。这一切都成功了,而且我可能不必为
上下文创建额外的对象