File size: 979 Bytes
043267b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
from __future__ import annotations

import argparse


def main() -> None:
    ap = argparse.ArgumentParser(prog="xaddons-classifier")
    sub = ap.add_subparsers(dest="cmd", required=True)
    s = sub.add_parser("serve", help="run the local HTTP service for the extension")
    s.add_argument("--backend", choices=["rules", "basal", "embed"], default="rules")
    s.add_argument("--basal-url", default="http://127.0.0.1:8000")
    s.add_argument("--embed-model", default=None)
    s.add_argument("--host", default="127.0.0.1")
    s.add_argument("--port", type=int, default=8765)
    a = ap.parse_args()

    import uvicorn

    from .backends import get_backend
    from .server import create_app

    kw = {}
    if a.backend == "basal":
        kw["url"] = a.basal_url
    if a.backend == "embed" and a.embed_model:
        kw["model"] = a.embed_model
    uvicorn.run(create_app(get_backend(a.backend, **kw)), host=a.host, port=a.port)


if __name__ == "__main__":
    main()