-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun_chainlit.py
More file actions
59 lines (48 loc) · 1.86 KB
/
Copy pathrun_chainlit.py
File metadata and controls
59 lines (48 loc) · 1.86 KB
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/usr/bin/env python3
"""Load project `.env` then start Chainlit (reads CHAINLIT_PORT before binding).
Run from repo root: python run_chainlit.py
Or with CLI flags: python run_chainlit.py --port 8010
If you see "address already in use", set CHAINLIT_PORT in `.env` or pass `--port`.
"""
from __future__ import annotations
import os
import sys
from pathlib import Path
def main() -> None:
# Python 3.14: engineio/socketio + asyncio.wait_for → "Timeout should be used inside a task"
if sys.version_info >= (3, 14):
sys.stderr.write(
"travel-agent: Python 3.14+ is not supported yet (Chainlit / engineio / asyncio). "
"Use Python 3.11, 3.12, or 3.13. See pyproject.toml requires-python.\n"
)
raise SystemExit(1)
root = Path(__file__).resolve().parent
env_file = root / ".env"
if env_file.is_file():
from dotenv import load_dotenv
load_dotenv(env_file)
# Chainlit does int(os.environ["CHAINLIT_PORT"]); empty string crashes ValueError.
raw = os.environ.get("CHAINLIT_PORT")
if raw is not None and not str(raw).strip():
os.environ.pop("CHAINLIT_PORT", None)
elif raw is not None:
try:
p = int(str(raw).strip())
if 1 <= p <= 65535:
os.environ["CHAINLIT_PORT"] = str(p)
else:
os.environ.pop("CHAINLIT_PORT", None)
except ValueError:
os.environ.pop("CHAINLIT_PORT", None)
os.chdir(root)
src = root / "src"
if src.is_dir() and str(src) not in sys.path:
sys.path.insert(0, str(src))
from travel_agent.sniffio_patch import apply_chainlit_python314_compat
apply_chainlit_python314_compat()
app = root / "chainlit_app.py"
sys.argv = ["chainlit", "run", str(app), *sys.argv[1:]]
from chainlit.cli import cli
cli()
if __name__ == "__main__":
main()