Skip to content

Commit

Permalink
Merge pull request #1 from DjangoPeng/fix-api-error
Browse files Browse the repository at this point in the history
fix issue openai#29
  • Loading branch information
xianminx authored Jul 5, 2023
2 parents 3096542 + a5796e7 commit 174fac9
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,19 @@
# Keep track of todo's. Does not persist if Python session is restarted.
_TODOS = {}

@app.post("/todos/<string:username>")
@app.route("/todos/<string:username>", methods=["POST"])
async def add_todo(username):
request = await quart.request.get_json(force=True)
if username not in _TODOS:
_TODOS[username] = []
_TODOS[username].append(request["todo"])
return quart.Response(response='OK', status=200)

@app.get("/todos/<string:username>")
@app.route("/todos/<string:username>", methods=["GET"])
async def get_todos(username):
return quart.Response(response=json.dumps(_TODOS.get(username, [])), status=200)

@app.delete("/todos/<string:username>")
@app.route("/todos/<string:username>", methods=["DELETE"])
async def delete_todo(username):
request = await quart.request.get_json(force=True)
todo_idx = request["todo_idx"]
Expand All @@ -30,24 +30,24 @@ async def delete_todo(username):
_TODOS[username].pop(todo_idx)
return quart.Response(response='OK', status=200)

@app.get("/logo.png")
@app.route("/logo.png", methods=["GET"])
async def plugin_logo():
filename = 'logo.png'
return await quart.send_file(filename, mimetype='image/png')
return await quart.send_file(filename)

@app.get("/.well-known/ai-plugin.json")
@app.route("/.well-known/ai-plugin.json", methods=["GET"])
async def plugin_manifest():
host = request.headers['Host']
with open("./.well-known/ai-plugin.json") as f:
text = f.read()
return quart.Response(text, mimetype="text/json")
return quart.Response(text, content_type="text/json")

@app.get("/openapi.yaml")
@app.route("/openapi.yaml", methods=["GET"])
async def openapi_spec():
host = request.headers['Host']
with open("openapi.yaml") as f:
text = f.read()
return quart.Response(text, mimetype="text/yaml")
return quart.Response(text, content_type="text/yaml")

def main():
app.run(debug=True, host="0.0.0.0", port=5003)
Expand Down

0 comments on commit 174fac9

Please sign in to comment.