第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機(jī)立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何在Python中使用dialogflow客戶端

如何在Python中使用dialogflow客戶端

慕姐8265434 2023-09-05 20:21:15
我正在嘗試的是在 python 中獲得響應(yīng)import dialogflowfrom google.api_core.exceptions import InvalidArgumentDIALOGFLOW_PROJECT_ID = 'imposing-fx-333333'DIALOGFLOW_LANGUAGE_CODE = 'en'GOOGLE_APPLICATION_CREDENTIALS = 'imposing-fx-333333-e6e3cb9e4adb.json'text_to_be_analyzed = "Hi! I'm David and I'd like to eat some sushi, can you help me?"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:    raiseprint("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)我無法驗證憑據(jù)google.auth.exceptions.DefaultCredentialsError: Could not automatically determine credentials. Please set GOOGLE_APPLICATION_CREDENTIALS or explicitly create credentials and re-run the application. For more information, please see https://cloud.google.com/docs/authentication/getting-started這是我在 stackoverflow 中的第一個問題:)我知道我已經(jīng)做了很多
查看完整描述

2 回答

?
肥皂起泡泡

TA貢獻(xiàn)1829條經(jīng)驗 獲得超6個贊

您需要從 導(dǎo)出服務(wù)帳戶密鑰 (JSON)文件,并將環(huán)境變量設(shè)置GOOGLE_APPLICATION_CREDENTIALS為包含服務(wù)帳戶密鑰的 JSON 文件的文件路徑。然后你就可以調(diào)用dialogflow了。


獲取服務(wù)帳戶密鑰的步驟: 確保您使用的是 Dialogflow v2。轉(zhuǎn)到常規(guī)設(shè)置并單擊您的服務(wù)帳戶。這會將您重定向到 Google Cloud Platform 項目的服務(wù)帳戶頁面。下一步是為服務(wù)帳戶創(chuàng)建新密鑰?,F(xiàn)在創(chuàng)建一個服務(wù)帳戶并選擇 JSON 作為輸出密鑰。按照說明操作,JSON 文件將下載到您的計算機(jī)。該文件將用作GOOGLE_APPLICATION_CREDENTIALS.


現(xiàn)在在代碼中,


import os

import dialogflow

os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = "/path/to/file.json"

project_id = "your_project_id"

session_id = "your_session_id"

language_code = "en"

session_client = dialogflow.SessionsClient()

session = session_client.session_path(project_id, session_id)


text_input = dialogflow.types.TextInput(text=text, language_code=language_code)

query_input = dialogflow.types.QueryInput(text=text_input)

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



查看完整回答
反對 回復(fù) 2023-09-05
?
慕虎7371278

TA貢獻(xiàn)1802條經(jīng)驗 獲得超4個贊

如果您想從文件系統(tǒng)中獲取文件,此方法也適用。推薦的方法是使用環(huán)境變量



    import json

    from google.cloud import dialogflow_v2

    from google.oauth2 import *

session_client = None

dialogflow_key = None

creds_file = "/path/to/json/file.json"


dialogflow_key = json.load(open(creds_file))

credentials = (service_account.Credentials.from_service_account_info(dialogflow_key))


session_client = dialogflow_v2.SessionsClient(credentials=credentials)


print("it works : " + session_client.DEFAULT_ENDPOINT) if session_client is not None 

else print("does not work")


我忘記添加主要文章抱歉...這里是:


https://googleapis.dev/python/google-auth/latest/user-guide.html#service-account-private-key-files


查看完整回答
反對 回復(fù) 2023-09-05
  • 2 回答
  • 0 關(guān)注
  • 150 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號