CoolFace
Apppublic

Rhinox13/chatapi

sourceHugging Faceupdated 3mo agoView on Hugging Face
0likes
main.py44 linesDownload Raw Back to backend
1import gc
2gc.set_threshold(300,5,3)
3
4from pathlib import Path
5import sys
6
7if __package__ in {None, ""}:
8    sys.path.insert(0, str(Path(__file__).resolve().parents[1]))
9
10from backend.app import create_app
11from backend.core import settings
12
13
14def main() -> None:
15    app = create_app()
16    ssl_context: tuple[str, str] | None = None
17    if settings.tls_cert_file or settings.tls_key_file:
18        if not settings.tls_cert_file or not settings.tls_key_file:
19            raise RuntimeError(
20                "CHATAPI_TLS_CERT_FILE and CHATAPI_TLS_KEY_FILE must be set together"
21            )
22        if not settings.tls_cert_file.exists():
23            raise FileNotFoundError(
24                f"TLS certificate file not found: {settings.tls_cert_file}"
25            )
26        if not settings.tls_key_file.exists():
27            raise FileNotFoundError(
28                f"TLS key file not found: {settings.tls_key_file}"
29            )
30        ssl_context = (
31            str(settings.tls_cert_file),
32            str(settings.tls_key_file),
33        )
34    app.run(
35        host=settings.host,
36        port=settings.port,
37        debug=settings.debug,
38        ssl_context=ssl_context,
39    )
40
41
42if __name__ == "__main__":
43    main()
44