简体   繁体   English

如何使用对话流 python api 在 shell(最好是 repl.it)中制作文本机器人?

[英]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.

相关问题 "如何使用 python 在 repl.it 上自动在 shell 上安装模块" - How to install modules on the shell automatically on repl.it using python 如何使用代码在 Python 中创建永久文件? - 复制 - How Do You Make a Permanent File in Python Using Code? - Repl.it 如何使用 repl.it 数据库在 discord.py 中创建顶部 - How do I make a top in discord.py using repl.it database 如何使用repl.it使用python打印退格字符 - How to print a backspace character with python using repl.it 如何在Web应用程序中使用Repl.it? - how do I use Repl.it in my web application? 如何制作一个文件来加载变量的腌制文件,打印它,让您可以选择添加到它并重新腌制? 这在 repl.it 上可行吗? - How do I make a file that loads a pickled file of a variable, prints it, gives you the option to add to it and repickles? Is this possible on repl.it? 我应该如何最好地在 RStudio 中“运行”Python 脚本? 通过运行(使用 reticulate::repl_python()?)或来源? - How should I preferably "run" Python scripts in RStudio? Through run (using reticulate::repl_python()?) or source? 如何在 repl.it python 中创建排行榜 - How to create a leader board in repl.it python 托管在 repl.it 上的 Python discord 机器人无法正常工作 - Python discord bot hosted on repl.it not working properly 我在 Repl.it 上创建了一个 discord 音乐机器人,这个错误一直显示 - I was creating a discord music bot on Repl.it and this error keeps showing
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM