Skip to content

Commit 1d5e4ec

Browse files
committed
Add 'trial mode' - No DB or credits needed
1 parent b9e9b04 commit 1d5e4ec

File tree

4 files changed

+16
-4
lines changed

4 files changed

+16
-4
lines changed

app/api/v1/routes/ideas.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ async def rank_ideas(
2525
request: Request,
2626
ideaRequest: IdeaRequest,
2727
user_info: dict = Depends(verify_token),
28-
) -> AnalysisResponse:
28+
) -> AnalysisResponse | Response:
2929
"""
3030
Analyze and rank ideas based on semantic similarity.
3131
@@ -186,17 +186,17 @@ async def process_advanced_features(
186186
total_bytes: int
187187
) -> dict:
188188
"""Process and add advanced features if credits are available"""
189-
if request.advanced_features.relationship_graph:
189+
if request.advanced_features and request.advanced_features.relationship_graph:
190190
response["relationship_graph"] = build_relationship_graph(
191191
response["ranked_ideas"], plot_data
192192
)
193193
await CreditService.deduct_credits(user_id, "relationship_graph", num_ideas, total_bytes)
194194

195-
if request.advanced_features.cluster_names:
195+
if request.advanced_features and request.advanced_features.cluster_names:
196196
response["cluster_names"] = await summarize_clusters(response["ranked_ideas"])
197197
await CreditService.deduct_credits(user_id, "cluster_names", num_ideas, total_bytes)
198198

199-
if request.advanced_features.pairwise_similarity_matrix:
199+
if request.advanced_features and request.advanced_features.pairwise_similarity_matrix:
200200
response["pairwise_similarity_matrix"] = plot_data["pairwise_similarity"]
201201

202202
return response

app/core/config.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ class Settings(BaseSettings):
5353
USER_DAILY_CREDITS: int = 100
5454
USER_MAX_CREDITS: int = 1000
5555

56+
is_in_trial_mode: bool = True
57+
5658
# Environment
5759
ENVIRONMENT: str = "DEV"
5860

app/core/security.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,12 @@ async def verify_token(request: Request, credentials: Optional[HTTPAuthorization
125125

126126
# Whatever the logic flow, first we need to make sure that there isn't a different user still authorized:
127127
db.auth.sign_out()
128+
if settings.is_in_trial_mode:
129+
return {
130+
"user_id": f"trial_mode_{datetime.now()}",
131+
"is_guest": True,
132+
"balance": 1000
133+
}
128134

129135
# Now we can do the rest of the logic. run test routines first, then check guest or proper user.
130136
try:

app/services/credits.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,16 @@ async def get_total_cost(operations, num_ideas, bytes):
2626
@staticmethod
2727
async def get_credits(user_id: str) -> int:
2828
"""Get available credits for user"""
29+
if settings.is_in_trial_mode:
30+
return 1000
2931
credits = db.table('credits').select('balance').eq('user_id', user_id).single().execute()
3032
return int(credits.data['balance']) if credits.data else 0
3133

3234
@staticmethod
3335
async def deduct_credits(user_id: str, operation: str, data_size: int, bytes: int) -> bool:
3436
"""Deduct credits after successful operation"""
37+
if settings.is_in_trial_mode:
38+
return True
3539
cost = await CreditService.get_operation_cost(operation, data_size, bytes)
3640
print(f"Deducting {cost} credits from {user_id} for {operation} with {data_size} statements and a total of {bytes} bytes")
3741
result = db.rpc(

0 commit comments

Comments
 (0)