{"id":29666492,"url":"https://github.com/mk-hasan/fastapi-llm-postgres-server","last_synced_at":"2026-04-11T02:48:52.412Z","repository":{"id":305053341,"uuid":"1021760722","full_name":"mk-hasan/FastAPI-LLM-Postgres-Server","owner":"mk-hasan","description":"A Fast API powered server project to use different LLM services with Postgres and Caching!","archived":false,"fork":false,"pushed_at":"2025-07-17T23:36:25.000Z","size":356,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-07-18T04:21:06.053Z","etag":null,"topics":["fastapi","fastapi-template","gemini","llm","openai","postgresql"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mk-hasan.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-07-17T22:59:18.000Z","updated_at":"2025-07-17T23:37:26.000Z","dependencies_parsed_at":"2025-07-18T05:17:53.985Z","dependency_job_id":"c08c97bd-5b00-489c-81f7-c8b1f5e8feaa","html_url":"https://github.com/mk-hasan/FastAPI-LLM-Postgres-Server","commit_stats":null,"previous_names":["mk-hasan/fastapi-llm-postgres-server"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/mk-hasan/FastAPI-LLM-Postgres-Server","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mk-hasan%2FFastAPI-LLM-Postgres-Server","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mk-hasan%2FFastAPI-LLM-Postgres-Server/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mk-hasan%2FFastAPI-LLM-Postgres-Server/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mk-hasan%2FFastAPI-LLM-Postgres-Server/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mk-hasan","download_url":"https://codeload.github.com/mk-hasan/FastAPI-LLM-Postgres-Server/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mk-hasan%2FFastAPI-LLM-Postgres-Server/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":266516523,"owners_count":23941450,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-07-22T02:00:09.085Z","response_time":66,"last_error":null,"robots_txt_status":null,"robots_txt_updated_at":null,"robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["fastapi","fastapi-template","gemini","llm","openai","postgresql"],"created_at":"2025-07-22T15:09:59.938Z","updated_at":"2026-04-11T02:48:52.372Z","avatar_url":"https://github.com/mk-hasan.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n# 🚀 FastAPI-LLM-Postgres Backend\n\n![Screenshot](public/ss.png)\n\n## 📁 Project Structure\n\nThe project follows a layered architecture to ensure clear separation of concerns, scalability, and maintainability.\n\n```plaintext\n.\n├── .env                  \n├── .gitignore            \n├── Dockerfile            \n├── pyproject.toml        \n├── poetry.lock           \n├── README.md             \n├── alembic.ini           \n├── migrations/           \n│   ├── env.py            \n│   ├── script.py.mako    \n│   └── versions/         \n│       └── \u003ctimestamp\u003e_initial_ai_schema_and_tables.py\n├── prompts/              \n│   ├── generic_text_generation.jinja2\n│   └── job_parser.jinja2\n└── app/                  \n    ├── main.py           \n    ├── api/              \n    │   └── v1/           \n    │       ├── endpoints/\n    │       │   ├── llm.py     \n    │       │   └── data.py    \n    │       └── dependencies.py\n    ├── core/             \n    │   ├── config.py     \n    │   └── exceptions.py \n    ├── db/               \n    │   ├── database.py   \n    │   └── models.py     \n    ├── llm_providers/    \n    │   ├── base.py       \n    │   ├── openai_provider.py \n    │   ├── gemini_provider.py \n    │   └── (other_providers.py)\n    ├── models/           \n    │   ├── llm_models.py \n    │   └── db_models.py  \n    ├── services/         \n    │   ├── llm_service.py \n    │   └── data_service.py \n    └── utils/            \n        ├── logger.py     \n        ├── prompt_manager.py \n        └── web_scraper.py \n```\n\n## 🛠️ Setup Guide\n\n### 1. Prerequisites\n\nEnsure you have the following installed on your system:\n\n- **Python 3.11+**\n- **PostgreSQL**\n- **Git**\n\n### 2. Install Poetry\n\n#### macOS / Linux / WSL\n\n```bash\npipx install poetry\n```\n\n#### Windows (PowerShell)\n\n```powershell\n(Invoke-WebRequest -Uri https://install.python-poetry.org -UseBasicParsing).Content | python -\n```\n\nVerify installation:\n\n```bash\npoetry --version\n```\n\n### 3. Clone the Repository\n\n```bash\ngit clone https://github.com/mk-hasan/FastAPI-LLM-Postgres-Server.git\ncd FastAPI-LLM-Postgres-Server.ai\n```\n\n### 4. Install Dependencies\n\n```bash\npoetry install\npoetry shell\n```\n\n### 5. Configure Environment Variables\n\nCreate a `.env` file in the root directory:\n\n```env\nOPENAI_API_KEY=\"sk-your-openai-api-key-here\"\nCOHERE_API_KEY=\"your-cohere-api-key-here\"\nHUGGINGFACE_API_KEY=\"hf_your_huggingface_api_key\"\nGOOGLE_API_KEY=\"AIzaSy_your-gemini-api-key-here\"\nDEFAULT_LLM_PROVIDER=\"gemini\"\nPOSTGRES_USER=\"local_user\"\nPOSTGRES_PASSWORD=\"local_password\"\nPOSTGRES_SERVER=\"localhost\"\nPOSTGRES_PORT=\"5432\"\nPOSTGRES_DB=\"ai_db\"\n```\n\n### 6. Database Setup \u0026 Migrations\n\nCreate database and user:\n\nYou can quickly start a PostgreSQL database using Docker Compose:\n\n```bash\ndocker-compose up -d postgres\n```\n\nThis will start the PostgreSQL service defined in your `docker-compose.yaml`. Make sure your environment variables in `.env` match the credentials above.\n\n---\nAlternatively you can install postgres and execute this command\n```sql\nCREATE DATABASE ai_db;\nCREATE USER local_user WITH PASSWORD 'local_password';\nGRANT ALL PRIVILEGES ON DATABASE craidb TO local_user;\n```\n\n---\n\n\n\nClean Alembic State:\n\n```bash\nrm -rf migrations/versions/*\n```\n\nIn PostgreSQL:\n\n```sql\nDROP TABLE IF EXISTS alembic_version;\nDROP SCHEMA IF EXISTS db_ai CASCADE;\n```\n\nReinitialize Alembic:\n\n```bash\nalembic init migrations\n```\n\nEdit `alembic.ini`:\n\n```\nsqlalchemy.url = postgresql+psycopg2://local_user:local_password@localhost:5432/craidb\n```\n\nEdit `migrations/env.py`:\n\n```python\nfrom app.db.database import Base\ntarget_metadata = Base.metadata\n```\n\nGenerate and apply migration:\n\n```bash\nalembic revision --autogenerate -m \"Initial AI schema and tables\"\nalembic upgrade head\n```\n\n## 🚀 Running the Application\n\n```bash\npoetry shell\nuvicorn app.main:app --host 0.0.0.0 --port 8000 --reload\n```\n\nVisit [http://0.0.0.0:8000/docs](http://0.0.0.0:8000/docs) to explore the interactive OpenAPI docs.\n\n## 🧪 API Endpoints \u0026 Testing\n\n### 1. LLM Generation \u0026 Parsing\n\n**POST /api/v1/llm/generate**\n\n```json\n{\n  \"request\": {\n    \"prompt\": \"Explain quantum entanglement in two sentences.\",\n    \"llm_provider\": \"gemini\",\n    \"max_tokens\": 100,\n    \"temperature\": 0.5\n  },\n  \"use_cache\": true,\n  \"cache_ttl_minutes\": 60\n}\n```\n\n**POST /api/v1/llm/parse-job**\n\n```json\n{\n  \"job_url\": \"https://careers.google.com/jobs/results/1234567890/software-engineer-mountain-view-ca/\",\n  \"llm_provider\": \"gemini\"\n}\n```\n\n### 2. Data Management\n\n**POST /api/v1/data/users**\n\n```json\n{\n  \"name\": \"Jane Doe\",\n  \"email\": \"jane.doe@example.com\",\n  \"is_active\": true\n}\n```\n\n**GET /api/v1/data/users/{user_id}**\n\nExample: `http://0.0.0.0:8000/api/v1/data/users/1`\n\n**GET /api/v1/data/users?skip=0\u0026limit=10**\n\n## 🤝 Contributing\n\nCreate A PR with your changes!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmk-hasan%2Ffastapi-llm-postgres-server","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmk-hasan%2Ffastapi-llm-postgres-server","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmk-hasan%2Ffastapi-llm-postgres-server/lists"}