Skip to content
This repository has been archived by the owner on Jan 15, 2025. It is now read-only.

Dockerized application. Added UI #2

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
OPENAI_API_KEY=your_api_key_here
53 changes: 50 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,61 @@
/lib
/lib64
/share
/app/chroma_db
/chunks
/logs
backend/chunks
backend/logs/*
/app/utils/__pycache__
/node_modules
backend/chroma_db/*
backend/chunks/*

# Ignore files #
################
*.cfg
*.bin
*.keep
.idea
.idea
__pycache__

# Python #
##########
*.py[cod]
*.pyo
*.pyd
*.env
*.venv
env/
venv/
ENV/
VENV/
*.egg
*.egg-info
dist/
build/
*.manifest
*.spec

# Jupyter Notebooks #
#####################
.ipynb_checkpoints

# macOS #
#########
.DS_Store

# Windows #
###########
Thumbs.db
ehthumbs.db
Desktop.ini
$RECYCLE.BIN/

# Logs and databases #
######################
*.log
*.sql
*.sqlite

# VS Code #
###########
.vscode/
24 changes: 24 additions & 0 deletions backend/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
FROM python:3.12-slim

WORKDIR /app

# Install system dependencies
RUN apt-get update && apt-get install -y \
build-essential \
curl \
&& rm -rf /var/lib/apt/lists/*

# Install Python dependencies
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt

# Copy application code
COPY . .

ENV PYTHONPATH=/app

# Expose the API port
EXPOSE 8000

# Run the FastAPI application
CMD ["uvicorn", "api.base_api:app", "--host", "0.0.0.0", "--port", "8000", "--reload"]
File renamed without changes.
Empty file added backend/app/api/ __init__.py
Empty file.
79 changes: 79 additions & 0 deletions backend/app/api/base_api.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
from fastapi import FastAPI, HTTPException
from fastapi.middleware.cors import CORSMiddleware
from pydantic import BaseModel

import sys
sys.path.append("app")
from ..main import NexusPJLLM
from utils.ingerir import extractor, sintetizador_respuesta, guardar_nodos, embedding_model
from utils.logs import logger

app = FastAPI()

# Configure CORS middleware
app.add_middleware(
CORSMiddleware,
allow_origins=["*"],
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)

class ConsultaRequest(BaseModel):
consulta: str

class Respuesta(BaseModel):
respuesta: str

class NodosResponse(BaseModel):
nodos: list

nexus = NexusPJLLM()

@app.post("/extraer", response_model=NodosResponse)
async def extraer(request: ConsultaRequest):
try:
consulta = request.consulta
nodes = extractor(consulta, embedding_model)

# Handle case where extractor returns None or empty results
if not nodes:
return {"nodos": []}

retrieved_nodes = nexus.procesar_consulta(consulta)
guardar_nodos(nodes)

return {
"nodos": [
{"metadata": node.metadata, "texto": node.text}
for node in retrieved_nodes
]
}
except Exception as e:
logger.error(f"Error procesando consulta: {str(e)}")
raise HTTPException(
status_code=500,
detail=f"Error procesando consulta: {str(e)}"
)

@app.post("/sintetizar", response_model=Respuesta)
async def sintetizar(request: ConsultaRequest):
try:
consulta = request.consulta
retrieved_nodes = nexus.procesar_consulta(consulta, reranker=True)
respuesta = sintetizador_respuesta(consulta, retrieved_nodes)
respuesta = str(respuesta)
return {"respuesta": respuesta}
except Exception as e:
logger.error(f"Error en opción 2: {str(e)}")
raise HTTPException(status_code=500, detail=f"Error en opción 2: {str(e)}")

@app.post("/buscar", response_model=NodosResponse)
async def buscar(request: ConsultaRequest):
try:
consulta = request.consulta
retrieved_nodes = nexus.procesar_consulta(consulta, reranker=True)
return {"nodos": [{"metadata": node.metadata, "texto": node.text} for node in retrieved_nodes]}
except Exception as e:
logger.error(f"Error en opción 3: {str(e)}")
raise HTTPException(status_code=500, detail=f"Error en opción 3: {str(e)}")
File renamed without changes.
Empty file added backend/app/utils/ __init__.py
Empty file.
File renamed without changes.
File renamed without changes.
176 changes: 176 additions & 0 deletions backend/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
aiohappyeyeballs==2.4.3 ; python_version >= "3.12" and python_version < "4.0"
aiohttp==3.11.7 ; python_version >= "3.12" and python_version < "4.0"
aiosignal==1.3.1 ; python_version >= "3.12" and python_version < "4.0"
annotated-types==0.7.0 ; python_version >= "3.12" and python_version < "4.0"
anyio==4.6.2.post1 ; python_version >= "3.12" and python_version < "4.0"
asgiref==3.8.1 ; python_version >= "3.12" and python_version < "4.0"
attrs==24.2.0 ; python_version >= "3.12" and python_version < "4.0"
backoff==2.2.1 ; python_version >= "3.12" and python_version < "4.0"
bcrypt==4.2.1 ; python_version >= "3.12" and python_version < "4.0"
beautifulsoup4==4.12.3 ; python_version >= "3.12" and python_version < "4.0"
build==1.2.2.post1 ; python_version >= "3.12" and python_version < "4.0"
cachetools==5.5.0 ; python_version >= "3.12" and python_version < "4.0"
certifi==2024.8.30 ; python_version >= "3.12" and python_version < "4.0"
charset-normalizer==3.4.0 ; python_version >= "3.12" and python_version < "4.0"
chroma-hnswlib==0.7.6 ; python_version >= "3.12" and python_version < "4.0"
chroma==0.2.0 ; python_version >= "3.12" and python_version < "4.0"
chromadb==0.5.20 ; python_version >= "3.12" and python_version < "4.0"
click==8.1.7 ; python_version >= "3.12" and python_version < "4.0"
colorama==0.4.6 ; python_version >= "3.12" and python_version < "4.0" and (sys_platform == "win32" or os_name == "nt" or platform_system == "Windows")
coloredlogs==15.0.1 ; python_version >= "3.12" and python_version < "4.0"
colorlog==6.9.0 ; python_version >= "3.12" and python_version < "4.0"
dataclasses-json==0.6.7 ; python_version >= "3.12" and python_version < "4.0"
deprecated==1.2.15 ; python_version >= "3.12" and python_version < "4.0"
dirtyjson==1.0.8 ; python_version >= "3.12" and python_version < "4.0"
distro==1.9.0 ; python_version >= "3.12" and python_version < "4.0"
durationpy==0.9 ; python_version >= "3.12" and python_version < "4.0"
fastapi==0.115.5 ; python_version >= "3.12" and python_version < "4.0"
filelock==3.16.1 ; python_version >= "3.12" and python_version < "4.0"
filetype==1.2.0 ; python_version >= "3.12" and python_version < "4.0"
flatbuffers==24.3.25 ; python_version >= "3.12" and python_version < "4.0"
frozenlist==1.5.0 ; python_version >= "3.12" and python_version < "4.0"
fsspec==2024.10.0 ; python_version >= "3.12" and python_version < "4.0"
google-auth==2.36.0 ; python_version >= "3.12" and python_version < "4.0"
googleapis-common-protos==1.66.0 ; python_version >= "3.12" and python_version < "4.0"
greenlet==3.1.1 ; python_version >= "3.12" and python_version < "4.0"
grpcio==1.68.0 ; python_version >= "3.12" and python_version < "4.0"
h11==0.14.0 ; python_version >= "3.12" and python_version < "4.0"
httpcore==1.0.7 ; python_version >= "3.12" and python_version < "4.0"
httptools==0.6.4 ; python_version >= "3.12" and python_version < "4.0"
httpx==0.27.2 ; python_version >= "3.12" and python_version < "4.0"
huggingface-hub==0.26.2 ; python_version >= "3.12" and python_version < "4.0"
humanfriendly==10.0 ; python_version >= "3.12" and python_version < "4.0"
idna==3.10 ; python_version >= "3.12" and python_version < "4.0"
importlib-metadata==8.5.0 ; python_version >= "3.12" and python_version < "4.0"
importlib-resources==6.4.5 ; python_version >= "3.12" and python_version < "4.0"
jinja2==3.1.4 ; python_version >= "3.12" and python_version < "4.0"
jiter==0.7.1 ; python_version >= "3.12" and python_version < "4.0"
joblib==1.4.2 ; python_version >= "3.12" and python_version < "4.0"
jsonpatch==1.33 ; python_version >= "3.12" and python_version < "4.0"
jsonpointer==3.0.0 ; python_version >= "3.12" and python_version < "4.0"
keybert==0.8.5 ; python_version >= "3.12" and python_version < "4.0"
kubernetes==31.0.0 ; python_version >= "3.12" and python_version < "4.0"
langchain-core==0.3.21 ; python_version >= "3.12" and python_version < "4.0"
langchain-text-splitters==0.3.2 ; python_version >= "3.12" and python_version < "4.0"
langchain==0.3.8 ; python_version >= "3.12" and python_version < "4.0"
langsmith==0.1.146 ; python_version >= "3.12" and python_version < "4.0"
llama-cloud==0.1.5 ; python_version >= "3.12" and python_version < "4"
llama-index-agent-openai==0.4.0 ; python_version >= "3.12" and python_version < "4.0"
llama-index-cli==0.4.0 ; python_version >= "3.12" and python_version < "4.0"
llama-index-core==0.12.1 ; python_version >= "3.12" and python_version < "4.0"
llama-index-embeddings-ollama==0.4.0 ; python_version >= "3.12" and python_version < "4.0"
llama-index-embeddings-openai==0.3.0 ; python_version >= "3.12" and python_version < "4.0"
llama-index-indices-managed-llama-cloud==0.6.2 ; python_version >= "3.12" and python_version < "4.0"
llama-index-legacy==0.9.48.post4 ; python_version >= "3.12" and python_version < "4.0"
llama-index-llms-ollama==0.4.1 ; python_version >= "3.12" and python_version < "4.0"
llama-index-llms-openai==0.3.2 ; python_version >= "3.12" and python_version < "4.0"
llama-index-multi-modal-llms-openai==0.3.0 ; python_version >= "3.12" and python_version < "4.0"
llama-index-program-openai==0.3.1 ; python_version >= "3.12" and python_version < "4.0"
llama-index-question-gen-openai==0.3.0 ; python_version >= "3.12" and python_version < "4.0"
llama-index-readers-file==0.4.0 ; python_version >= "3.12" and python_version < "4.0"
llama-index-readers-llama-parse==0.4.0 ; python_version >= "3.12" and python_version < "4.0"
llama-index-vector-stores-chroma==0.4.0 ; python_version >= "3.12" and python_version < "4.0"
llama-index==0.12.1 ; python_version >= "3.12" and python_version < "4.0"
llama-parse==0.5.15 ; python_version >= "3.12" and python_version < "4.0"
markdown-it-py==3.0.0 ; python_version >= "3.12" and python_version < "4.0"
markupsafe==3.0.2 ; python_version >= "3.12" and python_version < "4.0"
marshmallow==3.23.1 ; python_version >= "3.12" and python_version < "4.0"
mdurl==0.1.2 ; python_version >= "3.12" and python_version < "4.0"
mmh3==5.0.1 ; python_version >= "3.12" and python_version < "4.0"
monotonic==1.6 ; python_version >= "3.12" and python_version < "4.0"
mpmath==1.3.0 ; python_version >= "3.12" and python_version < "4.0"
multidict==6.1.0 ; python_version >= "3.12" and python_version < "4.0"
mypy-extensions==1.0.0 ; python_version >= "3.12" and python_version < "4.0"
nest-asyncio==1.6.0 ; python_version >= "3.12" and python_version < "4.0"
networkx==3.4.2 ; python_version >= "3.12" and python_version < "4.0"
nltk==3.9.1 ; python_version >= "3.12" and python_version < "4.0"
numpy==1.26.4 ; python_version >= "3.12" and python_version < "4.0"
nvidia-cublas-cu12==12.4.5.8 ; platform_system == "Linux" and platform_machine == "x86_64" and python_version >= "3.12" and python_version < "4.0"
nvidia-cuda-cupti-cu12==12.4.127 ; platform_system == "Linux" and platform_machine == "x86_64" and python_version >= "3.12" and python_version < "4.0"
nvidia-cuda-nvrtc-cu12==12.4.127 ; platform_system == "Linux" and platform_machine == "x86_64" and python_version >= "3.12" and python_version < "4.0"
nvidia-cuda-runtime-cu12==12.4.127 ; platform_system == "Linux" and platform_machine == "x86_64" and python_version >= "3.12" and python_version < "4.0"
nvidia-cudnn-cu12==9.1.0.70 ; platform_system == "Linux" and platform_machine == "x86_64" and python_version >= "3.12" and python_version < "4.0"
nvidia-cufft-cu12==11.2.1.3 ; platform_system == "Linux" and platform_machine == "x86_64" and python_version >= "3.12" and python_version < "4.0"
nvidia-curand-cu12==10.3.5.147 ; platform_system == "Linux" and platform_machine == "x86_64" and python_version >= "3.12" and python_version < "4.0"
nvidia-cusolver-cu12==11.6.1.9 ; platform_system == "Linux" and platform_machine == "x86_64" and python_version >= "3.12" and python_version < "4.0"
nvidia-cusparse-cu12==12.3.1.170 ; platform_system == "Linux" and platform_machine == "x86_64" and python_version >= "3.12" and python_version < "4.0"
nvidia-nccl-cu12==2.21.5 ; platform_system == "Linux" and platform_machine == "x86_64" and python_version >= "3.12" and python_version < "4.0"
nvidia-nvjitlink-cu12==12.4.127 ; platform_system == "Linux" and platform_machine == "x86_64" and python_version >= "3.12" and python_version < "4.0"
nvidia-nvtx-cu12==12.4.127 ; platform_system == "Linux" and platform_machine == "x86_64" and python_version >= "3.12" and python_version < "4.0"
oauthlib==3.2.2 ; python_version >= "3.12" and python_version < "4.0"
ollama==0.3.3 ; python_version >= "3.12" and python_version < "4.0"
onnxruntime==1.20.1 ; python_version >= "3.12" and python_version < "4.0"
openai==1.55.1 ; python_version >= "3.12" and python_version < "4.0"
opentelemetry-api==1.28.2 ; python_version >= "3.12" and python_version < "4.0"
opentelemetry-exporter-otlp-proto-common==1.28.2 ; python_version >= "3.12" and python_version < "4.0"
opentelemetry-exporter-otlp-proto-grpc==1.28.2 ; python_version >= "3.12" and python_version < "4.0"
opentelemetry-instrumentation-asgi==0.49b2 ; python_version >= "3.12" and python_version < "4.0"
opentelemetry-instrumentation-fastapi==0.49b2 ; python_version >= "3.12" and python_version < "4.0"
opentelemetry-instrumentation==0.49b2 ; python_version >= "3.12" and python_version < "4.0"
opentelemetry-proto==1.28.2 ; python_version >= "3.12" and python_version < "4.0"
opentelemetry-sdk==1.28.2 ; python_version >= "3.12" and python_version < "4.0"
opentelemetry-semantic-conventions==0.49b2 ; python_version >= "3.12" and python_version < "4.0"
opentelemetry-util-http==0.49b2 ; python_version >= "3.12" and python_version < "4.0"
orjson==3.10.12 ; python_version >= "3.12" and python_version < "4.0"
overrides==7.7.0 ; python_version >= "3.12" and python_version < "4.0"
packaging==24.2 ; python_version >= "3.12" and python_version < "4.0"
pandas==2.2.3 ; python_version >= "3.12" and python_version < "4.0"
pillow==11.0.0 ; python_version >= "3.12" and python_version < "4.0"
posthog==3.7.3 ; python_version >= "3.12" and python_version < "4.0"
propcache==0.2.0 ; python_version >= "3.12" and python_version < "4.0"
protobuf==5.28.3 ; python_version >= "3.12" and python_version < "4.0"
pyasn1-modules==0.4.1 ; python_version >= "3.12" and python_version < "4.0"
pyasn1==0.6.1 ; python_version >= "3.12" and python_version < "4.0"
pydantic-core==2.23.4 ; python_version >= "3.12" and python_version < "4.0"
pydantic==2.9.2 ; python_version >= "3.12" and python_version < "4.0"
pygments==2.18.0 ; python_version >= "3.12" and python_version < "4.0"
pypdf==5.1.0 ; python_version >= "3.12" and python_version < "4.0"
pypika==0.48.9 ; python_version >= "3.12" and python_version < "4.0"
pyproject-hooks==1.2.0 ; python_version >= "3.12" and python_version < "4.0"
pyreadline3==3.5.4 ; sys_platform == "win32" and python_version >= "3.12" and python_version < "4.0"
python-dateutil==2.9.0.post0 ; python_version >= "3.12" and python_version < "4.0"
python-dotenv==1.0.1 ; python_version >= "3.12" and python_version < "4.0"
pytz==2024.2 ; python_version >= "3.12" and python_version < "4.0"
pyyaml==6.0.2 ; python_version >= "3.12" and python_version < "4.0"
regex==2024.11.6 ; python_version >= "3.12" and python_version < "4.0"
requests-oauthlib==2.0.0 ; python_version >= "3.12" and python_version < "4.0"
requests-toolbelt==1.0.0 ; python_version >= "3.12" and python_version < "4.0"
requests==2.32.3 ; python_version >= "3.12" and python_version < "4.0"
rich==13.9.4 ; python_version >= "3.12" and python_version < "4.0"
rsa==4.9 ; python_version >= "3.12" and python_version < "4"
safetensors==0.4.5 ; python_version >= "3.12" and python_version < "4.0"
scikit-learn==1.5.2 ; python_version >= "3.12" and python_version < "4.0"
scipy==1.14.1 ; python_version >= "3.12" and python_version < "4.0"
sentence-transformers==3.3.1 ; python_version >= "3.12" and python_version < "4.0"
setuptools==75.6.0 ; python_version >= "3.12" and python_version < "4.0"
shellingham==1.5.4 ; python_version >= "3.12" and python_version < "4.0"
six==1.16.0 ; python_version >= "3.12" and python_version < "4.0"
sniffio==1.3.1 ; python_version >= "3.12" and python_version < "4.0"
soupsieve==2.6 ; python_version >= "3.12" and python_version < "4.0"
sqlalchemy==2.0.36 ; python_version >= "3.12" and python_version < "4.0"
sqlalchemy[asyncio]==2.0.36 ; python_version >= "3.12" and python_version < "4.0"
starlette==0.41.3 ; python_version >= "3.12" and python_version < "4.0"
striprtf==0.0.26 ; python_version >= "3.12" and python_version < "4.0"
sympy==1.13.1 ; python_version >= "3.12" and python_version < "4.0"
tenacity==8.5.0 ; python_version >= "3.12" and python_version < "4.0"
threadpoolctl==3.5.0 ; python_version >= "3.12" and python_version < "4.0"
tiktoken==0.8.0 ; python_version >= "3.12" and python_version < "4.0"
tokenizers==0.20.3 ; python_version >= "3.12" and python_version < "4.0"
torch==2.5.1 ; python_version >= "3.12" and python_version < "4.0"
tqdm==4.67.1 ; python_version >= "3.12" and python_version < "4.0"
transformers==4.46.3 ; python_version >= "3.12" and python_version < "4.0"
triton==3.1.0 ; platform_system == "Linux" and platform_machine == "x86_64" and python_version < "3.13" and python_version >= "3.12"
typer==0.13.1 ; python_version >= "3.12" and python_version < "4.0"
typing-extensions==4.12.2 ; python_version >= "3.12" and python_version < "4.0"
typing-inspect==0.9.0 ; python_version >= "3.12" and python_version < "4.0"
tzdata==2024.2 ; python_version >= "3.12" and python_version < "4.0"
urllib3==2.2.3 ; python_version >= "3.12" and python_version < "4.0"
uvicorn==0.32.1 ; python_version >= "3.12" and python_version < "4.0"
uvicorn[standard]==0.32.1 ; python_version >= "3.12" and python_version < "4.0"
uvloop==0.21.0 ; (sys_platform != "win32" and sys_platform != "cygwin") and platform_python_implementation != "PyPy" and python_version >= "3.12" and python_version < "4.0"
watchfiles==1.0.0 ; python_version >= "3.12" and python_version < "4.0"
websocket-client==1.8.0 ; python_version >= "3.12" and python_version < "4.0"
websockets==14.1 ; python_version >= "3.12" and python_version < "4.0"
wrapt==1.17.0 ; python_version >= "3.12" and python_version < "4.0"
yarl==1.18.0 ; python_version >= "3.12" and python_version < "4.0"
zipp==3.21.0 ; python_version >= "3.12" and python_version < "4.0"
Loading