feat: Implement text manager API and database connection
- Added `text_manager.py` to handle the creation of text libraries via FastAPI. - Introduced database connection management in `conexion.py` using PostgreSQL credentials from environment variables. - Created abstract base class `EmbedderABC` in `Base_Embedder.py` for embedding models. - Developed `OpenAIEmbedder` class to generate embeddings using OpenAI's API. - Implemented `OpenAIEmbedderModel` and repository pattern for managing OpenAI embedders in `Openai_embedder_mmr.py`. - Established `Biblioteca` class for managing text libraries and their associated notes in `biblioteca.py`. - Created SQLAlchemy models and mappers for `Biblioteca` and `Nota` in `biblioteca_mmr.py` and `notas_biblioteca_mmr.py`. - Added functionality for dynamic table generation for notes associated with libraries. - Included comprehensive methods for adding, retrieving, and managing notes and libraries in their respective repositories.
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
from fastapi import APIRouter, HTTPException
|
||||
from pydantic import BaseModel
|
||||
from typing import Optional
|
||||
from backend.db.conexion import get_conexion
|
||||
from src.TextManager.biblioteca import Biblioteca
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
class BibliotecaIn(BaseModel):
|
||||
nombre: str
|
||||
descripcion: Optional[str] = ""
|
||||
vector_dim: Optional[int] = None
|
||||
|
||||
@router.post("/")
|
||||
def crear_biblioteca(biblio: BibliotecaIn):
|
||||
try:
|
||||
biblioteca = Biblioteca(
|
||||
nombre=biblio.nombre,
|
||||
descripcion=biblio.descripcion,
|
||||
vector_dim=biblio.vector_dim
|
||||
)
|
||||
conexion = get_conexion()
|
||||
modelo = biblioteca.generar_modelo_notas(conexion)
|
||||
return {"id": biblioteca.id, "modelo": str(modelo.__name__)}
|
||||
except Exception as e:
|
||||
raise HTTPException(status_code=400, detail=str(e))
|
||||
@@ -1,7 +1,8 @@
|
||||
# backend/api/router.py
|
||||
|
||||
from fastapi import APIRouter
|
||||
from backend.api.v1.endpoints import ping
|
||||
from backend.api.v1.endpoints import ping, nota, text_manager
|
||||
|
||||
router = APIRouter()
|
||||
router.include_router(ping.router, prefix="/api/v1")
|
||||
router.include_router(ping.router, prefix="/api/v1/ping")
|
||||
router.include_router(text_manager.router, prefix="/api/v1/bibliotecas")
|
||||
@@ -0,0 +1,19 @@
|
||||
from src.ConexionSql.Postgres_conexion import PostgresConexion
|
||||
from src.Credenciales.postgres_credencial import PostgresCredencial
|
||||
from dotenv import load_dotenv
|
||||
import os
|
||||
from entrypoint import ENV_PATH
|
||||
|
||||
# Cargar .env
|
||||
load_dotenv(ENV_PATH)
|
||||
|
||||
def get_conexion():
|
||||
db_credencial = PostgresCredencial(
|
||||
titulo=os.getenv("DB_TITLE"),
|
||||
user=os.getenv("DB_USER"),
|
||||
password=os.getenv("DB_PASSWORD"),
|
||||
host=os.getenv("DB_HOST"),
|
||||
port=os.getenv("DB_PORT"),
|
||||
dbname=os.getenv("DB_NAME")
|
||||
)
|
||||
return PostgresConexion(db_credencial)
|
||||
+1
-1
@@ -13,7 +13,7 @@ app = FastAPI(
|
||||
# Configuración de CORS
|
||||
app.add_middleware(
|
||||
CORSMiddleware,
|
||||
allow_origins=["http://localhost:5173"], # Solo permite tu frontend local
|
||||
allow_origins=["http://localhost:5173", "http://0.0.0.0:5173"], # Solo permite tu frontend local
|
||||
allow_credentials=True,
|
||||
allow_methods=["*"],
|
||||
allow_headers=["*"],
|
||||
|
||||
Reference in New Issue
Block a user