Skip to content

Commit

Permalink
feat: forward the intent creation to NLU (#2)
Browse files Browse the repository at this point in the history
feat: forward the intent creation to NLU
  • Loading branch information
sylvain-reynaud authored Apr 24, 2023
1 parent 7de0927 commit 53bb4f7
Show file tree
Hide file tree
Showing 14 changed files with 969 additions and 192 deletions.
3 changes: 3 additions & 0 deletions .adr/post_2_files.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Why POSTing 2 files instead of the archive as file and a json in the request body ?

Because HTTP protocol cannot handle a `multipart/form-data` request with a `body`.
59 changes: 39 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,9 @@

The goal of this project is to provide a simple API gateway for **creating skills**.

By recieving a POST request like this:

```bash
curl -X POST \
http://localhost:8080/skills \
-H 'Content-Type: multipart/form-data' \
-F 'name=lighton' \
-F 'intents_json=@./test_data/intents.json' \
-F 'function_archive=@./test_data/lightOn.zip'
```

The gateway will:
- Create a new functions with the Morty Function Registry
- Create a new skill with the NLU API
The gateway:
- Creates a new functions with the Morty Function Registry
- Creates a new skill with the NLU API

**Today, the gate do not "Create a new skill with the NLU API"** because the NLU API is not ready yet.

Expand All @@ -35,8 +24,10 @@ Flow without NLU:

```bash
# Example values
export MORTY_API_ENDPOINT="http://localhost:8081/"
export NLU_API_ENDPOINT="http://localhost:8082/"
export POLYXIA_GATEWAY_MORTY_API_ENDPOINT="http://localhost:8081/v1"
export POLYXIA_GATEWAY_NLU_API_ENDPOINT="http://localhost:8082/v1"
export POLYXIA_GATEWAY_MORTY_ADDR="localhost"
export POLYXIA_GATEWAY_MORTY_PORT="8080"
```

2. Run the API gateway with the following command:
Expand All @@ -61,6 +52,10 @@ aws --endpoint-url=http://localhost:9000 s3 mb s3://functions
make start
```

4. Run the NLU API

Follow the instructions here: https://github.com/polyxia-org/nlu/

### Use the API gateway

1. Create a new skill using the Morty CLI:
Expand All @@ -77,13 +72,37 @@ morty function init lightOn
zip -r lightOn.zip lightOn
```

2. Send a POST request with 2 files to the API gateway:
2. Write an `intent.json` to `./test_data`

The json should look like this:
```json
{
"utterances": [
"météo",
"donne moi la météo",
"quel temps fait-il aujourd'hui à [ Paris | Montpellier ] ?",
"est ce qu'il pleut ?",
"est-ce qu'il fait beau ?",
"Y a t'il du soleil ?",
"Quelle est la météo actuelle ?"
],
"slots": [
{
"type": "place_name"
}
]
}
```

3. Send a POST request with 2 files to the API gateway:

```bash
curl -X POST \
http://localhost:8080/skills \
http://localhost:8080/v1/skills \
-H 'Content-Type: multipart/form-data' \
-F 'name=lighton' \
-F 'intents_json=@./test_data/intents.json' \
-F 'intents_json=@./test_data/intent.json' \
-F 'function_archive=@./test_data/lightOn.zip'
```
```

For more information, see the [OpenAPI spec](./openapi.yml).
6 changes: 4 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,7 @@ services:
ports:
- "8080:8080"
environment:
MORTY_API_ENDPOINT: "http://localhost:8081"
NLU_API_ENDPOINT: "http://localhost:8082"
POLYXIA_GATEWAY_MORTY_API_ENDPOINT: "http://localhost:8081/v1"
POLYXIA_GATEWAY_NLU_API_ENDPOINT: "http://localhost:8082/v1"
POLYXIA_GATEWAY_MORTY_ADDR: "0.0.0.0"
POLYXIA_GATEWAY_MORTY_PORT: "8080"
15 changes: 15 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,21 @@ go 1.20
require github.com/aws/aws-sdk-go v1.44.225

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/fsnotify/fsnotify v1.6.0 // indirect
github.com/go-ini/ini v1.67.0 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/mitchellh/go-homedir v1.1.0 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/spf13/afero v1.9.3 // indirect
github.com/spf13/cast v1.5.0 // indirect
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/spf13/viper v1.15.0 // indirect
github.com/stretchr/testify v1.8.2 // indirect
github.com/subosito/gotenv v1.4.2 // indirect
)

require (
Expand All @@ -15,6 +28,7 @@ require (
github.com/dustin/go-humanize v1.0.1 // indirect
github.com/gin-contrib/sse v0.1.0 // indirect
github.com/gin-gonic/gin v1.9.0 // indirect
github.com/go-chi/chi/v5 v5.0.8
github.com/go-playground/locales v0.14.1 // indirect
github.com/go-playground/universal-translator v0.18.1 // indirect
github.com/go-playground/validator/v10 v10.11.2 // indirect
Expand All @@ -35,6 +49,7 @@ require (
github.com/pelletier/go-toml/v2 v2.0.6 // indirect
github.com/rs/xid v1.4.0 // indirect
github.com/sirupsen/logrus v1.9.0 // indirect
github.com/thomasgouveia/go-config v1.0.0
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
github.com/ugorji/go/codec v1.2.9 // indirect
golang.org/x/arch v0.0.0-20210923205945-b76863e36670 // indirect
Expand Down
Loading

0 comments on commit 53bb4f7

Please sign in to comment.