首页 > 解决方案 > Dialogflow api检测意图在Windows上不起作用

问题描述

我创建了一个 dialogflow 代理,并且在我的 mac 上使用 dialogflow api 已经有一段时间了。当我开始在 Windows 上工作时,出现了这个问题。基本上我的代码执行直到它到达该行

response = session_client.detect_intent(session=session, query_input=query_input)

它不会抛出错误或存在。它只是卡在那里,根据我的代理的历史记录,没有发送任何请求。我不知道这是操作系统问题还是缺少其他东西。您可以在下面查看我的代码:

import dialogflow
from google.api_core.exceptions import InvalidArgument

os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = 'private-key.json'

DIALOGFLOW_PROJECT_ID = 'campus-guide-xetlpf'
DIALOGFLOW_LANGUAGE_CODE = 'en'
SESSION_ID = 'me'

text_to_be_analyzed = "Hello"

session_client = dialogflow.SessionsClient()
session = session_client.session_path(DIALOGFLOW_PROJECT_ID, SESSION_ID)
text_input = dialogflow.types.TextInput(text=text_to_be_analyzed, language_code=DIALOGFLOW_LANGUAGE_CODE)
query_input = dialogflow.types.QueryInput(text=text_input)
try:
    print(query_input)
    print(session)
    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)

输出:

文本 { 文本:“你好” 语言代码:“en” }

项目/校园指南-xetlpf/代理/会话/我

更新: 当我调试时,我得到了这个,它看起来像是 grpc 请求中的错误。任何线索为什么?

标签: pythongoogle-apidialogflow-es

解决方案


推荐阅读