From 3f141da50913d166667ed0c1ca43d0885916163f Mon Sep 17 00:00:00 2001 From: Aherobo Ovie Victor Date: Thu, 17 Jul 2025 23:06:27 +0100 Subject: [PATCH] adding run.py --- .env.example | 20 ------------ run.py | 87 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 87 insertions(+), 20 deletions(-) delete mode 100644 .env.example create mode 100644 run.py diff --git a/.env.example b/.env.example deleted file mode 100644 index 0d1de68..0000000 --- a/.env.example +++ /dev/null @@ -1,20 +0,0 @@ -# Required API Keys -GROQ_API_KEY=your_groq_api_key -COHERE_API_KEY=your_cohere_api_key - -# Vector Database (Choose one) -# For Pinecone: -VECTOR_DB=pinecone -PINECONE_API_KEY=your_pinecone_api_key -PINECONE_ENVIRONMENT=your_pinecone_environment #us-east-1 -PINECONE_INDEX_NAME=specscomply_documents - -# Or for Weaviate: -# VECTOR_DB=weaviate -# WEAVIATE_URL=your_weaviate_url -# WEAVIATE_API_KEY=your_weaviate_api_key - -# Optional Settings -APP_NAME="Mini SpecsComply Pro" -APP_VERSION="0.1.0" -DEBUG=False \ No newline at end of file diff --git a/run.py b/run.py new file mode 100644 index 0000000..b0ad5b2 --- /dev/null +++ b/run.py @@ -0,0 +1,87 @@ +#!/usr/bin/env python3 +""" +Run script for Mini SpecsComply Pro. +This script initializes and runs the application. +""" + +import os +import uvicorn +import argparse +from dotenv import load_dotenv +from loguru import logger +import sys + +# Load environment variables from .env file +load_dotenv() + +def check_api_keys(): + """Check if required API keys are set.""" + missing_keys = [] + + # Check required API keys + if not os.getenv("COHERE_API_KEY"): + missing_keys.append("COHERE_API_KEY") + + if not os.getenv("GROQ_API_KEY"): + missing_keys.append("GROQ_API_KEY") + + # Check vector database keys + vector_db = os.getenv("VECTOR_DB", "pinecone").lower() + + if vector_db == "pinecone": + if not os.getenv("PINECONE_API_KEY"): + missing_keys.append("PINECONE_API_KEY") + if not os.getenv("PINECONE_ENVIRONMENT"): + missing_keys.append("PINECONE_ENVIRONMENT") + + if vector_db == "weaviate": + if not os.getenv("WEAVIATE_URL"): + missing_keys.append("WEAVIATE_URL") + + return missing_keys + +def main(): + """Run the application.""" + # Parse command-line arguments + parser = argparse.ArgumentParser(description="Run Mini SpecsComply Pro API") + parser.add_argument("--host", default="0.0.0.0", help="Host to bind") + parser.add_argument("--port", type=int, default=8000, help="Port to bind") + parser.add_argument("--reload", action="store_true", help="Enable auto-reload") + parser.add_argument("--debug", action="store_true", help="Enable debug mode") + args = parser.parse_args() + + # Configure logging + log_level = "DEBUG" if args.debug else "INFO" + logger.remove() + logger.add( + sys.stdout, + format="{time:YYYY-MM-DD HH:mm:ss} | {level} | {message}", + level=log_level, + ) + + # Check API keys + missing_keys = check_api_keys() + if missing_keys: + logger.warning(f"Missing API keys: {', '.join(missing_keys)}") + logger.warning("Some functionality may not work properly.") + logger.warning("Please check your .env file and ensure all required API keys are set.") + + # If critical keys are missing, exit + critical_keys = ["COHERE_API_KEY", "GROQ_API_KEY"] + if any(key in critical_keys for key in missing_keys): + logger.error("Critical API keys are missing. Application cannot start.") + sys.exit(1) + + logger.info(f"Starting Mini SpecsComply Pro on {args.host}:{args.port}") + + # Run the application + uvicorn.run( + "app.main:app", + host=args.host, + port=args.port, + reload=args.reload, + log_level=log_level.lower(), + ) + +if __name__ == "__main__": + main() \ No newline at end of file