如何使用boto3发送API请求并获得答案? [英] How can i send api requests and get the answers using boto3?
本文介绍了如何使用boto3发送API请求并获得答案?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经在lex上构建了我的机器人。
我试图在python上与它交互,发送请求(句子)并解析答案。
为此,我现在花了一些时间反复阅读这些文档:https://boto3.readthedocs.io/en/latest/reference/services/lex-runtime.html#LexRuntimeService.Client.generate_presigned_url
但我似乎无法理解如何发送这些请求,以及哪个函数实际上会从机器人给我答案。
推荐答案
您是否尝试过post_text()方法?
import boto3
client = boto3.client('lex-runtime')
response = client.post_text(
botName='string',
botAlias='string',
userId='string',
sessionAttributes={
'string': 'string'
},
requestAttributes={
'string': 'string'
},
inputText='string'
)
此函数将为您提供来自机器人的答案,并将其存储在response
变量中。
在lambda函数中编写代码,并授予访问lex的权限。
希望能有所帮助。
这篇关于如何使用boto3发送API请求并获得答案?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文