1

I am trying to run duckling locally. So with the help of this article I installed stack, and then

cloned duckling code

git clone https://github.com/facebook/duckling.git

download the zoneinfo and updated the reference in exe/ExampleMain.hs

  let defaultPath = "duckling/exe/zoneinfo/"
  let fallbackPath = "exe/zoneinfo/"

build using

stack build

then run using

stack exec duckling-example-exe

now if i hit http://localhost:8000/parse in the postman with request type POST and with following content

{
    "text": "tommorow",
    "locale": "de_DE",
    "tz": "Europe/Berlin",
    "dims": [
        "time"
    ],
    "reftime": 1616571265000
}

it shows 422 bad input

Need a 'text' parameter to parse

and if i hit the same request again it shows 200 OK

quack!

any help?

Sunil Garg
  • 14,608
  • 25
  • 132
  • 189

2 Answers2

1

I see that you are trying to send the request as a JSON, however, the "http://localhost:8000/parse" endpoint expects the input to be sent as "form-encoded" data.

Refer to this image for a sample snapshot - https://i.stack.imgur.com/Cqdz4.png

1

You can check the source code of RASA open source. They are using requests python library to use duckling inside RASA for data parsing.

Here is the source code, here

It will be so useful to know the correct format of text data.

Also, I will show you how to use duckling through a simple example:

  1. Be sure that you compile and run the binary:
$ stack build
$ stack exec duckling-example-exe
  1. Insdie pythod code environment or any IDE that support python run the following:
import requests
t = requests.post('http://0.0.0.0:8000/parse', data={'text':'tomorrow at eight', 'locale':'en_GB'})
print(t.text)

The output is

[{"body":"tomorrow at eight","start":0,"value":{"values":[{"value":"2021-09-27T08:00:00.000-07:00","grain":"hour","type":"value"},{"value":"2021-09-27T20:00:00.000-07:00","grain":"hour","type":"value"}],"value":"2021-09-27T08:00:00.000-07:00","grain":"hour","type":"value"},"end":17,"dim":"time","latent":false}]


Pain
  • 111
  • 1
  • 2
  • 12