Repository navigation
Expand file tree
/
Copy pathmain.py
More file actions
59 lines (42 loc) · 1.42 KB
/
Copy pathmain.py
File metadata and controls
59 lines (42 loc) · 1.42 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
"""Sharlok FastAPI Server Launcher.
This script runs the Sharlok threat modeling web server.
Access the interface at http://localhost:8000
Before starting, it makes sure Ollama is running and the required models are
present (starting `ollama serve` and pulling missing models automatically).
Use --build-index to create or update the FAISS knowledge store and exit.
"""
import argparse
import logging
import os
import sys
import requests
# Add current directory to path
sys.path.insert(0, os.path.dirname(__file__))
def main() -> None:
parser = argparse.ArgumentParser(description="Sharlok server launcher.")
parser.add_argument(
"--build-index",
action="store_true",
help="Create or update the FAISS store from PDF/, Repos/, Tools/ and webpages.yml, then exit",
)
args = parser.parse_args()
logging.basicConfig(level=logging.INFO, format="%(levelname)s %(message)s")
from ready import ensure_ollama_ready
try:
ensure_ollama_ready()
except (RuntimeError, requests.RequestException) as exc:
sys.exit(f"Startup check failed: {exc}")
if args.build_index:
from knowledge_base import build_index
print(f"Indexed {build_index()} new chunk(s).")
return
import uvicorn
uvicorn.run(
"app:app",
host="0.0.0.0",
port=8000,
reload=True,
log_level="info",
)
if __name__ == "__main__":
main()