-
-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Validate Zotero credentials early and support configurable library type #212
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
base: main
Are you sure you want to change the base?
Changes from all commits
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 | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -29,9 +29,24 @@ def normalize_include_path_patterns(include_path: list[str] | ListConfig | None) | |||||||||||
| return list(include_path) | ||||||||||||
|
|
||||||||||||
|
|
||||||||||||
| def normalize_zotero_settings(zotero_config: DictConfig) -> tuple[str, str, str]: | ||||||||||||
| user_id = str(zotero_config.get("user_id") or "").strip() | ||||||||||||
| api_key = str(zotero_config.get("api_key") or "").strip() | ||||||||||||
| library_type = str(zotero_config.get("library_type", "user")).strip().lower() | ||||||||||||
|
|
||||||||||||
| if not user_id or not api_key: | ||||||||||||
| raise ValueError("config.zotero.user_id and config.zotero.api_key must be set.") | ||||||||||||
|
|
||||||||||||
| if library_type not in {"user", "group"}: | ||||||||||||
| raise ValueError('config.zotero.library_type must be either "user" or "group".') | ||||||||||||
|
Comment on lines
+40
to
+41
|
||||||||||||
|
|
||||||||||||
| return user_id, api_key, library_type | ||||||||||||
|
Comment on lines
+32
to
+43
|
||||||||||||
|
|
||||||||||||
|
|
||||||||||||
| class Executor: | ||||||||||||
| def __init__(self, config:DictConfig): | ||||||||||||
| self.config = config | ||||||||||||
| self.zotero_user_id, self.zotero_api_key, self.zotero_library_type = normalize_zotero_settings(config.zotero) | ||||||||||||
| self.include_path_patterns = normalize_include_path_patterns(config.zotero.include_path) | ||||||||||||
| self.retrievers = { | ||||||||||||
| source: get_retriever_cls(source)(config) for source in config.executor.source | ||||||||||||
|
|
@@ -40,10 +55,13 @@ def __init__(self, config:DictConfig): | |||||||||||
| self.openai_client = OpenAI(api_key=config.llm.api.key, base_url=config.llm.api.base_url) | ||||||||||||
| def fetch_zotero_corpus(self) -> list[CorpusPaper]: | ||||||||||||
| logger.info("Fetching zotero corpus") | ||||||||||||
| zot = zotero.Zotero(self.config.zotero.user_id, 'user', self.config.zotero.api_key) | ||||||||||||
| collections = zot.everything(zot.collections()) | ||||||||||||
| zot = zotero.Zotero(self.zotero_user_id, self.zotero_library_type, self.zotero_api_key) | ||||||||||||
| try: | ||||||||||||
| collections = zot.everything(zot.collections()) | ||||||||||||
| corpus = zot.everything(zot.items(itemType='conferencePaper || journalArticle || preprint')) | ||||||||||||
| except Exception as e: | ||||||||||||
| raise RuntimeError("Failed to access Zotero library. Please check user_id, api_key, and library_type.") from e | ||||||||||||
|
||||||||||||
| raise RuntimeError("Failed to access Zotero library. Please check user_id, api_key, and library_type.") from e | |
| raise RuntimeError( | |
| "Failed to access Zotero library. This may be due to invalid user_id/api_key/library_type " | |
| f"or a transient Zotero/network issue. Original error: {type(e).__name__}: {e}" | |
| ) from e |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
library_typenormalization treats an explicit null/None value as the string "none" (becausestr(None).lower()), which then fails validation. If users wire this to an env var with anulldefault (common with Hydra/OmegaConf), the config will error unexpectedly. Consider defaulting falsy values to "user" (e.g., applyor "user"before lowercasing) so missing/empty values behave like the intended default.