File size: 843 Bytes
c63bc31
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
"""Run the CORTEX AI API server.

    python -m cortex_ai.api.serve

Uses the mock adapter by default so the server starts on any machine. Set
CORTEX_ADAPTER=hf to load the real checkpoint instead.
"""

from __future__ import annotations

import os

from .server import create_app
from ..adapters.mock import MockAdapter
from ..config import CortexConfig


def build_adapter(config: CortexConfig):
    kind = os.getenv("CORTEX_ADAPTER", "mock").lower()
    if kind == "hf":
        from ..adapters.hf_adapter import HFAdapter

        return HFAdapter(config.model_id).load()
    return MockAdapter()


def main() -> None:
    import uvicorn

    config = CortexConfig.from_env()
    app = create_app(build_adapter(config), config)
    uvicorn.run(app, host=config.server.host, port=config.server.port)


if __name__ == "__main__":
    main()