-
Notifications
You must be signed in to change notification settings - Fork 3.4k
RAG: 401 on invalid OpenAI key; prevent silent empty results (#371/#362) #521
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -31,6 +31,10 @@ | |||||||||||||||||
| from ..services.search.rag_service import RAGService | ||||||||||||||||||
| from ..services.storage import DocumentStorageService | ||||||||||||||||||
| from ..utils import get_supabase_client | ||||||||||||||||||
| from ..services.embeddings.embedding_exceptions import ( | ||||||||||||||||||
| EmbeddingAuthenticationError, | ||||||||||||||||||
| EmbeddingQuotaExhaustedError, | ||||||||||||||||||
| ) | ||||||||||||||||||
| from ..utils.document_processing import extract_text_from_document | ||||||||||||||||||
|
|
||||||||||||||||||
| # Get logger for this module | ||||||||||||||||||
|
|
@@ -750,6 +754,9 @@ async def perform_rag_query(request: RagQueryRequest): | |||||||||||||||||
| ) | ||||||||||||||||||
| except HTTPException: | ||||||||||||||||||
| raise | ||||||||||||||||||
| except EmbeddingAuthenticationError as e: | ||||||||||||||||||
| safe_logfire_error(f"Authentication error in RAG query: {str(e)}") | ||||||||||||||||||
| raise HTTPException(status_code=401, detail="Invalid API key") | ||||||||||||||||||
| except Exception as e: | ||||||||||||||||||
| safe_logfire_error( | ||||||||||||||||||
| f"RAG query failed | error={str(e)} | query={request.query[:50]} | source={request.source}" | ||||||||||||||||||
|
|
@@ -784,6 +791,9 @@ async def search_code_examples(request: RagQueryRequest): | |||||||||||||||||
| ) | ||||||||||||||||||
| except HTTPException: | ||||||||||||||||||
| raise | ||||||||||||||||||
| except EmbeddingAuthenticationError as e: | ||||||||||||||||||
| safe_logfire_error(f"Authentication error in code examples search: {str(e)}") | ||||||||||||||||||
| raise HTTPException(status_code=401, detail="Invalid API key") | ||||||||||||||||||
| except Exception as e: | ||||||||||||||||||
|
Comment on lines
+794
to
796
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Same here: standardize the 401 response body. - raise HTTPException(status_code=401, detail="Invalid API key")
+ raise HTTPException(status_code=401, detail={"error": "Invalid API key"})📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||
| safe_logfire_error( | ||||||||||||||||||
| f"Code examples search failed | error={str(e)} | query={request.query[:50]} | source={request.source}" | ||||||||||||||||||
|
|
||||||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.