0

I am trying to integrate DialogFlow using the Python SDK. Code:

def detect_action_from_phrase(self, phrase):
    """Returns the result of detect intent with texts as inputs.

    Using the same `session_id` between requests allows continuation
    of the conversaion."""

    print("Called intent detection")
    session_client = dialogflow.SessionsClient()

    session = session_client.session_path(self.project_id, self.session_id)

    text_input = dialogflow.types.TextInput(
        text=phrase, language_code=self.language_code)

    query_input = dialogflow.types.QueryInput(text=text_input)

    print("NLP getting resp")
    response = session_client.detect_intent(
        session=session, query_input=query_input)
    print("Received resp")

    intent = response.query_result.intent
    action = response.query_result.action

    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("Action: {}\n".format(action))
    print('Fulfillment text: {}\n'.format(
        response.query_result.fulfillment_text))

    return action

I set session_id to "1".

I have an account credential JSON file, which an environment variable points to as explained in the docs.

Everything works fine locally, but when I use it on AWS Elastic Beanstalk, for some reason it works sometimes and other times completely times out. The script starts timing out just after printing "NLP getting resp".

I don't understand this. Any tips on why this is happening or a good way to debug it?

I'm using the v2 API and SDK.

Konrad
  • 852
  • 11
  • 31
  • Is it timeout during the eb deployment ? If that's the case then you can control it by : `eb create environment-name --timeout minutes` For example `eb create myapp-env --timeout 30` will timeout after 30 minutes – Hasan Feb 23 '18 at 15:43
  • No, it times out when my script runs: `session_client.detect_intent( session=session, query_input=query_input)` – Konrad Feb 24 '18 at 14:41
  • Hey, I'm having exactly this issue, did you ever figure something out? – S.V. Jan 22 '19 at 18:47
  • Will add that my issue is using the node api, though. – S.V. Jan 22 '19 at 18:51
  • I moved to API v1, probably something obvious I missed but I couldn't figure it out. Let me know if you find what's wrong please! I'll do the same when I'll be forced to use v2... – Konrad Jan 22 '19 at 22:01
  • We’re you able to find out more about this? I’m having this issue now when connecting from Beanstalk – dimirc Jul 16 '19 at 13:36
  • @dimirc I moved to API v1 but this is getting very worrisome given that API v1 will be completely unusable in October. Please let me know if you find anything on your end, I'll do the same. – Konrad Jul 17 '19 at 16:03

1 Answers1

1

I resolved this by adding

WSGIApplicationGroup %{GLOBAL}

To etc/httpd/conf.d/wsgi.conf

You can automate this process by creating a .ebextensions config

vim .ebextensions/dialogflow-fix.config

add the following to dialogflow-fix.config

 "/etc/httpd/conf.d/wsgi_custom.conf":
     mode: "000644"
     owner: root
     group: root
     content: |
       WSGIApplicationGroup %{GLOBAL}

add to git

git add .ebextensions/.config git commit -m 'message here'

deploy to beanstalk

eb deploy

dimirc
  • 6,347
  • 3
  • 23
  • 34
  • Thanks @dimirc! Could you please explain your answer (the contents of the snippet) and are you sure that your snippet is complete (`%{GLOBAL....`)? I will be testing this soon. – Konrad Jul 18 '19 at 09:06
  • Honestly I haven’t research yet the reason, but I found out that the second call to dialogflow was timing out because some resource wasn’t released by the first call. With this Global definition we avoid this process sharing issue – dimirc Jul 19 '19 at 09:08
  • Here is a related question https://stackoverflow.com/questions/41812497/aws-elastic-beanstalk-script-timed-out-before-returning-headers-application-p – dimirc Jul 19 '19 at 09:08
  • Thank you, I will accept your answer once I have time to test it – Konrad Jul 25 '19 at 13:44
  • Oh could you edit your answer? There is a typo in your snippet it's missing a `}` character – Konrad Jul 25 '19 at 13:45
  • 1
    @Konrad fixed – dimirc Jul 28 '19 at 02:09