我试图在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)