[英]How do I make a text bot in a shell (preferably repl.it) using the dialogflow python api?
I am trying to make a simple chatbot in my repl.it shell, but it errors, saying that it "Could not automatically determine credentials.", I have looked over it many times, and can't figure out how to do it.我正在尝试在我的 repl.it shell 中制作一个简单的聊天机器人,但它出错,说它“无法自动确定凭据。”,我已经看过很多次了,但不知道该怎么做。 In addition, I might have other things wrong but I can't tell since I can't get past this error.此外,我可能还有其他问题,但我无法判断,因为我无法克服这个错误。 If anyone can help me with this, or if you have an example that I can follow, that would be great https://repl.it/@RyandaKing/ThoughtfulWorrisomeQuadrant如果有人可以帮助我,或者如果你有一个我可以效仿的例子,那就太好了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)
The reason is that you improperly use the private key contained by .json
.原因是您不当使用.json
包含的私钥。 As described here you should define the environment variable having the value of .json
key file path.如此处所述,您应该定义值为.json
密钥文件路径的环境变量。
Assuming that the .py
and .json
files are in the same directory run it like this.假设.py
和.json
文件在同一个目录中,像这样运行它。
$ cd path/to/app
$ env 'GOOGLE_APPLICATION_CREDENTIALS=newagent-1-rhjebl-29ae80f7e64d.json' python3 app.py
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.