如何使用dialogflow python API在外壳(最好是repl.it)中制作文本机器人?

我试图在repl.it shell中创建一个简单的聊天机器人,但是它出错,并说它“无法自动确定凭据。”,我已经看了很多遍了,无法弄清楚该怎么做。做吧。另外,我可能有其他错误,但是由于我无法克服此错误,因此无法确定。 如果有人可以帮助我,或者您有一个可以效法的例子,那将是很好的 https://repl.it/@RyandaKing/ThoughtfulWorrisomeQuadrant

import dialogflow
from google.api_core.exceptions import InvalidArgument

DIALOGFLOW_PROJECT_ID = 'newagent-1-rhjebl'
DIALOGFLOW_LANGUAGE_CODE = 'en-US'
GOOGLE_APPLICATION_CREDENTIALS = 'newagent-1-rhjebl-29ae80f7e64d.json'
SESSION_ID = '110497386060607202274'
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:
    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)
niewenge 回答:如何使用dialogflow python API在外壳(最好是repl.it)中制作文本机器人?

原因是您不正确地使用.json包含的私钥。如here所述,您应该定义值为.json密钥文件路径的环境变量。

假设.py.json文件在同一目录中,请按以下方式运行它。

$ cd path/to/app
$ env 'GOOGLE_APPLICATION_CREDENTIALS=newagent-1-rhjebl-29ae80f7e64d.json' python3 app.py
本文链接:https://www.f2er.com/3162607.html

大家都在问