Spaces:
Sleeping
Sleeping
github-actions[bot] commited on
Commit ·
cbe8d49
1
Parent(s): b2673e1
Auto-deploy backend from GitHub Actions
Browse files- app/api/v1/endpoints/discover.py +20 -0
- app/schemas/discover.py +4 -0
app/api/v1/endpoints/discover.py
CHANGED
|
@@ -90,12 +90,32 @@ async def discover_from_vision(
|
|
| 90 |
|
| 91 |
token = sign_quest_matches(verified_matches) if verified_matches else None
|
| 92 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 93 |
return DiscoverResponse(
|
| 94 |
scanned_object=llm_resp.scanned_object,
|
| 95 |
teaser_doors=llm_resp.teaser_doors,
|
| 96 |
matched_quest_ids=[m["id"] for m in verified_matches],
|
| 97 |
gamification_token=token,
|
| 98 |
quest_target_lenses=list(target_lenses),
|
|
|
|
| 99 |
)
|
| 100 |
|
| 101 |
except HTTPException:
|
|
|
|
| 90 |
|
| 91 |
token = sign_quest_matches(verified_matches) if verified_matches else None
|
| 92 |
|
| 93 |
+
# --- 4. NEW: Memory Pre-Check (Foreshadowing State) ---
|
| 94 |
+
completed_lenses = []
|
| 95 |
+
try:
|
| 96 |
+
past_scans = (
|
| 97 |
+
db_client.table("scans")
|
| 98 |
+
.select("chosen_lens")
|
| 99 |
+
.eq("user_id", user_id)
|
| 100 |
+
.eq("object_name", llm_resp.scanned_object)
|
| 101 |
+
.execute()
|
| 102 |
+
)
|
| 103 |
+
if past_scans.data:
|
| 104 |
+
# Extract unique lenses they have already completed for this object
|
| 105 |
+
completed_lenses = list(
|
| 106 |
+
set([scan["chosen_lens"] for scan in past_scans.data])
|
| 107 |
+
)
|
| 108 |
+
except Exception as mem_err:
|
| 109 |
+
logger.error(f"Failed to fetch completed lenses: {mem_err}")
|
| 110 |
+
# Non-fatal error, we just pass an empty list if it fails
|
| 111 |
+
|
| 112 |
return DiscoverResponse(
|
| 113 |
scanned_object=llm_resp.scanned_object,
|
| 114 |
teaser_doors=llm_resp.teaser_doors,
|
| 115 |
matched_quest_ids=[m["id"] for m in verified_matches],
|
| 116 |
gamification_token=token,
|
| 117 |
quest_target_lenses=list(target_lenses),
|
| 118 |
+
completed_lenses=completed_lenses, # 🚀 Pass it to the mobile UI
|
| 119 |
)
|
| 120 |
|
| 121 |
except HTTPException:
|
app/schemas/discover.py
CHANGED
|
@@ -32,3 +32,7 @@ class DiscoverResponse(DiscoverLLMResponse):
|
|
| 32 |
quest_target_lenses: list[str] = Field(
|
| 33 |
default_factory=list, description="Lenses to highlight in UI"
|
| 34 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
quest_target_lenses: list[str] = Field(
|
| 33 |
default_factory=list, description="Lenses to highlight in UI"
|
| 34 |
)
|
| 35 |
+
completed_lenses: list[str] = Field(
|
| 36 |
+
default_factory=list,
|
| 37 |
+
description="Lenses already completed for this object by this user",
|
| 38 |
+
)
|