【问题标题】:Obtain Intents, Entities and the training data from Dialogflow in the python environment在 python 环境中从 Dialogflow 中获取 Intents、Entities 和训练数据
【发布时间】:2020-03-02 18:12:01
【问题描述】:

我想知道是否有某种方法可以以编程方式获取所有 Intent(其对应的问题)、实体和训练数据(我在 Google Dialogflow 中定义) /strong> 使用 python

以下是我从对话流中获得响应的代码(工作正常)。

GOOGLE_APPLICATION_CREDENTIALS = '###'

os.environ["GOOGLE_APPLICATION_CREDENTIALS"] =
GOOGLE_APPLICATION_CREDENTIALS

def dialogflow_api_response(text):
  session_client = dialogflow.SessionsClient()

  session = session_client.session_path('###', '##')

  text_input = dialogflow.types.TextInput(text=text, language_code='en')
  query_input = dialogflow.types.QueryInput(text=text_input)
  response = session_client.detect_intent(session=session, query_input=query_input)
  jsonObj = MessageToJson(response)
  x = json.loads(jsonObj)

如果有,请指出正确的方向。

谢谢

【问题讨论】:

    标签: python python-3.x dialogflow-es chatbot


    【解决方案1】:

    是的,可以使用 Dilogflow API 作为 JSON 对象从 Dialogflow 代理获取所有意图、实体、unserEntities 和上下文。这是获取意图列表的代码:

    def list_intents(project_id):
       import dialogflow_v2 as dialogflow
       intents_client = dialogflow.IntentsClient()
    
       parent = intents_client.project_agent_path(project_id)
    
       intents = intents_client.list_intents(parent)
    
       for intent in intents:
           print('=' * 20)
           print('Intent name: {}'.format(intent.name))
           print('Intent display_name: {}'.format(intent.display_name))
           print('Action: {}\n'.format(intent.action))
           print('Root followup intent: {}'.format(
               intent.root_followup_intent_name))
           print('Parent followup intent: {}\n'.format(
              intent.parent_followup_intent_name))
    
           print('Input contexts:')
           for input_context_name in intent.input_context_names:
               print('\tName: {}'.format(input_context_name))
    
           print('Output contexts:')
           for output_context in intent.output_contexts:
               print('\tName: {}'.format(output_context.name))
    
           for training_phrase in intent.training_phrases:
                train_phrase = training_phrase.parts[0].text
                print(train_phrase)  
    

    更多信息可以参考DF官方gitHubhere

    【讨论】:

    • 嘿,非常感谢。还有一种方法可以获取每个意图的训练短语吗?
    • intent.training_phrases 为您提供训练短语列表。
    猜你喜欢
    • 2022-01-16
    • 2019-06-23
    • 1970-01-01
    • 2019-08-01
    • 1970-01-01
    • 2019-06-16
    • 2019-11-11
    • 2019-05-28
    • 1970-01-01
    相关资源
    最近更新 更多