get -> post
Browse files- .vscode/launch.json +21 -0
- games/game_snake.py +13 -4
- main.py +3 -3
.vscode/launch.json
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
// Use IntelliSense to learn about possible attributes.
|
| 3 |
+
// Hover to view descriptions of existing attributes.
|
| 4 |
+
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
| 5 |
+
"version": "0.2.0",
|
| 6 |
+
"configurations": [
|
| 7 |
+
|
| 8 |
+
{
|
| 9 |
+
"name": "Python: FastAPI",
|
| 10 |
+
"type": "python",
|
| 11 |
+
"request": "launch",
|
| 12 |
+
"module": "uvicorn",
|
| 13 |
+
"args": [
|
| 14 |
+
"main:app",
|
| 15 |
+
"--reload"
|
| 16 |
+
],
|
| 17 |
+
"jinja": true,
|
| 18 |
+
"justMyCode": true
|
| 19 |
+
}
|
| 20 |
+
]
|
| 21 |
+
}
|
games/game_snake.py
CHANGED
|
@@ -1,10 +1,19 @@
|
|
| 1 |
-
|
|
|
|
|
|
|
| 2 |
|
|
|
|
| 3 |
|
| 4 |
game = snake()
|
| 5 |
|
| 6 |
-
|
| 7 |
def process(command: str):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
# res1, _ = game.query_entry_point(command)
|
| 9 |
-
|
| 10 |
-
return res1
|
|
|
|
| 1 |
+
import json
|
| 2 |
+
import requests
|
| 3 |
+
import urllib.parse
|
| 4 |
|
| 5 |
+
from games.snake.snake import snake
|
| 6 |
|
| 7 |
game = snake()
|
| 8 |
|
|
|
|
| 9 |
def process(command: str):
|
| 10 |
+
url = 'http://127.0.0.1:8080/nlp'
|
| 11 |
+
myobj = {
|
| 12 |
+
'game': 'snake',
|
| 13 |
+
'command': command,
|
| 14 |
+
}
|
| 15 |
+
x = requests.post(url, json=myobj)
|
| 16 |
+
print(x.text)
|
| 17 |
+
|
| 18 |
# res1, _ = game.query_entry_point(command)
|
| 19 |
+
return json.loads(x.text)
|
|
|
main.py
CHANGED
|
@@ -1,4 +1,4 @@
|
|
| 1 |
-
from fastapi import FastAPI
|
| 2 |
|
| 3 |
import games.game_util as game_util
|
| 4 |
|
|
@@ -9,6 +9,6 @@ app = FastAPI()
|
|
| 9 |
async def root():
|
| 10 |
return {"message": "PGAI API"}
|
| 11 |
|
| 12 |
-
@app.
|
| 13 |
-
def test(game: str, command: str):
|
| 14 |
return game_util.nlp(game, command)
|
|
|
|
| 1 |
+
from fastapi import FastAPI, Body
|
| 2 |
|
| 3 |
import games.game_util as game_util
|
| 4 |
|
|
|
|
| 9 |
async def root():
|
| 10 |
return {"message": "PGAI API"}
|
| 11 |
|
| 12 |
+
@app.post("/nlp")
|
| 13 |
+
def test(game: str=Body(), command: str=Body()):
|
| 14 |
return game_util.nlp(game, command)
|