File size: 2,484 Bytes
86c402d
 
0341212
a88e42e
0341212
86c402d
57cf043
 
86c402d
57cf043
86c402d
57cf043
0341212
86c402d
 
0341212
57cf043
 
86c402d
0341212
57cf043
 
 
86c402d
0341212
 
 
 
57cf043
 
 
 
 
 
 
 
 
 
 
 
0341212
57cf043
 
 
a88e42e
fbf2abd
 
57cf043
4daae4e
5dee1a1
 
4daae4e
57cf043
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
86c402d
0341212
fd3c8b9
57cf043
0341212
57cf043
 
 
 
0341212
 
6666b3d
57cf043
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import logging
import os
from contextlib import asynccontextmanager  # noqa: F401
from pathlib import Path
from typing import Annotated  # noqa: F401

import dotenv
import uvicorn
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from transformers import AutoModel, AutoTokenizer

from common import dependencies as DI  # noqa: F401
from common.common import configure_logging
from common.configuration import Configuration
from routes.auth import router as auth_router
from routes.dataset import router as dataset_router
from routes.document import router as document_router
from routes.entity import router as entity_router
from routes.evaluation import router as evaluation_router
from routes.llm import router as llm_router
from routes.llm_config import router as llm_config_router
from routes.llm_prompt import router as llm_prompt_router

# Защита от автоудаления линтером
_ = DI
_ = Annotated
_ = asynccontextmanager

# Загружаем переменные из .env
dotenv.load_dotenv()

CONFIG_PATH = os.environ.get('CONFIG_PATH', 'config_dev.yaml')
print("config path: ")
print(CONFIG_PATH)
config = Configuration(CONFIG_PATH)

logger = logging.getLogger(__name__)

configure_logging(
    level=config.common_config.log_level, 
    config_file_path=config.common_config.log_file_path, 
)

# Костыль №47364: Удаляем файл статуса обработки датасета при запуске приложения
tmp_path = Path(os.environ.get("APP_TMP_PATH", '.')) / 'tmp.json'
tmp_path.unlink(missing_ok=True)

print("Downloading model to cache...")
AutoTokenizer.from_pretrained(config.db_config.search.vectorizer_path)
AutoModel.from_pretrained(config.db_config.search.vectorizer_path)
print("Model cached successfully.")
            
app = FastAPI(title="Assistant control panel")
    
origins = ["*"]

app.add_middleware(
    CORSMiddleware,
    allow_origins=origins,
    allow_credentials=True,
    allow_methods=["*"],
    allow_headers=["*"],
)

app.include_router(llm_router)
app.include_router(dataset_router)
app.include_router(document_router)
app.include_router(llm_config_router)
app.include_router(llm_prompt_router)
app.include_router(entity_router)
app.include_router(evaluation_router)
app.include_router(auth_router)


if __name__ == "__main__":
    uvicorn.run(
        "main:app",
        host="localhost",
        port=8885,
        reload=True,
        workers=4
    )