gpt4 book ai didi

python - 对话流 : manage several credentials for several agents

转载 作者:太空宇宙 更新时间:2023-11-04 00:13:02 27 4
gpt4 key购买 nike

我在 python 中使用 dialogflow。我这样调用 API V2:

os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = "project/xx-prototype-v2-xxxxx.json"
import dialogflow_v2 as dialogflow
session_client = dialogflow.SessionsClient()
session = session_client.session_path(project_id, session_id)

现在我需要从同一个 python 模块访问多个具有多个 .json 凭据文件的代理。

是否有一种聪明的方法可以为多个对话流代理设置此代码,每个代理都有自己的凭据 json 文件?

最佳答案

您可以在实例化 SessionClient 时传递身份验证信息,如下面的示例代码所示:

const client = new dialogflow.SessionsClient({
credentials: {
client_email: "svc-acc@project-id.iam.gserviceaccount.com",
private_key: "---BEGIN.....END-----"
},
projectId: "your-project-id"
})

针对不同的代理/项目,您可以传入不同的认证信息。例如

const client1 = new dialogflow.SessionsClient({
credentials: {
client_email: "service-account-email-1@project-id.iam.gserviceaccount.com",
private_key: "---BEGIN.....END-----" //service account private key 1
},
projectId: "your-project-id-1"
})
// use client1 and make any needed API calls to your first agent

const client2 = new dialogflow.SessionsClient({
credentials: {
client_email: "service-account-email-2@project-id.iam.gserviceaccount.com",
private_key: "---BEGIN.....END-----" //service account private key 2
},
projectId: "your-project-id-2"
})
// use client2 and make any needed API calls to your second agent

// instantiate more clients as needed...

关于python - 对话流 : manage several credentials for several agents,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51823453/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com