gpt4 book ai didi

python - Python 中的 Dialogflow API 访问后续意图

转载 作者:行者123 更新时间:2023-12-01 08:01:58 25 4
gpt4 key购买 nike

我正在按照以下教程来了解 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.

现在,我的意图 support.problem 已跟进意图 support.problem-yes,客户回复 完成 并收到另一个响应让我们尝试另一个步骤

如何传递文本/查询来跟进意图以及如何在 Python 中获得响应?

最佳答案

response.query_result对象还应该包含 output_context字段,它应该是 Context 对象的数组。该数组应传入 query_parameters.context 您传递到detect_intent() .

您应该能够使用传递给 context 的查询参数字段(包括 session_client.detect_intent 的一个)创建一个字典。 .

关于python - Python 中的 Dialogflow API 访问后续意图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55694596/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com