feat(MAT-65): Remove WildFiles org-level fallback, require per-user key
No more shared org-level document search for unauthenticated users. DocumentRAG.search() now returns empty if no API key provided. Explicit !ai search command tells users to connect first. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
11
bot.py
11
bot.py
@@ -319,15 +319,11 @@ class DocumentRAG:
|
|||||||
self.enabled = bool(base_url and org)
|
self.enabled = bool(base_url and org)
|
||||||
|
|
||||||
async def search(self, query: str, top_k: int = 3, api_key: str | None = None) -> list[dict]:
|
async def search(self, query: str, top_k: int = 3, api_key: str | None = None) -> list[dict]:
|
||||||
if not api_key and not self.enabled:
|
if not api_key:
|
||||||
return []
|
return []
|
||||||
try:
|
try:
|
||||||
headers = {}
|
headers = {"X-API-Key": api_key}
|
||||||
body = {"query": query, "limit": top_k}
|
body = {"query": query, "limit": top_k}
|
||||||
if api_key:
|
|
||||||
headers["X-API-Key"] = api_key
|
|
||||||
else:
|
|
||||||
body["organization"] = self.org
|
|
||||||
async with httpx.AsyncClient(timeout=15.0) as client:
|
async with httpx.AsyncClient(timeout=15.0) as client:
|
||||||
resp = await client.post(
|
resp = await client.post(
|
||||||
f"{self.base_url}/api/v1/rag/search",
|
f"{self.base_url}/api/v1/rag/search",
|
||||||
@@ -1809,6 +1805,9 @@ class Bot:
|
|||||||
return
|
return
|
||||||
sender = event.sender if event else None
|
sender = event.sender if event else None
|
||||||
user_api_key = self.user_keys.get(sender) if sender else None
|
user_api_key = self.user_keys.get(sender) if sender else None
|
||||||
|
if not user_api_key:
|
||||||
|
await self._send_text(room.room_id, "WildFiles not connected. Use `!ai wildfiles connect` first.")
|
||||||
|
return
|
||||||
results = await self.rag.search(query, top_k=5, api_key=user_api_key)
|
results = await self.rag.search(query, top_k=5, api_key=user_api_key)
|
||||||
if not results:
|
if not results:
|
||||||
await self._send_text(room.room_id, "No documents found.")
|
await self._send_text(room.room_id, "No documents found.")
|
||||||
|
|||||||
Reference in New Issue
Block a user