-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
59 lines (46 loc) · 1.59 KB
/
app.py
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
import importlib.util
import os
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from api.service import shell
if not os.environ.get("IS_CONTAINER"):
shell.print_yellow_message("Running on bare metal. Loading environment variables from .env file...")
# docker-compose is configured to set IS_CONTAINER environment variable.
# if this variable is not set, the app is running on bare metal.
# so, we will load the environment variables from `.env` file.
from dotenv import load_dotenv
load_dotenv()
shell.print_cyan_message("Environment variables loaded successfully.")
app = FastAPI()
app.add_middleware(
CORSMiddleware,
allow_origins=["*"],
allow_methods=["*"],
allow_headers=["*"],
)
@app.get("/")
def read_root():
return {"ping": "I am alive!"}
# load API Routers
routes = [x.rstrip(".py") for x in os.listdir("api/route") if x.endswith(".py") and not x.startswith("_")]
for route in routes:
shell.print_cyan_message(f"Loading {route}...")
try:
importlib.util.spec_from_file_location(route, f"api/route/{route}.py")
module = importlib.import_module(f"api.route.{route}")
module.setup(app)
shell.print_green_message("Success!")
except Exception as e:
shell.print_red_message(f"Failed:")
print(e)
"""
Environment Variables:
CHAT_MODEL = qwen2:0.5b (or whatever is in .env)
OLLAMA_BASE_URL = http://localhost:11434
CHROMA_HOST = localhost
CHROMA_PORT = 8000
CHROMA_COLLECTION = ecosoc
"""
if __name__ == "__main__":
import uvicorn
uvicorn.run(app, host="0.0.0.0", port=5000)