From 5b5bc86f2aacb4eda6932a680e555dd4ad0d27ab Mon Sep 17 00:00:00 2001 From: Philo Wu Date: Sat, 14 Feb 2026 20:18:51 +1100 Subject: [PATCH] fix #1: separate error message for cache and api key --- src/embed_papers/searcher.py | 4 ++-- src/embed_papers/viewer/app.py | 7 +++++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/embed_papers/searcher.py b/src/embed_papers/searcher.py index bf872e0..1e64ba1 100644 --- a/src/embed_papers/searcher.py +++ b/src/embed_papers/searcher.py @@ -267,7 +267,7 @@ def _get_client(self) -> Any: key = self.resolved_api_key if not key: raise CacheMissRequiresApiKeyError( - "Embeddings cache not found. Set OPENAI_API_KEY (or pass api_key) to create conference cache." + "OpenAI API key required to compute embeddings. Set OPENAI_API_KEY (or pass api_key)." ) from openai import OpenAI @@ -309,7 +309,7 @@ def compute_embeddings(self, force: bool = False) -> np.ndarray: if self.require_api_key_on_cache_miss and not self.resolved_api_key: raise CacheMissRequiresApiKeyError( - "No cache for this venue/model and no API key found. Set OPENAI_API_KEY to build cache." + "No cached embeddings for this venue/model and no API key found. Set OPENAI_API_KEY to build cache." ) _log(f"Computing embeddings ({self.model_name})...") diff --git a/src/embed_papers/viewer/app.py b/src/embed_papers/viewer/app.py index 952f1b6..e859b48 100644 --- a/src/embed_papers/viewer/app.py +++ b/src/embed_papers/viewer/app.py @@ -1,6 +1,7 @@ from __future__ import annotations import json +import os from html import escape from pathlib import Path from typing import Any @@ -337,6 +338,12 @@ def _render_sidebar_form() -> dict[str, Any] | None: st.error("Upload a valid examples JSON file before running search.") return None + if not os.getenv("OPENAI_API_KEY"): + st.error( + "OPENAI_API_KEY is required to embed queries/examples. Set it in your shell and restart the app." + ) + return None + return { "conference": conference, "year": int(year),