我尝试使用一些旧教程,但实际上我需要的是一个完整的示例,可以根据自己的需要进行修改。
仅仅是python中使用DialogFlow的python(或c ++,尽管这将需要重做到目前为止的内容)的示例吗?只是一个简单的接口,其中DialogFlow接收字符串并发回字符串?
答案 0 :(得分:2)
您可以遵循quickstart:
def detect_intent_texts(project_id, session_id, texts, language_code):
"""Returns the result of detect intent with texts as inputs.
Using the same `session_id` between requests allows continuation
of the conversation."""
import dialogflow_v2 as dialogflow
session_client = dialogflow.SessionsClient()
session = session_client.session_path(project_id, session_id)
print('Session path: {}\n'.format(session))
for text in texts:
text_input = dialogflow.types.TextInput(
text=text, language_code=language_code)
query_input = dialogflow.types.QueryInput(text=text_input)
response = session_client.detect_intent(
session=session, query_input=query_input)
print('=' * 20)
print('Query text: {}'.format(response.query_result.query_text))
print('Detected intent: {} (confidence: {})\n'.format(
response.query_result.intent.display_name,
response.query_result.intent_detection_confidence))
print('Fulfillment text: {}\n'.format(
response.query_result.fulfillment_text))
def main():
project_id = 'PROJECT-ID-HERE'
session_id = 'SESSION-ID-HERE'
texts = ['reserve a meeting room for six people']
language_code = 'en-US'
detect_intent_texts(project_id, session_id, texts, language_code)
main()
文本应该是可迭代的字符串(列表,元组等)。
您还应该已经通过身份验证-我建议使用带有json密钥的服务帐户,因为这样做非常简单。有一个很好的例子here。