87 lines
2.7 KiB
Python
87 lines
2.7 KiB
Python
#!/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() |