Skip to content

Commit

Permalink
🔧 feat: custom HOST PORT (#15)
Browse files Browse the repository at this point in the history
* feat: custom HOST PORT

* Update main.py

* Update README.md

* refactor: move env var init to config.py

* chore: adjust README.md

* chore: add additional instructions based on debugging

* chore: bump langchain_core==0.1.35 due to CVE-2024-1455

---------

Co-authored-by: Berry-13 <81851188+Berry-13@users.noreply.github.com>
  • Loading branch information
danny-avila and berry-13 authored Mar 29, 2024
1 parent 6906742 commit fb1a629
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 9 deletions.
12 changes: 8 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,26 +22,30 @@ The API will evolve over time to employ different querying/re-ranking methods, e
- **Setup pgvector database:**
- Run an existing PSQL/PGVector setup, or,
- Docker: `docker compose up` (also starts RAG API)
- or, use docker just for DB: `docker compose -f ./db-compose.yaml`
- or, use docker just for DB: `docker compose -f ./db-compose.yaml up`
- **Run API**:
- Docker: `docker compose up` (also starts PSQL/pgvector)
- or, use docker just for RAG API: `docker compose -f ./api-compose.yaml`
- or, use docker just for RAG API: `docker compose -f ./api-compose.yaml up`
- Local:
- Make sure to setup `DB_HOST` to the correct database hostname
- Run the following commands (preferably in a [virtual environment](https://realpython.com/python-virtual-environments-a-primer/))
```bash
pip install -r requirements.txt
uvicorn main:app --host 0.0.0.0 --port 8000
uvicorn main:app
```

### Environment Variables

The following environment variables are required to run the application:

- `OPENAI_API_KEY`: The API key for OpenAI API Embeddings.
- `OPENAI_API_KEY`: The API key for OpenAI API Embeddings (if using default settings).
- `POSTGRES_DB`: (Optional) The name of the PostgreSQL database.
- `POSTGRES_USER`: (Optional) The username for connecting to the PostgreSQL database.
- `POSTGRES_PASSWORD`: (Optional) The password for connecting to the PostgreSQL database.
- `DB_HOST`: (Optional) The hostname or IP address of the PostgreSQL database server.
- `DB_PORT`: (Optional) The port number of the PostgreSQL database server.
- `RAG_HOST`: (Optional) The hostname or IP address where the API server will run. Defaults to "0.0.0.0"
- `RAG_PORT`: (Optional) The port number where the API server will run. Defaults to port 8000.
- `JWT_SECRET`: (Optional) The secret key used for verifying JWT tokens for requests.
- The secret is only used for verification. This basic approach assumes a signed JWT from elsewhere.
- Omit to run API without requiring authentication
Expand Down
2 changes: 2 additions & 0 deletions config.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ def get_env_variable(var_name: str, default_value: str = None) -> str:
return default_value
return value

RAG_HOST = os.getenv('HOST', '0.0.0.0')
RAG_PORT = int(os.getenv('PORT', 8000))

RAG_UPLOAD_DIR = get_env_variable("RAG_UPLOAD_DIR", "./uploads/")
if not os.path.exists(RAG_UPLOAD_DIR):
Expand Down
7 changes: 4 additions & 3 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@

load_dotenv(find_dotenv())


from config import (
logger,
debug_mode,
Expand All @@ -47,6 +46,8 @@
RAG_UPLOAD_DIR,
known_source_ext,
PDF_EXTRACT_IMAGES, LogMiddleware,
RAG_HOST,
RAG_PORT,
# RAG_EMBEDDING_MODEL,
# RAG_EMBEDDING_MODEL_DEVICE_TYPE,
# RAG_TEMPLATE,
Expand All @@ -59,7 +60,7 @@ async def lifespan(app: FastAPI):
await PSQLDatabase.get_pool() # Initialize the pool
await ensure_custom_id_index_on_embedding()

yield # The application is now up and serving requests
yield

app = FastAPI(lifespan=lifespan)

Expand Down Expand Up @@ -451,4 +452,4 @@ async def query_embeddings_by_file_ids(body: QueryMultipleBody):
app.include_router(router=pgvector_router)

if __name__ == "__main__":
uvicorn.run(app, host="0.0.0.0", port=8000, log_config=None)
uvicorn.run(app, host=RAG_HOST, port=RAG_PORT, log_config=None)
2 changes: 1 addition & 1 deletion requirements.lite.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
langchain==0.1.12
langchain_community==0.0.28
langchain_openai==0.0.8
langchain_core==0.1.32
langchain_core==0.1.35
sqlalchemy==2.0.28
python-dotenv==1.0.1
fastapi==0.110.0
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
langchain==0.1.12
langchain_community==0.0.28
langchain_openai==0.0.8
langchain_core==0.1.32
langchain_core==0.1.35
sqlalchemy==2.0.28
python-dotenv==1.0.1
fastapi==0.110.0
Expand Down

0 comments on commit fb1a629

Please sign in to comment.