首页 > 解决方案 > 模块“dialogflow_v2.types”没有“QueryInput”成员

问题描述

我尝试使用 python 调用 dialogflow api,但出现错误

模块“dialogflow_v2.types”没有“QueryInput”成员

请帮帮我。

import dialogflow

def detect_intent_texts(project_id, session_id, texts, language_code):
    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('Fulfillment text: {}\n'.format(response.query_result.fulfillment_text)) 

detect_intent_texts("upcl-b0ba9","abcd",["hello"],"en-US")

标签: pythondialogflow-es

解决方案


这是您的问题的解决方案,而不是

import dialogflow_v2 as dialogflow 

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

试试这样

from dialogflow_v2.types import TextInput, QueryInput

text_input = TextInput(text=text, language_code=language_code)
query_input = QueryInput(text=text_input)


推荐阅读