From 895a367c17ee14aa8ed04d38dd7f1f2a9389b95b Mon Sep 17 00:00:00 2001 From: pavanmantha Date: Tue, 24 Sep 2024 03:42:11 +0530 Subject: [PATCH 1/5] -created the required configs for pypi --- .github/workflows/python-app.yml | 22 +++++++++++++++++++++- MANIFEST.in | 1 + __init__.py | 0 setup.py | 14 +++++++++----- 4 files changed, 31 insertions(+), 6 deletions(-) create mode 100644 MANIFEST.in create mode 100644 __init__.py diff --git a/.github/workflows/python-app.yml b/.github/workflows/python-app.yml index 5216a63..8a2dbb6 100644 --- a/.github/workflows/python-app.yml +++ b/.github/workflows/python-app.yml @@ -36,4 +36,24 @@ jobs: flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics - name: Test with pytest run: | - pytest \ No newline at end of file + pytest + + deploy: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Set up Python + uses: actions/setup-python@v2 + with: + python-version: '3.10' + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install setuptools wheel twine + - name: Build and publish + env: + TWINE_USERNAME: __token__ + TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }} + run: | + python setup.py sdist bdist_wheel + twine upload dist/* \ No newline at end of file diff --git a/MANIFEST.in b/MANIFEST.in new file mode 100644 index 0000000..ba2aec4 --- /dev/null +++ b/MANIFEST.in @@ -0,0 +1 @@ +recursive-include bootstraprag/templates * \ No newline at end of file diff --git a/__init__.py b/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/setup.py b/setup.py index c8f195e..de3cc8d 100644 --- a/setup.py +++ b/setup.py @@ -8,8 +8,12 @@ install_requires=[ 'click', ], - entry_points=''' - [console_scripts] - bootstraprag=bootstraprag.cli:cli - ''', -) + entry_points={ + 'console_scripts': [ + 'bootstraprag=bootstraprag.cli:cli', + ], + }, + package_data={ + 'bootstraprag': ['templates/*'], + }, +) \ No newline at end of file From 1ee5eaf673a635f3ced06aeae3ad5f1784c89652 Mon Sep 17 00:00:00 2001 From: pavanmantha Date: Tue, 24 Sep 2024 06:48:32 +0530 Subject: [PATCH 2/5] -modified the configs accordingly --- .github/workflows/python-app.yml | 9 ++++++--- setup.py | 8 +++++++- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/.github/workflows/python-app.yml b/.github/workflows/python-app.yml index 8a2dbb6..d6f2e3e 100644 --- a/.github/workflows/python-app.yml +++ b/.github/workflows/python-app.yml @@ -5,9 +5,12 @@ name: Python application on: push: - branches: [ "main" ] - pull_request: - branches: [ "main" ] + branches: + - main +# uncomment the below code to enable actions on PR branch also. +# pull_request: +# branches: +# - main permissions: contents: read diff --git a/setup.py b/setup.py index de3cc8d..c514dff 100644 --- a/setup.py +++ b/setup.py @@ -1,8 +1,14 @@ from setuptools import setup, find_packages +import pathlib + +doc_path = pathlib.Path(__file__).parent.resolve() +long_description = (doc_path / "README.md").read_text(encoding="utf-8") setup( name='bootstrap-rag', - version='0.0.4', + version='0.0.5', + long_description=long_description, + long_description_content_type="text/markdown", packages=find_packages(), include_package_data=True, install_requires=[ From eea659a3f6c033578ecfc319ea15aebc8798face Mon Sep 17 00:00:00 2001 From: pavanmantha Date: Wed, 25 Sep 2024 10:23:13 +0530 Subject: [PATCH 3/5] -implemented fastapi support for all the RAG templates --- .../rag_with_flare/api_core/__init__.py | 0 .../rag_with_flare/api_core/config.py | 5 + .../rag_with_flare/api_routes/__init__.py | 0 .../rag_with_flare/api_routes/apis.py | 14 +++ .../llamaindex/rag_with_flare/apis.py | 110 ++++++++++++++++++ .../rag_with_flare/models/__init__.py | 0 .../rag_with_flare/models/payload.py | 5 + .../rag_with_hyde/api_core/__init__.py | 0 .../rag_with_hyde/api_core/config.py | 5 + .../rag_with_hyde/api_routes/__init__.py | 0 .../rag_with_hyde/api_routes/apis.py | 14 +++ .../llamaindex/rag_with_hyde/apis.py | 110 ++++++++++++++++++ .../rag_with_hyde/models/__init__.py | 0 .../rag_with_hyde/models/payload.py | 5 + .../api_core/__init__.py | 0 .../api_core/config.py | 5 + .../api_routes/__init__.py | 0 .../api_routes/apis.py | 14 +++ .../rag_with_hyde_with_observability/apis.py | 110 ++++++++++++++++++ .../models/__init__.py | 0 .../models/payload.py | 5 + .../rag_with_react/api_core/__init__.py | 0 .../rag_with_react/api_core/config.py | 5 + .../rag_with_react/api_routes/__init__.py | 0 .../rag_with_react/api_routes/apis.py | 14 +++ .../llamaindex/rag_with_react/apis.py | 110 ++++++++++++++++++ .../rag_with_react/models/__init__.py | 0 .../rag_with_react/models/payload.py | 5 + .../api_core/__init__.py | 0 .../api_core/config.py | 5 + .../api_routes/__init__.py | 0 .../api_routes/apis.py | 14 +++ .../rag_with_react_with_observability/apis.py | 110 ++++++++++++++++++ .../models/__init__.py | 0 .../models/payload.py | 5 + 35 files changed, 670 insertions(+) create mode 100644 bootstraprag/templates/llamaindex/rag_with_flare/api_core/__init__.py create mode 100644 bootstraprag/templates/llamaindex/rag_with_flare/api_core/config.py create mode 100644 bootstraprag/templates/llamaindex/rag_with_flare/api_routes/__init__.py create mode 100644 bootstraprag/templates/llamaindex/rag_with_flare/api_routes/apis.py create mode 100644 bootstraprag/templates/llamaindex/rag_with_flare/apis.py create mode 100644 bootstraprag/templates/llamaindex/rag_with_flare/models/__init__.py create mode 100644 bootstraprag/templates/llamaindex/rag_with_flare/models/payload.py create mode 100644 bootstraprag/templates/llamaindex/rag_with_hyde/api_core/__init__.py create mode 100644 bootstraprag/templates/llamaindex/rag_with_hyde/api_core/config.py create mode 100644 bootstraprag/templates/llamaindex/rag_with_hyde/api_routes/__init__.py create mode 100644 bootstraprag/templates/llamaindex/rag_with_hyde/api_routes/apis.py create mode 100644 bootstraprag/templates/llamaindex/rag_with_hyde/apis.py create mode 100644 bootstraprag/templates/llamaindex/rag_with_hyde/models/__init__.py create mode 100644 bootstraprag/templates/llamaindex/rag_with_hyde/models/payload.py create mode 100644 bootstraprag/templates/llamaindex/rag_with_hyde_with_observability/api_core/__init__.py create mode 100644 bootstraprag/templates/llamaindex/rag_with_hyde_with_observability/api_core/config.py create mode 100644 bootstraprag/templates/llamaindex/rag_with_hyde_with_observability/api_routes/__init__.py create mode 100644 bootstraprag/templates/llamaindex/rag_with_hyde_with_observability/api_routes/apis.py create mode 100644 bootstraprag/templates/llamaindex/rag_with_hyde_with_observability/apis.py create mode 100644 bootstraprag/templates/llamaindex/rag_with_hyde_with_observability/models/__init__.py create mode 100644 bootstraprag/templates/llamaindex/rag_with_hyde_with_observability/models/payload.py create mode 100644 bootstraprag/templates/llamaindex/rag_with_react/api_core/__init__.py create mode 100644 bootstraprag/templates/llamaindex/rag_with_react/api_core/config.py create mode 100644 bootstraprag/templates/llamaindex/rag_with_react/api_routes/__init__.py create mode 100644 bootstraprag/templates/llamaindex/rag_with_react/api_routes/apis.py create mode 100644 bootstraprag/templates/llamaindex/rag_with_react/apis.py create mode 100644 bootstraprag/templates/llamaindex/rag_with_react/models/__init__.py create mode 100644 bootstraprag/templates/llamaindex/rag_with_react/models/payload.py create mode 100644 bootstraprag/templates/llamaindex/rag_with_react_with_observability/api_core/__init__.py create mode 100644 bootstraprag/templates/llamaindex/rag_with_react_with_observability/api_core/config.py create mode 100644 bootstraprag/templates/llamaindex/rag_with_react_with_observability/api_routes/__init__.py create mode 100644 bootstraprag/templates/llamaindex/rag_with_react_with_observability/api_routes/apis.py create mode 100644 bootstraprag/templates/llamaindex/rag_with_react_with_observability/apis.py create mode 100644 bootstraprag/templates/llamaindex/rag_with_react_with_observability/models/__init__.py create mode 100644 bootstraprag/templates/llamaindex/rag_with_react_with_observability/models/payload.py diff --git a/bootstraprag/templates/llamaindex/rag_with_flare/api_core/__init__.py b/bootstraprag/templates/llamaindex/rag_with_flare/api_core/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/bootstraprag/templates/llamaindex/rag_with_flare/api_core/config.py b/bootstraprag/templates/llamaindex/rag_with_flare/api_core/config.py new file mode 100644 index 0000000..d944427 --- /dev/null +++ b/bootstraprag/templates/llamaindex/rag_with_flare/api_core/config.py @@ -0,0 +1,5 @@ +class Settings: + PROJECT_NAME: str = "Simple RAG as FastAPI Application" + + +settings = Settings() diff --git a/bootstraprag/templates/llamaindex/rag_with_flare/api_routes/__init__.py b/bootstraprag/templates/llamaindex/rag_with_flare/api_routes/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/bootstraprag/templates/llamaindex/rag_with_flare/api_routes/apis.py b/bootstraprag/templates/llamaindex/rag_with_flare/api_routes/apis.py new file mode 100644 index 0000000..82f1533 --- /dev/null +++ b/bootstraprag/templates/llamaindex/rag_with_flare/api_routes/apis.py @@ -0,0 +1,14 @@ +from fastapi import APIRouter, Depends +from models.payload import Payload +from base_rag import BaseRAG + + +base_rag = BaseRAG(show_progress=True, data_path='data') + +router = APIRouter(prefix="/api/v1/rag", tags=["rag"]) + + +@router.post(path='/query') +def fetch_response(payload: Payload): + response = base_rag.query(query_string=payload.query) + return response diff --git a/bootstraprag/templates/llamaindex/rag_with_flare/apis.py b/bootstraprag/templates/llamaindex/rag_with_flare/apis.py new file mode 100644 index 0000000..3a885a5 --- /dev/null +++ b/bootstraprag/templates/llamaindex/rag_with_flare/apis.py @@ -0,0 +1,110 @@ +from fastapi import FastAPI, Request +from fastapi.openapi.utils import get_openapi +from api_routes.apis import router +from fastapi.middleware.cors import CORSMiddleware +import uvicorn +import logging +import time + +logging.basicConfig(level=logging.DEBUG) +logging.basicConfig( + level=logging.INFO, + format="%(asctime)s [%(levelname)s] %(name)s: %(message)s", +) +logger = logging.getLogger(__name__) +allowed_origins = [ + "*" +] + +app = FastAPI( + title="My FastAPI Application", + description="This is a FastAPI implementation for RAG application with Swagger UI configurations.", + version="1.0.0", + docs_url="/documentation", + redoc_url="/redoc", + openapi_url="/openapi.json", + contact={ + "name": "M K Pavan Kumar", + "linkedin": "https://www.linkedin.com", + }, + license_info={ + "name": "MIT License", + "url": "https://opensource.org/licenses/MIT", + }, + terms_of_service="https://www.yourwebsite.com/terms/", +) +app.add_middleware( + CORSMiddleware, + allow_origins=allowed_origins, + allow_credentials=True, + allow_methods=["*"], + allow_headers=["*"], +) +app.include_router(router) + + +# Custom OpenAPI schema generation (optional) +def custom_openapi(): + if app.openapi_schema: + return app.openapi_schema + openapi_schema = get_openapi( + title="RAG APIs", + version="1.0.0", + description="This is a custom OpenAPI schema with additional metadata.", + routes=app.routes, + tags=[ + { + "name": "rag", + "description": "Operations for RAG query.", + } + ], + ) + # Modify openapi_schema as needed + app.openapi_schema = openapi_schema + return app.openapi_schema + + +app.openapi = custom_openapi + + +@app.middleware("http") +async def log_requests(request: Request, call_next): + try: + logger.info(f"Incoming request: {request.method} {request.url}") + response = await call_next(request) + logger.info(f"Response status: {response.status_code}") + return response + except Exception as e: + logger.exception(f"Error processing request: {e}") + raise e + + +# Request Timing Middleware +@app.middleware("http") +async def add_process_time_header(request: Request, call_next): + start_time = time.time() + response = await call_next(request) + process_time = time.time() - start_time + response.headers["X-Process-Time"] = str(process_time) + logger.info(f"Processed in {process_time:.4f} seconds") + return response + + +# Logging Middleware +@app.middleware("http") +async def log_requests(request: Request, call_next): + logger.info(f"Incoming request: {request.method} {request.url}") + response = await call_next(request) + logger.info(f"Response status: {response.status_code}") + return response + + +if __name__ == "__main__": + uvicorn.run( + "apis:app", + host="127.0.0.1", + port=8000, + reload=True, + log_level="info", + workers=1, + ) diff --git a/bootstraprag/templates/llamaindex/rag_with_flare/models/__init__.py b/bootstraprag/templates/llamaindex/rag_with_flare/models/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/bootstraprag/templates/llamaindex/rag_with_flare/models/payload.py b/bootstraprag/templates/llamaindex/rag_with_flare/models/payload.py new file mode 100644 index 0000000..ae09aba --- /dev/null +++ b/bootstraprag/templates/llamaindex/rag_with_flare/models/payload.py @@ -0,0 +1,5 @@ +from pydantic import BaseModel + + +class Payload(BaseModel): + query: str diff --git a/bootstraprag/templates/llamaindex/rag_with_hyde/api_core/__init__.py b/bootstraprag/templates/llamaindex/rag_with_hyde/api_core/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/bootstraprag/templates/llamaindex/rag_with_hyde/api_core/config.py b/bootstraprag/templates/llamaindex/rag_with_hyde/api_core/config.py new file mode 100644 index 0000000..d944427 --- /dev/null +++ b/bootstraprag/templates/llamaindex/rag_with_hyde/api_core/config.py @@ -0,0 +1,5 @@ +class Settings: + PROJECT_NAME: str = "Simple RAG as FastAPI Application" + + +settings = Settings() diff --git a/bootstraprag/templates/llamaindex/rag_with_hyde/api_routes/__init__.py b/bootstraprag/templates/llamaindex/rag_with_hyde/api_routes/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/bootstraprag/templates/llamaindex/rag_with_hyde/api_routes/apis.py b/bootstraprag/templates/llamaindex/rag_with_hyde/api_routes/apis.py new file mode 100644 index 0000000..82f1533 --- /dev/null +++ b/bootstraprag/templates/llamaindex/rag_with_hyde/api_routes/apis.py @@ -0,0 +1,14 @@ +from fastapi import APIRouter, Depends +from models.payload import Payload +from base_rag import BaseRAG + + +base_rag = BaseRAG(show_progress=True, data_path='data') + +router = APIRouter(prefix="/api/v1/rag", tags=["rag"]) + + +@router.post(path='/query') +def fetch_response(payload: Payload): + response = base_rag.query(query_string=payload.query) + return response diff --git a/bootstraprag/templates/llamaindex/rag_with_hyde/apis.py b/bootstraprag/templates/llamaindex/rag_with_hyde/apis.py new file mode 100644 index 0000000..3a885a5 --- /dev/null +++ b/bootstraprag/templates/llamaindex/rag_with_hyde/apis.py @@ -0,0 +1,110 @@ +from fastapi import FastAPI, Request +from fastapi.openapi.utils import get_openapi +from api_routes.apis import router +from fastapi.middleware.cors import CORSMiddleware +import uvicorn +import logging +import time + +logging.basicConfig(level=logging.DEBUG) +logging.basicConfig( + level=logging.INFO, + format="%(asctime)s [%(levelname)s] %(name)s: %(message)s", +) +logger = logging.getLogger(__name__) +allowed_origins = [ + "*" +] + +app = FastAPI( + title="My FastAPI Application", + description="This is a FastAPI implementation for RAG application with Swagger UI configurations.", + version="1.0.0", + docs_url="/documentation", + redoc_url="/redoc", + openapi_url="/openapi.json", + contact={ + "name": "M K Pavan Kumar", + "linkedin": "https://www.linkedin.com", + }, + license_info={ + "name": "MIT License", + "url": "https://opensource.org/licenses/MIT", + }, + terms_of_service="https://www.yourwebsite.com/terms/", +) +app.add_middleware( + CORSMiddleware, + allow_origins=allowed_origins, + allow_credentials=True, + allow_methods=["*"], + allow_headers=["*"], +) +app.include_router(router) + + +# Custom OpenAPI schema generation (optional) +def custom_openapi(): + if app.openapi_schema: + return app.openapi_schema + openapi_schema = get_openapi( + title="RAG APIs", + version="1.0.0", + description="This is a custom OpenAPI schema with additional metadata.", + routes=app.routes, + tags=[ + { + "name": "rag", + "description": "Operations for RAG query.", + } + ], + ) + # Modify openapi_schema as needed + app.openapi_schema = openapi_schema + return app.openapi_schema + + +app.openapi = custom_openapi + + +@app.middleware("http") +async def log_requests(request: Request, call_next): + try: + logger.info(f"Incoming request: {request.method} {request.url}") + response = await call_next(request) + logger.info(f"Response status: {response.status_code}") + return response + except Exception as e: + logger.exception(f"Error processing request: {e}") + raise e + + +# Request Timing Middleware +@app.middleware("http") +async def add_process_time_header(request: Request, call_next): + start_time = time.time() + response = await call_next(request) + process_time = time.time() - start_time + response.headers["X-Process-Time"] = str(process_time) + logger.info(f"Processed in {process_time:.4f} seconds") + return response + + +# Logging Middleware +@app.middleware("http") +async def log_requests(request: Request, call_next): + logger.info(f"Incoming request: {request.method} {request.url}") + response = await call_next(request) + logger.info(f"Response status: {response.status_code}") + return response + + +if __name__ == "__main__": + uvicorn.run( + "apis:app", + host="127.0.0.1", + port=8000, + reload=True, + log_level="info", + workers=1, + ) diff --git a/bootstraprag/templates/llamaindex/rag_with_hyde/models/__init__.py b/bootstraprag/templates/llamaindex/rag_with_hyde/models/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/bootstraprag/templates/llamaindex/rag_with_hyde/models/payload.py b/bootstraprag/templates/llamaindex/rag_with_hyde/models/payload.py new file mode 100644 index 0000000..ae09aba --- /dev/null +++ b/bootstraprag/templates/llamaindex/rag_with_hyde/models/payload.py @@ -0,0 +1,5 @@ +from pydantic import BaseModel + + +class Payload(BaseModel): + query: str diff --git a/bootstraprag/templates/llamaindex/rag_with_hyde_with_observability/api_core/__init__.py b/bootstraprag/templates/llamaindex/rag_with_hyde_with_observability/api_core/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/bootstraprag/templates/llamaindex/rag_with_hyde_with_observability/api_core/config.py b/bootstraprag/templates/llamaindex/rag_with_hyde_with_observability/api_core/config.py new file mode 100644 index 0000000..d944427 --- /dev/null +++ b/bootstraprag/templates/llamaindex/rag_with_hyde_with_observability/api_core/config.py @@ -0,0 +1,5 @@ +class Settings: + PROJECT_NAME: str = "Simple RAG as FastAPI Application" + + +settings = Settings() diff --git a/bootstraprag/templates/llamaindex/rag_with_hyde_with_observability/api_routes/__init__.py b/bootstraprag/templates/llamaindex/rag_with_hyde_with_observability/api_routes/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/bootstraprag/templates/llamaindex/rag_with_hyde_with_observability/api_routes/apis.py b/bootstraprag/templates/llamaindex/rag_with_hyde_with_observability/api_routes/apis.py new file mode 100644 index 0000000..82f1533 --- /dev/null +++ b/bootstraprag/templates/llamaindex/rag_with_hyde_with_observability/api_routes/apis.py @@ -0,0 +1,14 @@ +from fastapi import APIRouter, Depends +from models.payload import Payload +from base_rag import BaseRAG + + +base_rag = BaseRAG(show_progress=True, data_path='data') + +router = APIRouter(prefix="/api/v1/rag", tags=["rag"]) + + +@router.post(path='/query') +def fetch_response(payload: Payload): + response = base_rag.query(query_string=payload.query) + return response diff --git a/bootstraprag/templates/llamaindex/rag_with_hyde_with_observability/apis.py b/bootstraprag/templates/llamaindex/rag_with_hyde_with_observability/apis.py new file mode 100644 index 0000000..3a885a5 --- /dev/null +++ b/bootstraprag/templates/llamaindex/rag_with_hyde_with_observability/apis.py @@ -0,0 +1,110 @@ +from fastapi import FastAPI, Request +from fastapi.openapi.utils import get_openapi +from api_routes.apis import router +from fastapi.middleware.cors import CORSMiddleware +import uvicorn +import logging +import time + +logging.basicConfig(level=logging.DEBUG) +logging.basicConfig( + level=logging.INFO, + format="%(asctime)s [%(levelname)s] %(name)s: %(message)s", +) +logger = logging.getLogger(__name__) +allowed_origins = [ + "*" +] + +app = FastAPI( + title="My FastAPI Application", + description="This is a FastAPI implementation for RAG application with Swagger UI configurations.", + version="1.0.0", + docs_url="/documentation", + redoc_url="/redoc", + openapi_url="/openapi.json", + contact={ + "name": "M K Pavan Kumar", + "linkedin": "https://www.linkedin.com", + }, + license_info={ + "name": "MIT License", + "url": "https://opensource.org/licenses/MIT", + }, + terms_of_service="https://www.yourwebsite.com/terms/", +) +app.add_middleware( + CORSMiddleware, + allow_origins=allowed_origins, + allow_credentials=True, + allow_methods=["*"], + allow_headers=["*"], +) +app.include_router(router) + + +# Custom OpenAPI schema generation (optional) +def custom_openapi(): + if app.openapi_schema: + return app.openapi_schema + openapi_schema = get_openapi( + title="RAG APIs", + version="1.0.0", + description="This is a custom OpenAPI schema with additional metadata.", + routes=app.routes, + tags=[ + { + "name": "rag", + "description": "Operations for RAG query.", + } + ], + ) + # Modify openapi_schema as needed + app.openapi_schema = openapi_schema + return app.openapi_schema + + +app.openapi = custom_openapi + + +@app.middleware("http") +async def log_requests(request: Request, call_next): + try: + logger.info(f"Incoming request: {request.method} {request.url}") + response = await call_next(request) + logger.info(f"Response status: {response.status_code}") + return response + except Exception as e: + logger.exception(f"Error processing request: {e}") + raise e + + +# Request Timing Middleware +@app.middleware("http") +async def add_process_time_header(request: Request, call_next): + start_time = time.time() + response = await call_next(request) + process_time = time.time() - start_time + response.headers["X-Process-Time"] = str(process_time) + logger.info(f"Processed in {process_time:.4f} seconds") + return response + + +# Logging Middleware +@app.middleware("http") +async def log_requests(request: Request, call_next): + logger.info(f"Incoming request: {request.method} {request.url}") + response = await call_next(request) + logger.info(f"Response status: {response.status_code}") + return response + + +if __name__ == "__main__": + uvicorn.run( + "apis:app", + host="127.0.0.1", + port=8000, + reload=True, + log_level="info", + workers=1, + ) diff --git a/bootstraprag/templates/llamaindex/rag_with_hyde_with_observability/models/__init__.py b/bootstraprag/templates/llamaindex/rag_with_hyde_with_observability/models/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/bootstraprag/templates/llamaindex/rag_with_hyde_with_observability/models/payload.py b/bootstraprag/templates/llamaindex/rag_with_hyde_with_observability/models/payload.py new file mode 100644 index 0000000..ae09aba --- /dev/null +++ b/bootstraprag/templates/llamaindex/rag_with_hyde_with_observability/models/payload.py @@ -0,0 +1,5 @@ +from pydantic import BaseModel + + +class Payload(BaseModel): + query: str diff --git a/bootstraprag/templates/llamaindex/rag_with_react/api_core/__init__.py b/bootstraprag/templates/llamaindex/rag_with_react/api_core/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/bootstraprag/templates/llamaindex/rag_with_react/api_core/config.py b/bootstraprag/templates/llamaindex/rag_with_react/api_core/config.py new file mode 100644 index 0000000..d944427 --- /dev/null +++ b/bootstraprag/templates/llamaindex/rag_with_react/api_core/config.py @@ -0,0 +1,5 @@ +class Settings: + PROJECT_NAME: str = "Simple RAG as FastAPI Application" + + +settings = Settings() diff --git a/bootstraprag/templates/llamaindex/rag_with_react/api_routes/__init__.py b/bootstraprag/templates/llamaindex/rag_with_react/api_routes/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/bootstraprag/templates/llamaindex/rag_with_react/api_routes/apis.py b/bootstraprag/templates/llamaindex/rag_with_react/api_routes/apis.py new file mode 100644 index 0000000..ac487dc --- /dev/null +++ b/bootstraprag/templates/llamaindex/rag_with_react/api_routes/apis.py @@ -0,0 +1,14 @@ +from fastapi import APIRouter, Depends +from models.payload import Payload +from react_agent_with_query_engine import ReActWithQueryEngine + + +react_with_engine = ReActWithQueryEngine(input_dir='data', show_progress=True) + +router = APIRouter(prefix="/api/v1/rag", tags=["rag"]) + + +@router.post(path='/query') +def fetch_response(payload: Payload): + response = react_with_engine.query(user_query=payload.query) + return response diff --git a/bootstraprag/templates/llamaindex/rag_with_react/apis.py b/bootstraprag/templates/llamaindex/rag_with_react/apis.py new file mode 100644 index 0000000..3a885a5 --- /dev/null +++ b/bootstraprag/templates/llamaindex/rag_with_react/apis.py @@ -0,0 +1,110 @@ +from fastapi import FastAPI, Request +from fastapi.openapi.utils import get_openapi +from api_routes.apis import router +from fastapi.middleware.cors import CORSMiddleware +import uvicorn +import logging +import time + +logging.basicConfig(level=logging.DEBUG) +logging.basicConfig( + level=logging.INFO, + format="%(asctime)s [%(levelname)s] %(name)s: %(message)s", +) +logger = logging.getLogger(__name__) +allowed_origins = [ + "*" +] + +app = FastAPI( + title="My FastAPI Application", + description="This is a FastAPI implementation for RAG application with Swagger UI configurations.", + version="1.0.0", + docs_url="/documentation", + redoc_url="/redoc", + openapi_url="/openapi.json", + contact={ + "name": "M K Pavan Kumar", + "linkedin": "https://www.linkedin.com", + }, + license_info={ + "name": "MIT License", + "url": "https://opensource.org/licenses/MIT", + }, + terms_of_service="https://www.yourwebsite.com/terms/", +) +app.add_middleware( + CORSMiddleware, + allow_origins=allowed_origins, + allow_credentials=True, + allow_methods=["*"], + allow_headers=["*"], +) +app.include_router(router) + + +# Custom OpenAPI schema generation (optional) +def custom_openapi(): + if app.openapi_schema: + return app.openapi_schema + openapi_schema = get_openapi( + title="RAG APIs", + version="1.0.0", + description="This is a custom OpenAPI schema with additional metadata.", + routes=app.routes, + tags=[ + { + "name": "rag", + "description": "Operations for RAG query.", + } + ], + ) + # Modify openapi_schema as needed + app.openapi_schema = openapi_schema + return app.openapi_schema + + +app.openapi = custom_openapi + + +@app.middleware("http") +async def log_requests(request: Request, call_next): + try: + logger.info(f"Incoming request: {request.method} {request.url}") + response = await call_next(request) + logger.info(f"Response status: {response.status_code}") + return response + except Exception as e: + logger.exception(f"Error processing request: {e}") + raise e + + +# Request Timing Middleware +@app.middleware("http") +async def add_process_time_header(request: Request, call_next): + start_time = time.time() + response = await call_next(request) + process_time = time.time() - start_time + response.headers["X-Process-Time"] = str(process_time) + logger.info(f"Processed in {process_time:.4f} seconds") + return response + + +# Logging Middleware +@app.middleware("http") +async def log_requests(request: Request, call_next): + logger.info(f"Incoming request: {request.method} {request.url}") + response = await call_next(request) + logger.info(f"Response status: {response.status_code}") + return response + + +if __name__ == "__main__": + uvicorn.run( + "apis:app", + host="127.0.0.1", + port=8000, + reload=True, + log_level="info", + workers=1, + ) diff --git a/bootstraprag/templates/llamaindex/rag_with_react/models/__init__.py b/bootstraprag/templates/llamaindex/rag_with_react/models/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/bootstraprag/templates/llamaindex/rag_with_react/models/payload.py b/bootstraprag/templates/llamaindex/rag_with_react/models/payload.py new file mode 100644 index 0000000..ae09aba --- /dev/null +++ b/bootstraprag/templates/llamaindex/rag_with_react/models/payload.py @@ -0,0 +1,5 @@ +from pydantic import BaseModel + + +class Payload(BaseModel): + query: str diff --git a/bootstraprag/templates/llamaindex/rag_with_react_with_observability/api_core/__init__.py b/bootstraprag/templates/llamaindex/rag_with_react_with_observability/api_core/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/bootstraprag/templates/llamaindex/rag_with_react_with_observability/api_core/config.py b/bootstraprag/templates/llamaindex/rag_with_react_with_observability/api_core/config.py new file mode 100644 index 0000000..d944427 --- /dev/null +++ b/bootstraprag/templates/llamaindex/rag_with_react_with_observability/api_core/config.py @@ -0,0 +1,5 @@ +class Settings: + PROJECT_NAME: str = "Simple RAG as FastAPI Application" + + +settings = Settings() diff --git a/bootstraprag/templates/llamaindex/rag_with_react_with_observability/api_routes/__init__.py b/bootstraprag/templates/llamaindex/rag_with_react_with_observability/api_routes/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/bootstraprag/templates/llamaindex/rag_with_react_with_observability/api_routes/apis.py b/bootstraprag/templates/llamaindex/rag_with_react_with_observability/api_routes/apis.py new file mode 100644 index 0000000..ac487dc --- /dev/null +++ b/bootstraprag/templates/llamaindex/rag_with_react_with_observability/api_routes/apis.py @@ -0,0 +1,14 @@ +from fastapi import APIRouter, Depends +from models.payload import Payload +from react_agent_with_query_engine import ReActWithQueryEngine + + +react_with_engine = ReActWithQueryEngine(input_dir='data', show_progress=True) + +router = APIRouter(prefix="/api/v1/rag", tags=["rag"]) + + +@router.post(path='/query') +def fetch_response(payload: Payload): + response = react_with_engine.query(user_query=payload.query) + return response diff --git a/bootstraprag/templates/llamaindex/rag_with_react_with_observability/apis.py b/bootstraprag/templates/llamaindex/rag_with_react_with_observability/apis.py new file mode 100644 index 0000000..3a885a5 --- /dev/null +++ b/bootstraprag/templates/llamaindex/rag_with_react_with_observability/apis.py @@ -0,0 +1,110 @@ +from fastapi import FastAPI, Request +from fastapi.openapi.utils import get_openapi +from api_routes.apis import router +from fastapi.middleware.cors import CORSMiddleware +import uvicorn +import logging +import time + +logging.basicConfig(level=logging.DEBUG) +logging.basicConfig( + level=logging.INFO, + format="%(asctime)s [%(levelname)s] %(name)s: %(message)s", +) +logger = logging.getLogger(__name__) +allowed_origins = [ + "*" +] + +app = FastAPI( + title="My FastAPI Application", + description="This is a FastAPI implementation for RAG application with Swagger UI configurations.", + version="1.0.0", + docs_url="/documentation", + redoc_url="/redoc", + openapi_url="/openapi.json", + contact={ + "name": "M K Pavan Kumar", + "linkedin": "https://www.linkedin.com", + }, + license_info={ + "name": "MIT License", + "url": "https://opensource.org/licenses/MIT", + }, + terms_of_service="https://www.yourwebsite.com/terms/", +) +app.add_middleware( + CORSMiddleware, + allow_origins=allowed_origins, + allow_credentials=True, + allow_methods=["*"], + allow_headers=["*"], +) +app.include_router(router) + + +# Custom OpenAPI schema generation (optional) +def custom_openapi(): + if app.openapi_schema: + return app.openapi_schema + openapi_schema = get_openapi( + title="RAG APIs", + version="1.0.0", + description="This is a custom OpenAPI schema with additional metadata.", + routes=app.routes, + tags=[ + { + "name": "rag", + "description": "Operations for RAG query.", + } + ], + ) + # Modify openapi_schema as needed + app.openapi_schema = openapi_schema + return app.openapi_schema + + +app.openapi = custom_openapi + + +@app.middleware("http") +async def log_requests(request: Request, call_next): + try: + logger.info(f"Incoming request: {request.method} {request.url}") + response = await call_next(request) + logger.info(f"Response status: {response.status_code}") + return response + except Exception as e: + logger.exception(f"Error processing request: {e}") + raise e + + +# Request Timing Middleware +@app.middleware("http") +async def add_process_time_header(request: Request, call_next): + start_time = time.time() + response = await call_next(request) + process_time = time.time() - start_time + response.headers["X-Process-Time"] = str(process_time) + logger.info(f"Processed in {process_time:.4f} seconds") + return response + + +# Logging Middleware +@app.middleware("http") +async def log_requests(request: Request, call_next): + logger.info(f"Incoming request: {request.method} {request.url}") + response = await call_next(request) + logger.info(f"Response status: {response.status_code}") + return response + + +if __name__ == "__main__": + uvicorn.run( + "apis:app", + host="127.0.0.1", + port=8000, + reload=True, + log_level="info", + workers=1, + ) diff --git a/bootstraprag/templates/llamaindex/rag_with_react_with_observability/models/__init__.py b/bootstraprag/templates/llamaindex/rag_with_react_with_observability/models/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/bootstraprag/templates/llamaindex/rag_with_react_with_observability/models/payload.py b/bootstraprag/templates/llamaindex/rag_with_react_with_observability/models/payload.py new file mode 100644 index 0000000..ae09aba --- /dev/null +++ b/bootstraprag/templates/llamaindex/rag_with_react_with_observability/models/payload.py @@ -0,0 +1,5 @@ +from pydantic import BaseModel + + +class Payload(BaseModel): + query: str From 6b9c0fb817b8d054b8c3b4d0bd1a50c6e957d4c0 Mon Sep 17 00:00:00 2001 From: pavanmantha Date: Wed, 25 Sep 2024 10:36:43 +0530 Subject: [PATCH 4/5] -removed the auto deploy config --- .github/workflows/python-app.yml | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/.github/workflows/python-app.yml b/.github/workflows/python-app.yml index d6f2e3e..fb1049d 100644 --- a/.github/workflows/python-app.yml +++ b/.github/workflows/python-app.yml @@ -4,10 +4,12 @@ name: Python application on: - push: - branches: - - main -# uncomment the below code to enable actions on PR branch also. + workflow_dispatch: +# uncomment the below code to enable actions automatically on main for deployment. +# push: +# branches: +# - main +# uncomment the below code to enable actions on PR automatically on branch. # pull_request: # branches: # - main From 5d56ae8ff853aa61fc911f7945066b02df34a092 Mon Sep 17 00:00:00 2001 From: pavanmantha Date: Wed, 25 Sep 2024 10:41:13 +0530 Subject: [PATCH 5/5] -seperated the tasks for build and deploy --- .../{python-app.yml => application-build.yml} | 20 ---------- .github/workflows/application-deploy.yml | 40 +++++++++++++++++++ 2 files changed, 40 insertions(+), 20 deletions(-) rename .github/workflows/{python-app.yml => application-build.yml} (71%) create mode 100644 .github/workflows/application-deploy.yml diff --git a/.github/workflows/python-app.yml b/.github/workflows/application-build.yml similarity index 71% rename from .github/workflows/python-app.yml rename to .github/workflows/application-build.yml index fb1049d..9375fbb 100644 --- a/.github/workflows/python-app.yml +++ b/.github/workflows/application-build.yml @@ -42,23 +42,3 @@ jobs: - name: Test with pytest run: | pytest - - deploy: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - name: Set up Python - uses: actions/setup-python@v2 - with: - python-version: '3.10' - - name: Install dependencies - run: | - python -m pip install --upgrade pip - pip install setuptools wheel twine - - name: Build and publish - env: - TWINE_USERNAME: __token__ - TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }} - run: | - python setup.py sdist bdist_wheel - twine upload dist/* \ No newline at end of file diff --git a/.github/workflows/application-deploy.yml b/.github/workflows/application-deploy.yml new file mode 100644 index 0000000..3453fc7 --- /dev/null +++ b/.github/workflows/application-deploy.yml @@ -0,0 +1,40 @@ +# This workflow will install Python dependencies, run tests and lint with a single version of Python +# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python + +name: Python application + +on: + workflow_dispatch: +# uncomment the below code to enable actions automatically on main for deployment. +# push: +# branches: +# - main +# uncomment the below code to enable actions on PR automatically on branch. +# pull_request: +# branches: +# - main + +permissions: + contents: read + +jobs: + + deploy: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Set up Python + uses: actions/setup-python@v2 + with: + python-version: '3.10' + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install setuptools wheel twine + - name: Build and publish + env: + TWINE_USERNAME: __token__ + TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }} + run: | + python setup.py sdist bdist_wheel + twine upload dist/* \ No newline at end of file