DeepImagix commited on
Commit
7004a3e
·
verified ·
1 Parent(s): c7b0419

Upload 3 files

Browse files
core/dependencies.py ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ FastAPI Dependencies
3
+ """
4
+
5
+ from fastapi import Depends, HTTPException, Request
6
+ from services.polar_service import PolarService
7
+ from core.exceptions import RateLimitException
8
+
9
+ async def get_current_user(request: Request):
10
+ # Extract user from request (simplified)
11
+ user_id = request.headers.get("X-User-ID", "anonymous")
12
+ return user_id
13
+
14
+ async def verify_premium(user_id: str = Depends(get_current_user)):
15
+ # This would check Polar subscription
16
+ return True # Placeholder
17
+
18
+ def rate_limit_check(user_id: str = Depends(get_current_user)):
19
+ # Implement rate limiting logic here
20
+ pass
core/exceptions.py ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ Custom Exceptions for NeuraPrompt
3
+ """
4
+
5
+ class NeuraPromptException(Exception):
6
+ """Base exception for all NeuraPrompt errors"""
7
+ def __init__(self, message: str, code: str = "INTERNAL_ERROR"):
8
+ self.message = message
9
+ self.code = code
10
+ super().__init__(self.message)
11
+
12
+
13
+ class RateLimitException(NeuraPromptException):
14
+ def __init__(self, message: str = "Rate limit exceeded"):
15
+ super().__init__(message, "RATE_LIMIT")
16
+
17
+
18
+ class ModelNotFoundException(NeuraPromptException):
19
+ def __init__(self, model_id: str):
20
+ super().__init__(f"Model '{model_id}' not found", "MODEL_NOT_FOUND")
21
+
22
+
23
+ class PolarVerificationException(NeuraPromptException):
24
+ def __init__(self, message: str = "Polar verification failed"):
25
+ super().__init__(message, "POLAR_ERROR")
core/logging_config.py ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ Centralized Logging Configuration
3
+ """
4
+
5
+ import logging
6
+ import sys
7
+ from datetime import datetime
8
+
9
+ def setup_logging():
10
+ logging.basicConfig(
11
+ level=logging.INFO,
12
+ format="%(asctime)s | %(levelname)-8s | %(name)s | %(message)s",
13
+ handlers=[
14
+ logging.StreamHandler(sys.stdout),
15
+ logging.FileHandler("neuraprompt.log", encoding="utf-8")
16
+ ]
17
+ )
18
+
19
+ # Reduce noise from libraries
20
+ logging.getLogger("httpx").setLevel(logging.WARNING)
21
+ logging.getLogger("pymongo").setLevel(logging.WARNING)
22
+
23
+ return logging.getLogger("neuraprompt")