Spaces:
Runtime error
Runtime error
Commit
·
0af4a83
1
Parent(s):
be8d239
changed to uvicorn setup for HF v4
Browse files- main/main.py +32 -51
main/main.py
CHANGED
|
@@ -4,7 +4,6 @@ LLM Inference Server main application using LitServe framework.
|
|
| 4 |
import litserve as ls
|
| 5 |
import yaml
|
| 6 |
import logging
|
| 7 |
-
import asyncio
|
| 8 |
from pathlib import Path
|
| 9 |
from fastapi.middleware.cors import CORSMiddleware
|
| 10 |
from .routes import router, init_router
|
|
@@ -24,58 +23,40 @@ def load_config():
|
|
| 24 |
with open(config_path) as f:
|
| 25 |
return yaml.safe_load(f)
|
| 26 |
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
#
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
)
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
# Add CORS middleware
|
| 45 |
-
app.add_middleware(
|
| 46 |
-
CORSMiddleware,
|
| 47 |
-
allow_origins=["*"],
|
| 48 |
-
allow_credentials=True,
|
| 49 |
-
allow_methods=["*"],
|
| 50 |
-
allow_headers=["*"],
|
| 51 |
-
)
|
| 52 |
-
|
| 53 |
-
# Add routes with configured prefix
|
| 54 |
-
api_prefix = config.get('llm_server', {}).get('api_prefix', '/api/v1')
|
| 55 |
-
app.include_router(router, prefix=api_prefix)
|
| 56 |
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
"""Initialize async components on startup."""
|
| 60 |
-
# Initialize the router
|
| 61 |
-
await init_router(api)
|
| 62 |
-
# Launch the inference worker
|
| 63 |
-
server.launch_inference_worker()
|
| 64 |
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 69 |
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
host = server_config.get('host', '0.0.0.0')
|
| 74 |
-
server.run(host=host, port=port)
|
| 75 |
|
| 76 |
-
|
| 77 |
-
"""Entry point that runs the server directly"""
|
| 78 |
-
asyncio.run(run_server())
|
| 79 |
|
| 80 |
-
|
| 81 |
-
|
|
|
|
| 4 |
import litserve as ls
|
| 5 |
import yaml
|
| 6 |
import logging
|
|
|
|
| 7 |
from pathlib import Path
|
| 8 |
from fastapi.middleware.cors import CORSMiddleware
|
| 9 |
from .routes import router, init_router
|
|
|
|
| 23 |
with open(config_path) as f:
|
| 24 |
return yaml.safe_load(f)
|
| 25 |
|
| 26 |
+
def create_app():
|
| 27 |
+
"""Create and configure the application instance."""
|
| 28 |
+
logger = setup_logging()
|
| 29 |
+
config = load_config()
|
| 30 |
+
server_config = config.get('server', {})
|
| 31 |
+
|
| 32 |
+
# Initialize API with config
|
| 33 |
+
api = InferenceApi(config)
|
| 34 |
+
|
| 35 |
+
# Create LitServer instance
|
| 36 |
+
server = ls.LitServer(
|
| 37 |
+
api,
|
| 38 |
+
timeout=server_config.get('timeout', 60),
|
| 39 |
+
max_batch_size=server_config.get('max_batch_size', 1),
|
| 40 |
+
track_requests=True
|
| 41 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 42 |
|
| 43 |
+
# Get the FastAPI app
|
| 44 |
+
app = server.app
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
|
| 46 |
+
# Add CORS middleware
|
| 47 |
+
app.add_middleware(
|
| 48 |
+
CORSMiddleware,
|
| 49 |
+
allow_origins=["*"],
|
| 50 |
+
allow_credentials=True,
|
| 51 |
+
allow_methods=["*"],
|
| 52 |
+
allow_headers=["*"],
|
| 53 |
+
)
|
| 54 |
|
| 55 |
+
# Add routes with configured prefix
|
| 56 |
+
api_prefix = config.get('llm_server', {}).get('api_prefix', '/api/v1')
|
| 57 |
+
app.include_router(router, prefix=api_prefix)
|
|
|
|
|
|
|
| 58 |
|
| 59 |
+
return app
|
|
|
|
|
|
|
| 60 |
|
| 61 |
+
# Create the app instance for uvicorn
|
| 62 |
+
app = create_app()
|