Add logger config
This commit is contained in:
parent
95936798d1
commit
f9f1982442
37
src/config.py
Normal file
37
src/config.py
Normal file
@ -0,0 +1,37 @@
|
||||
import envyaml
|
||||
import os
|
||||
import logging
|
||||
from logging import Formatter, StreamHandler
|
||||
|
||||
config = envyaml.EnvYAML(os.environ.get('CONFIG_PATH', 'config.yaml'))
|
||||
|
||||
def initLogger() -> None:
|
||||
"""
|
||||
Initializes the logger
|
||||
"""
|
||||
# style the logger output to look like uvicorn for root app
|
||||
FORMAT = '%(asctime)-15s %(levelname)s %(message)s'
|
||||
DATE_FORMAT = '%b %d %H:%M:%S'
|
||||
formatter = Formatter(fmt=FORMAT, datefmt=DATE_FORMAT)
|
||||
handler = StreamHandler()
|
||||
handler.setFormatter(formatter)
|
||||
logger = logging.getLogger()
|
||||
|
||||
# remove default handler
|
||||
logger.handlers = []
|
||||
logger.addHandler(handler)
|
||||
|
||||
if config["app.log.level"] == 'debug':
|
||||
logging.basicConfig(level=logging.DEBUG)
|
||||
elif config["app.log.level"] == 'info':
|
||||
logging.basicConfig(level=logging.INFO)
|
||||
elif config["app.log.level"] == 'warning':
|
||||
logging.basicConfig(level=logging.WARNING)
|
||||
elif config["app.log.level"] == 'error':
|
||||
logging.basicConfig(level=logging.ERROR)
|
||||
elif config["app.log.level"] == 'critical':
|
||||
logging.basicConfig(level=logging.CRITICAL)
|
||||
else:
|
||||
logging.basicConfig(level=logging.INFO)
|
||||
logging.warning("Invalid log level. Using INFO as default")
|
||||
|
6
src/config.yaml
Normal file
6
src/config.yaml
Normal file
@ -0,0 +1,6 @@
|
||||
weaviate:
|
||||
url: "localhost:"
|
||||
|
||||
app:
|
||||
log:
|
||||
level: ""
|
0
src/internal/__init__.py
Normal file
0
src/internal/__init__.py
Normal file
0
src/internal/chain.py
Normal file
0
src/internal/chain.py
Normal file
3
src/internal/documents.py
Normal file
3
src/internal/documents.py
Normal file
@ -0,0 +1,3 @@
|
||||
|
||||
from langchain.text_splitter import SpacyTextSplitter
|
||||
|
20
src/main.py
20
src/main.py
@ -1,8 +1,24 @@
|
||||
from fastapi import FastAPI
|
||||
from fastapi import FastAPI, status
|
||||
from fastapi.responses import RedirectResponse
|
||||
|
||||
from routers import question
|
||||
from routers import question, documents
|
||||
|
||||
import logging
|
||||
from config import config, initLogger
|
||||
|
||||
initLogger()
|
||||
|
||||
app = FastAPI()
|
||||
|
||||
app.include_router(question.router)
|
||||
app.include_router(documents.router)
|
||||
|
||||
logging.warn("Test message")
|
||||
|
||||
|
||||
@app.get("/")
|
||||
async def root():
|
||||
"""
|
||||
Redirects to the docs page
|
||||
"""
|
||||
return RedirectResponse(url="/docs", status_code=status.HTTP_303_SEE_OTHER)
|
||||
|
60
src/routers/documents.py
Normal file
60
src/routers/documents.py
Normal file
@ -0,0 +1,60 @@
|
||||
from fastapi import APIRouter
|
||||
from pydantic import BaseModel
|
||||
from enum import Enum
|
||||
|
||||
router = APIRouter(
|
||||
prefix="/documents",
|
||||
tags=["documents"],
|
||||
responses={404: {"description": "Not found"}},
|
||||
)
|
||||
|
||||
class Document(BaseModel):
|
||||
id: int
|
||||
title: str
|
||||
content: str
|
||||
|
||||
# Document Type enum
|
||||
class DocumentType(str, Enum):
|
||||
markdown = "md"
|
||||
#html = "html"
|
||||
#pdf = "pdf"
|
||||
epub = "epub"
|
||||
odt = "odt"
|
||||
docx = "docx"
|
||||
|
||||
|
||||
@router.get("/{document_type}")
|
||||
async def read_documents(document_type: DocumentType):
|
||||
"""
|
||||
Get all documents
|
||||
"""
|
||||
pass
|
||||
|
||||
@router.get("/{document_id}")
|
||||
async def read_document(document_id: int):
|
||||
"""
|
||||
Get a specific document
|
||||
"""
|
||||
pass
|
||||
|
||||
@router.post("/")
|
||||
async def create_document(document: Document):
|
||||
"""
|
||||
Create a new document
|
||||
"""
|
||||
pass
|
||||
|
||||
@router.put("/{document_id}")
|
||||
async def update_document(document_id: int, document: Document):
|
||||
"""
|
||||
Update a document
|
||||
"""
|
||||
pass
|
||||
|
||||
@router.delete("/{document_id}")
|
||||
async def delete_document(document_id: int):
|
||||
"""
|
||||
Delete a document
|
||||
"""
|
||||
pass
|
||||
|
Loading…
Reference in New Issue
Block a user