Improve API
This commit is contained in:
parent
d40e22707a
commit
e53afb07bc
4 changed files with 47 additions and 4 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -8,3 +8,4 @@ __pycache__
|
|||
.ipynb_checkpoints
|
||||
*.egg-info
|
||||
build
|
||||
tracing_database.json
|
||||
|
|
|
|||
26
docs/hello_world.ipynb
Normal file
26
docs/hello_world.ipynb
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from great_ai import GreatAI\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"@GreatAI.create\n",
|
||||
"def hello_world(name: str) -> str:\n",
|
||||
" return f\"Hello {name}!\"\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
"language_info": {
|
||||
"name": "python"
|
||||
},
|
||||
"orig_nbformat": 4
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 2
|
||||
}
|
||||
|
|
@ -2,9 +2,9 @@
|
|||
|
||||
import logging
|
||||
import re
|
||||
import time
|
||||
from importlib import import_module, reload
|
||||
from pathlib import Path
|
||||
from threading import Event
|
||||
from typing import Optional
|
||||
|
||||
import uvicorn
|
||||
|
|
@ -65,7 +65,21 @@ def main() -> None:
|
|||
|
||||
logger.info(f"Starting uvicorn server with app={app}")
|
||||
|
||||
uvicorn.run(app, **common_config)
|
||||
config = Config(app, **common_config)
|
||||
socket = config.bind_socket()
|
||||
server = GreatAIReload(
|
||||
config, target=uvicorn.Server(config=config).run, sockets=[socket]
|
||||
)
|
||||
|
||||
server.startup()
|
||||
try:
|
||||
Event().wait()
|
||||
finally:
|
||||
server.shutdown()
|
||||
if args.file_name.endswith(".ipynb"):
|
||||
Path(get_script_name_of_notebook(args.file_name)).unlink(
|
||||
missing_ok=True
|
||||
)
|
||||
else:
|
||||
|
||||
class EventHandler(PatternMatchingEventHandler):
|
||||
|
|
@ -106,8 +120,7 @@ def main() -> None:
|
|||
observer.start()
|
||||
|
||||
try:
|
||||
while True:
|
||||
time.sleep(50)
|
||||
Event().wait()
|
||||
finally:
|
||||
observer.stop()
|
||||
restart_handler.stop_server()
|
||||
|
|
|
|||
|
|
@ -14,6 +14,9 @@ async def call_remote_great_ai_async(
|
|||
if http is None:
|
||||
http = HttpClient()
|
||||
|
||||
if base_uri.endswith("/"):
|
||||
base_uri = base_uri[:-1]
|
||||
|
||||
url = f"{base_uri}/predict/"
|
||||
response = await http.post(
|
||||
url=url, data=data, retry_count=retry_count, expected_status=200
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue