diff --git a/README.md b/README.md index 42862e3..b717bec 100644 --- a/README.md +++ b/README.md @@ -55,3 +55,34 @@ __Contributors:__ - Vincent Harkins (@vharkins1) - Marc Vergés (@marcvergees) - Jan Sans + + +## Local Development Setup (Beginner Friendly) + +1. Clone your fork and enter project folder: + + - git clone + cd FireForm (Terminal) + +2. Create virtual environment: + + - python3 -m venv venv + source venv/bin/activate + +3. Install dependencies: + +4. Initialize database tables: + +5. Run backend server: + +6. Open Swagger UI in browser: (http://127.0.0.1:8000/docs) + +### Common Errors + +- `sqlite3.OperationalError: no such table` +→ Run database initialization step. + +- `Could not connect to Ollama` +→ Ensure Ollama server is running locally. + + diff --git a/api/routes/forms.py b/api/routes/forms.py index f3430ed..0dd0fb7 100644 --- a/api/routes/forms.py +++ b/api/routes/forms.py @@ -19,6 +19,9 @@ def fill_form(form: FormFill, db: Session = Depends(get_db)): controller = Controller() path = controller.fill_form(user_input=form.input_text, fields=fetched_template.fields, pdf_form_path=fetched_template.pdf_path) + if not path: + raise AppError("PDF generation failed", status_code=400) + submission = FormSubmission(**form.model_dump(), output_pdf_path=path) return create_form(db, submission) diff --git a/src/file_manipulator.py b/src/file_manipulator.py index b7815cc..2350df9 100644 --- a/src/file_manipulator.py +++ b/src/file_manipulator.py @@ -1,8 +1,11 @@ import os +import logging from src.filler import Filler from src.llm import LLM from commonforms import prepare_form +logging.basicConfig(level=logging.INFO) +logger = logging.getLogger(__name__) class FileManipulator: def __init__(self): @@ -22,14 +25,14 @@ def fill_form(self, user_input: str, fields: list, pdf_form_path: str): It receives the raw data, runs the PDF filling logic, and returns the path to the newly created file. """ - print("[1] Received request from frontend.") + logger.info("[1] Received request from frontend.") print(f"[2] PDF template path: {pdf_form_path}") if not os.path.exists(pdf_form_path): print(f"Error: PDF template not found at {pdf_form_path}") return None # Or raise an exception - print("[3] Starting extraction and PDF filling process...") + logger.info("[3] Starting extraction...") try: self.llm._target_fields = fields self.llm._transcript_text = user_input diff --git a/src/llm.py b/src/llm.py index 70937f9..2c6e530 100644 --- a/src/llm.py +++ b/src/llm.py @@ -60,12 +60,11 @@ def main_loop(self): } try: - response = requests.post(ollama_url, json=payload) + response = requests.post(ollama_url, json=payload, timeout=30) response.raise_for_status() - except requests.exceptions.ConnectionError: - raise ConnectionError( - f"Could not connect to Ollama at {ollama_url}. " - "Please ensure Ollama is running and accessible." + except requests.exceptions.Timeout: + raise TimeoutError( + f"Ollama request timed out after 30 seconds at {ollama_url}" ) except requests.exceptions.HTTPError as e: raise RuntimeError(f"Ollama returned an error: {e}")