From 0a1b22da008b5ec6834453709499143cca2b1a09 Mon Sep 17 00:00:00 2001 From: Automated Action Date: Fri, 27 Jun 2025 15:01:50 +0000 Subject: [PATCH] Fix dependency conflicts and improve path handling MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Update OpenAI version to >=1.6.1 to resolve LangChain conflict - Remove LangChain dependencies (not needed for this implementation) - Fix OpenAI imports to use newer v1+ API format - Make database and storage paths flexible for different environments - Update Alembic configuration to use dynamic database paths - Ensure compatibility across different deployment environments 🤖 Generated with BackendIM Co-Authored-By: Claude --- alembic.ini | 2 +- alembic/env.py | 11 +++++++++++ app/db/session.py | 5 ++++- app/services/ai_service.py | 6 ++---- app/services/file_service.py | 4 +++- requirements.txt | 4 +--- 6 files changed, 22 insertions(+), 10 deletions(-) diff --git a/alembic.ini b/alembic.ini index bf58358..8f39a41 100644 --- a/alembic.ini +++ b/alembic.ini @@ -53,7 +53,7 @@ version_path_separator = os # are written from script.py.mako # output_encoding = utf-8 -sqlalchemy.url = sqlite:////app/storage/db/db.sqlite +sqlalchemy.url = sqlite:///storage/db/db.sqlite [post_write_hooks] # post_write_hooks defines scripts or Python functions that are run diff --git a/alembic/env.py b/alembic/env.py index 76ae233..e4a62a6 100644 --- a/alembic/env.py +++ b/alembic/env.py @@ -4,16 +4,27 @@ from sqlalchemy import pool from alembic import context import os import sys +from pathlib import Path # Add the project root to the Python path sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) # Import your models here from app.db.base import Base +from app.models import user, resume, job, match, analytics # this is the Alembic Config object config = context.config +# Use the same database path logic as the main app +base_path = Path("/app") if Path("/app").exists() else Path.cwd() +db_dir = base_path / "storage" / "db" +db_dir.mkdir(parents=True, exist_ok=True) +database_url = f"sqlite:///{db_dir}/db.sqlite" + +# Set the database URL for alembic +config.set_main_option("sqlalchemy.url", database_url) + # Interpret the config file for Python logging. if config.config_file_name is not None: fileConfig(config.config_file_name) diff --git a/app/db/session.py b/app/db/session.py index e77d375..27d2473 100644 --- a/app/db/session.py +++ b/app/db/session.py @@ -1,8 +1,11 @@ +import os from pathlib import Path from sqlalchemy import create_engine from sqlalchemy.orm import sessionmaker -DB_DIR = Path("/app") / "storage" / "db" +# Use current working directory if /app doesn't exist +base_path = Path("/app") if Path("/app").exists() else Path.cwd() +DB_DIR = base_path / "storage" / "db" DB_DIR.mkdir(parents=True, exist_ok=True) SQLALCHEMY_DATABASE_URL = f"sqlite:///{DB_DIR}/db.sqlite" diff --git a/app/services/ai_service.py b/app/services/ai_service.py index 9d09159..9bcb74f 100644 --- a/app/services/ai_service.py +++ b/app/services/ai_service.py @@ -1,14 +1,12 @@ -import openai +from openai import OpenAI from typing import Dict, List, Any from app.core.config import settings import json -openai.api_key = settings.OPENAI_API_KEY - class AIService: def __init__(self): - self.client = openai.OpenAI(api_key=settings.OPENAI_API_KEY) + self.client = OpenAI(api_key=settings.OPENAI_API_KEY) async def analyze_resume(self, resume_text: str) -> Dict[str, Any]: """Extract structured data from resume text using AI""" diff --git a/app/services/file_service.py b/app/services/file_service.py index f5a6737..3603feb 100644 --- a/app/services/file_service.py +++ b/app/services/file_service.py @@ -7,7 +7,9 @@ from app.core.config import settings class FileService: def __init__(self): - self.upload_dir = Path("/app/storage/uploads") + # Use current working directory if /app doesn't exist + base_path = Path("/app") if Path("/app").exists() else Path.cwd() + self.upload_dir = base_path / "storage" / "uploads" self.upload_dir.mkdir(parents=True, exist_ok=True) def validate_file(self, file: UploadFile) -> bool: diff --git a/requirements.txt b/requirements.txt index a962654..3bb5839 100644 --- a/requirements.txt +++ b/requirements.txt @@ -8,9 +8,7 @@ python-multipart==0.0.6 python-jose[cryptography]==3.3.0 passlib[bcrypt]==1.7.4 httpx==0.25.2 -openai==1.3.5 -langchain==0.0.350 -langchain-openai==0.0.2 +openai>=1.6.1 PyPDF2==3.0.1 python-docx==1.1.0 ruff==0.1.6