papers-app 0.3.0__tar.gz → 0.3.2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {papers_app-0.3.0 → papers_app-0.3.2}/CONTRIBUTING.md +1 -1
- {papers_app-0.3.0 → papers_app-0.3.2}/PKG-INFO +26 -8
- {papers_app-0.3.0 → papers_app-0.3.2}/README.md +24 -7
- {papers_app-0.3.0 → papers_app-0.3.2}/papers/__init__.py +1 -1
- {papers_app-0.3.0 → papers_app-0.3.2}/papers/agent/loop.py +1 -2
- {papers_app-0.3.0 → papers_app-0.3.2}/papers/ai/anthropic_api.py +21 -6
- papers_app-0.3.2/papers/cli.py +151 -0
- {papers_app-0.3.0 → papers_app-0.3.2}/papers/llm.py +17 -0
- {papers_app-0.3.0 → papers_app-0.3.2}/papers/pdf.py +5 -0
- {papers_app-0.3.0 → papers_app-0.3.2}/papers/roadmap.py +11 -16
- {papers_app-0.3.0 → papers_app-0.3.2}/papers/routes/goals.py +5 -7
- {papers_app-0.3.0 → papers_app-0.3.2}/papers/routes/papers.py +7 -0
- {papers_app-0.3.0 → papers_app-0.3.2}/papers/scholar.py +51 -7
- papers_app-0.3.2/papers/setup.py +317 -0
- {papers_app-0.3.0 → papers_app-0.3.2}/papers/static/css/goals.css +34 -1
- {papers_app-0.3.0 → papers_app-0.3.2}/papers/static/css/library.css +11 -1
- {papers_app-0.3.0 → papers_app-0.3.2}/papers/static/js/covers.js +29 -1
- {papers_app-0.3.0 → papers_app-0.3.2}/papers/static/js/pages/goals.js +14 -5
- {papers_app-0.3.0 → papers_app-0.3.2}/papers/static/js/pages/library.js +29 -3
- {papers_app-0.3.0 → papers_app-0.3.2}/papers/static/js/paper/reader.js +4 -0
- {papers_app-0.3.0 → papers_app-0.3.2}/papers/store.py +3 -1
- {papers_app-0.3.0 → papers_app-0.3.2}/pyproject.toml +1 -0
- papers_app-0.3.2/tests/test_cli.py +70 -0
- {papers_app-0.3.0 → papers_app-0.3.2}/tests/test_papers.py +10 -0
- {papers_app-0.3.0 → papers_app-0.3.2}/tests/test_roadmap.py +12 -0
- {papers_app-0.3.0 → papers_app-0.3.2}/tests/test_setup.py +31 -10
- papers_app-0.3.0/papers/cli.py +0 -67
- papers_app-0.3.0/papers/setup.py +0 -250
- {papers_app-0.3.0 → papers_app-0.3.2}/.gitignore +0 -0
- {papers_app-0.3.0 → papers_app-0.3.2}/LICENSE +0 -0
- {papers_app-0.3.0 → papers_app-0.3.2}/papers/__main__.py +0 -0
- {papers_app-0.3.0 → papers_app-0.3.2}/papers/agent/__init__.py +0 -0
- {papers_app-0.3.0 → papers_app-0.3.2}/papers/agent/mcp_server.py +0 -0
- {papers_app-0.3.0 → papers_app-0.3.2}/papers/agent/tools.py +0 -0
- {papers_app-0.3.0 → papers_app-0.3.2}/papers/ai/__init__.py +0 -0
- {papers_app-0.3.0 → papers_app-0.3.2}/papers/ai/capabilities.py +0 -0
- {papers_app-0.3.0 → papers_app-0.3.2}/papers/ai/claude_code.py +0 -0
- {papers_app-0.3.0 → papers_app-0.3.2}/papers/ai/codex.py +0 -0
- {papers_app-0.3.0 → papers_app-0.3.2}/papers/ai/errors.py +0 -0
- {papers_app-0.3.0 → papers_app-0.3.2}/papers/ai/openai_compat.py +0 -0
- {papers_app-0.3.0 → papers_app-0.3.2}/papers/ai/providers.py +0 -0
- {papers_app-0.3.0 → papers_app-0.3.2}/papers/ai/streaming.py +0 -0
- {papers_app-0.3.0 → papers_app-0.3.2}/papers/bibtex.py +0 -0
- {papers_app-0.3.0 → papers_app-0.3.2}/papers/chat/__init__.py +0 -0
- {papers_app-0.3.0 → papers_app-0.3.2}/papers/chat/answer.py +0 -0
- {papers_app-0.3.0 → papers_app-0.3.2}/papers/chat/store.py +0 -0
- {papers_app-0.3.0 → papers_app-0.3.2}/papers/config.py +0 -0
- {papers_app-0.3.0 → papers_app-0.3.2}/papers/db.py +0 -0
- {papers_app-0.3.0 → papers_app-0.3.2}/papers/figures.py +0 -0
- {papers_app-0.3.0 → papers_app-0.3.2}/papers/folders.py +0 -0
- {papers_app-0.3.0 → papers_app-0.3.2}/papers/index.py +0 -0
- {papers_app-0.3.0 → papers_app-0.3.2}/papers/ingest.py +0 -0
- {papers_app-0.3.0 → papers_app-0.3.2}/papers/keys.py +0 -0
- {papers_app-0.3.0 → papers_app-0.3.2}/papers/library.py +0 -0
- {papers_app-0.3.0 → papers_app-0.3.2}/papers/main.py +0 -0
- {papers_app-0.3.0 → papers_app-0.3.2}/papers/notes.py +0 -0
- {papers_app-0.3.0 → papers_app-0.3.2}/papers/routes/__init__.py +0 -0
- {papers_app-0.3.0 → papers_app-0.3.2}/papers/routes/chat.py +0 -0
- {papers_app-0.3.0 → papers_app-0.3.2}/papers/routes/learning.py +0 -0
- {papers_app-0.3.0 → papers_app-0.3.2}/papers/routes/notes.py +0 -0
- {papers_app-0.3.0 → papers_app-0.3.2}/papers/routes/reading.py +0 -0
- {papers_app-0.3.0 → papers_app-0.3.2}/papers/routes/recall.py +0 -0
- {papers_app-0.3.0 → papers_app-0.3.2}/papers/routes/settings.py +0 -0
- {papers_app-0.3.0 → papers_app-0.3.2}/papers/static/css/base.css +0 -0
- {papers_app-0.3.0 → papers_app-0.3.2}/papers/static/css/chat.css +0 -0
- {papers_app-0.3.0 → papers_app-0.3.2}/papers/static/css/components.css +0 -0
- {papers_app-0.3.0 → papers_app-0.3.2}/papers/static/css/map.css +0 -0
- {papers_app-0.3.0 → papers_app-0.3.2}/papers/static/css/paper.css +0 -0
- {papers_app-0.3.0 → papers_app-0.3.2}/papers/static/css/reader.css +0 -0
- {papers_app-0.3.0 → papers_app-0.3.2}/papers/static/css/recall.css +0 -0
- {papers_app-0.3.0 → papers_app-0.3.2}/papers/static/css/settings.css +0 -0
- {papers_app-0.3.0 → papers_app-0.3.2}/papers/static/css/tokens.css +0 -0
- {papers_app-0.3.0 → papers_app-0.3.2}/papers/static/css/welcome.css +0 -0
- {papers_app-0.3.0 → papers_app-0.3.2}/papers/static/index.html +0 -0
- {papers_app-0.3.0 → papers_app-0.3.2}/papers/static/js/chat/answer.js +0 -0
- {papers_app-0.3.0 → papers_app-0.3.2}/papers/static/js/chat/canvas.js +0 -0
- {papers_app-0.3.0 → papers_app-0.3.2}/papers/static/js/chat/conversation.js +0 -0
- {papers_app-0.3.0 → papers_app-0.3.2}/papers/static/js/chat/render.js +0 -0
- {papers_app-0.3.0 → papers_app-0.3.2}/papers/static/js/chat/stream.js +0 -0
- {papers_app-0.3.0 → papers_app-0.3.2}/papers/static/js/chat/widgets.js +0 -0
- {papers_app-0.3.0 → papers_app-0.3.2}/papers/static/js/components/combobox.js +0 -0
- {papers_app-0.3.0 → papers_app-0.3.2}/papers/static/js/components/folderpicker.js +0 -0
- {papers_app-0.3.0 → papers_app-0.3.2}/papers/static/js/core.js +0 -0
- {papers_app-0.3.0 → papers_app-0.3.2}/papers/static/js/highlights.js +0 -0
- {papers_app-0.3.0 → papers_app-0.3.2}/papers/static/js/icons.js +0 -0
- {papers_app-0.3.0 → papers_app-0.3.2}/papers/static/js/main.js +0 -0
- {papers_app-0.3.0 → papers_app-0.3.2}/papers/static/js/notes.js +0 -0
- {papers_app-0.3.0 → papers_app-0.3.2}/papers/static/js/pages/map.js +0 -0
- {papers_app-0.3.0 → papers_app-0.3.2}/papers/static/js/pages/recall.js +0 -0
- {papers_app-0.3.0 → papers_app-0.3.2}/papers/static/js/pages/settings.js +0 -0
- {papers_app-0.3.0 → papers_app-0.3.2}/papers/static/js/pages/shared.js +0 -0
- {papers_app-0.3.0 → papers_app-0.3.2}/papers/static/js/pages/welcome.js +0 -0
- {papers_app-0.3.0 → papers_app-0.3.2}/papers/static/js/paper/figures.js +0 -0
- {papers_app-0.3.0 → papers_app-0.3.2}/papers/static/js/paper/overview.js +0 -0
- {papers_app-0.3.0 → papers_app-0.3.2}/papers/static/js/paper/reader/bar.js +0 -0
- {papers_app-0.3.0 → papers_app-0.3.2}/papers/static/js/paper/reader/cite.js +0 -0
- {papers_app-0.3.0 → papers_app-0.3.2}/papers/static/js/paper/reader/finish.js +0 -0
- {papers_app-0.3.0 → papers_app-0.3.2}/papers/static/js/paper/reader/highlighter.js +0 -0
- {papers_app-0.3.0 → papers_app-0.3.2}/papers/static/js/paper/reader/keys.js +0 -0
- {papers_app-0.3.0 → papers_app-0.3.2}/papers/static/js/paper/reader/layout.js +0 -0
- {papers_app-0.3.0 → papers_app-0.3.2}/papers/static/js/paper/reader/panel.js +0 -0
- {papers_app-0.3.0 → papers_app-0.3.2}/papers/static/js/paper/reader/progress.js +0 -0
- {papers_app-0.3.0 → papers_app-0.3.2}/papers/static/js/paper/reader/route.js +0 -0
- {papers_app-0.3.0 → papers_app-0.3.2}/papers/static/js/paper/reader/selection.js +0 -0
- {papers_app-0.3.0 → papers_app-0.3.2}/papers/static/js/paper/reader/state.js +0 -0
- {papers_app-0.3.0 → papers_app-0.3.2}/papers/static/js/paper/reader/terms.js +0 -0
- {papers_app-0.3.0 → papers_app-0.3.2}/papers/static/js/paper/reader/views.js +0 -0
- {papers_app-0.3.0 → papers_app-0.3.2}/papers/static/js/paper/reader/vocab.js +0 -0
- {papers_app-0.3.0 → papers_app-0.3.2}/papers/static/js/paper/reader/zoom.js +0 -0
- {papers_app-0.3.0 → papers_app-0.3.2}/papers/static/js/paper/review.js +0 -0
- {papers_app-0.3.0 → papers_app-0.3.2}/papers/static/js/paper/shared.js +0 -0
- {papers_app-0.3.0 → papers_app-0.3.2}/papers/static/js/pdfview.js +0 -0
- {papers_app-0.3.0 → papers_app-0.3.2}/papers/static/js/readprefs.js +0 -0
- {papers_app-0.3.0 → papers_app-0.3.2}/papers/static/js/speech.js +0 -0
- {papers_app-0.3.0 → papers_app-0.3.2}/papers/static/js/textview.js +0 -0
- {papers_app-0.3.0 → papers_app-0.3.2}/papers/static/js/theme.js +0 -0
- {papers_app-0.3.0 → papers_app-0.3.2}/papers/static/js/tracker.js +0 -0
- {papers_app-0.3.0 → papers_app-0.3.2}/papers/storage.py +0 -0
- {papers_app-0.3.0 → papers_app-0.3.2}/tests/__init__.py +0 -0
- {papers_app-0.3.0 → papers_app-0.3.2}/tests/conftest.py +0 -0
- {papers_app-0.3.0 → papers_app-0.3.2}/tests/test_abstract_figures.py +0 -0
- {papers_app-0.3.0 → papers_app-0.3.2}/tests/test_add_link.py +0 -0
- {papers_app-0.3.0 → papers_app-0.3.2}/tests/test_agent.py +0 -0
- {papers_app-0.3.0 → papers_app-0.3.2}/tests/test_agent_actions.py +0 -0
- {papers_app-0.3.0 → papers_app-0.3.2}/tests/test_ai.py +0 -0
- {papers_app-0.3.0 → papers_app-0.3.2}/tests/test_capabilities.py +0 -0
- {papers_app-0.3.0 → papers_app-0.3.2}/tests/test_capture.py +0 -0
- {papers_app-0.3.0 → papers_app-0.3.2}/tests/test_claude_code.py +0 -0
- {papers_app-0.3.0 → papers_app-0.3.2}/tests/test_conversations.py +0 -0
- {papers_app-0.3.0 → papers_app-0.3.2}/tests/test_folders.py +0 -0
- {papers_app-0.3.0 → papers_app-0.3.2}/tests/test_frontend.py +0 -0
- {papers_app-0.3.0 → papers_app-0.3.2}/tests/test_highlights_notes.py +0 -0
- {papers_app-0.3.0 → papers_app-0.3.2}/tests/test_keys.py +0 -0
- {papers_app-0.3.0 → papers_app-0.3.2}/tests/test_learning.py +0 -0
- {papers_app-0.3.0 → papers_app-0.3.2}/tests/test_library_covers.py +0 -0
- {papers_app-0.3.0 → papers_app-0.3.2}/tests/test_library_folder.py +0 -0
- {papers_app-0.3.0 → papers_app-0.3.2}/tests/test_metadata.py +0 -0
- {papers_app-0.3.0 → papers_app-0.3.2}/tests/test_never_stuck.py +0 -0
- {papers_app-0.3.0 → papers_app-0.3.2}/tests/test_notes_ask.py +0 -0
- {papers_app-0.3.0 → papers_app-0.3.2}/tests/test_prepare.py +0 -0
- {papers_app-0.3.0 → papers_app-0.3.2}/tests/test_progress.py +0 -0
- {papers_app-0.3.0 → papers_app-0.3.2}/tests/test_prompts.py +0 -0
- {papers_app-0.3.0 → papers_app-0.3.2}/tests/test_provider_list.py +0 -0
- {papers_app-0.3.0 → papers_app-0.3.2}/tests/test_providers.py +0 -0
- {papers_app-0.3.0 → papers_app-0.3.2}/tests/test_recall_refs.py +0 -0
- {papers_app-0.3.0 → papers_app-0.3.2}/tests/test_review.py +0 -0
- {papers_app-0.3.0 → papers_app-0.3.2}/tests/test_scaffold.py +0 -0
- {papers_app-0.3.0 → papers_app-0.3.2}/tests/test_search.py +0 -0
- {papers_app-0.3.0 → papers_app-0.3.2}/tests/test_storage.py +0 -0
- {papers_app-0.3.0 → papers_app-0.3.2}/tests/test_streaming.py +0 -0
- {papers_app-0.3.0 → papers_app-0.3.2}/tests/test_tracker.py +0 -0
- {papers_app-0.3.0 → papers_app-0.3.2}/tests/test_triage.py +0 -0
- {papers_app-0.3.0 → papers_app-0.3.2}/tests/test_upload.py +0 -0
- {papers_app-0.3.0 → papers_app-0.3.2}/tests/test_vocabulary.py +0 -0
|
@@ -31,7 +31,7 @@ papers/
|
|
|
31
31
|
cli.py the `papers` command: options, then starts the server and opens the browser
|
|
32
32
|
config.py where data lives (the data folder, and config.json which remembers the chosen one) and every
|
|
33
33
|
environment variable
|
|
34
|
-
setup.py the first-run setup in the terminal (banner,
|
|
34
|
+
setup.py the first-run setup in the terminal (banner, library folder, AI); `papers setup`
|
|
35
35
|
storage.py what is kept where, with sizes, and moving the data folder (Settings › Where everything is kept)
|
|
36
36
|
main.py builds the app: the routers below, error handling, the web files, the Inbox watcher
|
|
37
37
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: papers-app
|
|
3
|
-
Version: 0.3.
|
|
3
|
+
Version: 0.3.2
|
|
4
4
|
Summary: An AI reading companion for research papers: skim, read, ask, recall. Runs on your computer.
|
|
5
5
|
Project-URL: Homepage, https://github.com/hBouanane/papers
|
|
6
6
|
Project-URL: Issues, https://github.com/hBouanane/papers/issues
|
|
@@ -16,6 +16,7 @@ Classifier: Topic :: Scientific/Engineering
|
|
|
16
16
|
Requires-Python: >=3.11
|
|
17
17
|
Requires-Dist: anthropic>=0.40
|
|
18
18
|
Requires-Dist: fastapi>=0.115
|
|
19
|
+
Requires-Dist: fonttools>=4
|
|
19
20
|
Requires-Dist: httpx>=0.27
|
|
20
21
|
Requires-Dist: keyring>=24
|
|
21
22
|
Requires-Dist: pdfplumber>=0.11
|
|
@@ -106,26 +107,43 @@ figures and check your library first.</td>
|
|
|
106
107
|
|
|
107
108
|
## Install
|
|
108
109
|
|
|
109
|
-
|
|
110
|
+
One command, with [uv](https://docs.astral.sh/uv/) (like `npx` for Node; it brings its own Python):
|
|
110
111
|
|
|
111
112
|
```bash
|
|
112
113
|
uvx papers-app
|
|
113
114
|
```
|
|
114
115
|
|
|
115
|
-
|
|
116
|
+
No `uvx` on your computer? Install uv first, then open a new terminal:
|
|
117
|
+
|
|
118
|
+
```bash
|
|
119
|
+
# Windows (PowerShell)
|
|
120
|
+
powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex"
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
```bash
|
|
124
|
+
# macOS and Linux
|
|
125
|
+
curl -LsSf https://astral.sh/uv/install.sh | sh
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
Or, with Python 3.11 or newer already installed, install it with pip's `pipx` and start it with `papers`:
|
|
116
129
|
|
|
117
130
|
```bash
|
|
118
131
|
pipx install papers-app
|
|
119
132
|
```
|
|
120
133
|
|
|
121
|
-
|
|
134
|
+
If the Python it lands on is one the libraries don't support yet (a pre-release, for example), Papers starts
|
|
135
|
+
itself again on Python 3.13 through uv. Without uv it tells you so; pick a released Python and try again.
|
|
136
|
+
|
|
137
|
+
The first time, a short setup in the terminal asks two things:
|
|
122
138
|
|
|
123
139
|
```
|
|
124
|
-
1/
|
|
125
|
-
2/
|
|
126
|
-
3/3 The AI model provider, key (kept in your system's keychain) and model, then a quick check
|
|
140
|
+
1/2 Your papers as normal files a folder with each paper's PDF and Markdown notes, for your file manager or Obsidian
|
|
141
|
+
2/2 The AI model provider, key (kept in your system's keychain) and model, then a quick check
|
|
127
142
|
```
|
|
128
143
|
|
|
144
|
+
The app's own data (database, PDFs, figures) goes to the usual place for app data; setup shows where, and Settings
|
|
145
|
+
can move it.
|
|
146
|
+
|
|
129
147
|
Then `papers` opens http://localhost:8000 in your browser. Everything can be changed later in Settings, or with
|
|
130
148
|
`papers setup`. Options: `--port 9000`, `--data D:\Papers` (use this data folder), `--no-browser`, `--no-setup`,
|
|
131
149
|
`--host 0.0.0.0` (reach it from other devices on your network; there is no login, so only on networks you trust).
|
|
@@ -145,7 +163,7 @@ Then open http://localhost:8000 and choose the AI in Settings. What each part me
|
|
|
145
163
|
| `-d --name papers` | run in the background, named `papers` (`docker stop papers` / `docker start papers`) |
|
|
146
164
|
| `-p 8000:8000` | the app inside listens on port 8000; this makes it http://localhost:8000 on your computer |
|
|
147
165
|
| `-v papers-data:/data` | your library (database, PDFs, figures) lives in `/data` inside the container; this keeps it in a Docker volume called `papers-data`, so it survives updates and restarts. Use a folder instead with `-v ~/Papers-data:/data` |
|
|
148
|
-
| `ghcr.io/hbouanane/papers:latest` | the image: on GitHub's registry (`ghcr.io`), from this repository, the newest release (or a version, e.g. `:0.3.
|
|
166
|
+
| `ghcr.io/hbouanane/papers:latest` | the image: on GitHub's registry (`ghcr.io`), from this repository, the newest release (or a version, e.g. `:0.3.2`) |
|
|
149
167
|
|
|
150
168
|
To update: `docker pull ghcr.io/hbouanane/papers:latest`, then `docker rm -f papers` and the same `docker run` again
|
|
151
169
|
(the volume keeps your library). From a clone you can also build it yourself with `docker compose up -d`; see
|
|
@@ -75,26 +75,43 @@ figures and check your library first.</td>
|
|
|
75
75
|
|
|
76
76
|
## Install
|
|
77
77
|
|
|
78
|
-
|
|
78
|
+
One command, with [uv](https://docs.astral.sh/uv/) (like `npx` for Node; it brings its own Python):
|
|
79
79
|
|
|
80
80
|
```bash
|
|
81
81
|
uvx papers-app
|
|
82
82
|
```
|
|
83
83
|
|
|
84
|
-
|
|
84
|
+
No `uvx` on your computer? Install uv first, then open a new terminal:
|
|
85
|
+
|
|
86
|
+
```bash
|
|
87
|
+
# Windows (PowerShell)
|
|
88
|
+
powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex"
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
```bash
|
|
92
|
+
# macOS and Linux
|
|
93
|
+
curl -LsSf https://astral.sh/uv/install.sh | sh
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
Or, with Python 3.11 or newer already installed, install it with pip's `pipx` and start it with `papers`:
|
|
85
97
|
|
|
86
98
|
```bash
|
|
87
99
|
pipx install papers-app
|
|
88
100
|
```
|
|
89
101
|
|
|
90
|
-
|
|
102
|
+
If the Python it lands on is one the libraries don't support yet (a pre-release, for example), Papers starts
|
|
103
|
+
itself again on Python 3.13 through uv. Without uv it tells you so; pick a released Python and try again.
|
|
104
|
+
|
|
105
|
+
The first time, a short setup in the terminal asks two things:
|
|
91
106
|
|
|
92
107
|
```
|
|
93
|
-
1/
|
|
94
|
-
2/
|
|
95
|
-
3/3 The AI model provider, key (kept in your system's keychain) and model, then a quick check
|
|
108
|
+
1/2 Your papers as normal files a folder with each paper's PDF and Markdown notes, for your file manager or Obsidian
|
|
109
|
+
2/2 The AI model provider, key (kept in your system's keychain) and model, then a quick check
|
|
96
110
|
```
|
|
97
111
|
|
|
112
|
+
The app's own data (database, PDFs, figures) goes to the usual place for app data; setup shows where, and Settings
|
|
113
|
+
can move it.
|
|
114
|
+
|
|
98
115
|
Then `papers` opens http://localhost:8000 in your browser. Everything can be changed later in Settings, or with
|
|
99
116
|
`papers setup`. Options: `--port 9000`, `--data D:\Papers` (use this data folder), `--no-browser`, `--no-setup`,
|
|
100
117
|
`--host 0.0.0.0` (reach it from other devices on your network; there is no login, so only on networks you trust).
|
|
@@ -114,7 +131,7 @@ Then open http://localhost:8000 and choose the AI in Settings. What each part me
|
|
|
114
131
|
| `-d --name papers` | run in the background, named `papers` (`docker stop papers` / `docker start papers`) |
|
|
115
132
|
| `-p 8000:8000` | the app inside listens on port 8000; this makes it http://localhost:8000 on your computer |
|
|
116
133
|
| `-v papers-data:/data` | your library (database, PDFs, figures) lives in `/data` inside the container; this keeps it in a Docker volume called `papers-data`, so it survives updates and restarts. Use a folder instead with `-v ~/Papers-data:/data` |
|
|
117
|
-
| `ghcr.io/hbouanane/papers:latest` | the image: on GitHub's registry (`ghcr.io`), from this repository, the newest release (or a version, e.g. `:0.3.
|
|
134
|
+
| `ghcr.io/hbouanane/papers:latest` | the image: on GitHub's registry (`ghcr.io`), from this repository, the newest release (or a version, e.g. `:0.3.2`) |
|
|
118
135
|
|
|
119
136
|
To update: `docker pull ghcr.io/hbouanane/papers:latest`, then `docker rm -f papers` and the same `docker run` again
|
|
120
137
|
(the volume keeps your library). From a clone you can also build it yourself with `docker compose up -d`; see
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
"""Papers: an AI reading companion for research papers."""
|
|
2
|
-
__version__ = "0.3.
|
|
2
|
+
__version__ = "0.3.2"
|
|
@@ -16,7 +16,6 @@ import sys
|
|
|
16
16
|
import tempfile
|
|
17
17
|
from dataclasses import asdict, dataclass
|
|
18
18
|
|
|
19
|
-
import anthropic
|
|
20
19
|
import httpx
|
|
21
20
|
|
|
22
21
|
from papers import config, llm
|
|
@@ -207,7 +206,7 @@ def _anthropic(paper: dict, system: list[dict], messages: list[dict]):
|
|
|
207
206
|
final = stream.get_final_message()
|
|
208
207
|
except TypeError as e:
|
|
209
208
|
raise AIError(anthropic_api.NOT_SET_UP) from e
|
|
210
|
-
except
|
|
209
|
+
except anthropic_api.sdk().APIError as e:
|
|
211
210
|
raise AIError(f"Claude request failed: {e}") from e
|
|
212
211
|
uses = [b for b in final.content if b.type == "tool_use"]
|
|
213
212
|
if final.stop_reason != "tool_use" or not uses:
|
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
"""The Anthropic API, with a key saved in Settings or ANTHROPIC_API_KEY (pay per use).
|
|
2
|
-
|
|
1
|
+
"""The Anthropic API, with a key saved in Settings or ANTHROPIC_API_KEY (pay per use).
|
|
2
|
+
|
|
3
|
+
The `anthropic` package takes several seconds to import (far longer the first time, before Python has compiled
|
|
4
|
+
it), so it's loaded when it's first used, not when the app starts: most starts never talk to this API at all.
|
|
5
|
+
"""
|
|
3
6
|
from pydantic import BaseModel
|
|
4
7
|
|
|
5
8
|
from papers.ai import providers
|
|
@@ -9,9 +12,21 @@ from papers.ai.streaming import as_messages
|
|
|
9
12
|
NOT_SET_UP = "Claude is not set up. In Settings, choose your Claude subscription, or set ANTHROPIC_API_KEY and restart."
|
|
10
13
|
|
|
11
14
|
|
|
12
|
-
def
|
|
15
|
+
def sdk():
|
|
16
|
+
"""The `anthropic` package, imported on first use."""
|
|
17
|
+
import anthropic
|
|
18
|
+
return anthropic
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def __getattr__(name: str): # `anthropic_api.anthropic` still works, for code and tests that reach for it
|
|
22
|
+
if name == "anthropic":
|
|
23
|
+
return sdk()
|
|
24
|
+
raise AttributeError(name)
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def client():
|
|
13
28
|
# A key saved in Settings wins; otherwise the SDK uses ANTHROPIC_API_KEY.
|
|
14
|
-
return
|
|
29
|
+
return sdk().Anthropic(api_key=providers.provider_setting("ai_key", "anthropic") or None)
|
|
15
30
|
|
|
16
31
|
|
|
17
32
|
def request(method: str, **kwargs):
|
|
@@ -19,7 +34,7 @@ def request(method: str, **kwargs):
|
|
|
19
34
|
response = getattr(client().messages, method)(model=providers.claude_model(), max_tokens=16000, **kwargs)
|
|
20
35
|
except TypeError as e:
|
|
21
36
|
raise AIError(NOT_SET_UP) from e
|
|
22
|
-
except
|
|
37
|
+
except sdk().APIError as e:
|
|
23
38
|
raise AIError(f"Claude request failed: {e}") from e
|
|
24
39
|
if response.stop_reason == "refusal":
|
|
25
40
|
raise AIError("The model declined this request.")
|
|
@@ -42,7 +57,7 @@ def stream(system: list[dict], content: str | list[dict], effort: str = "medium"
|
|
|
42
57
|
raise AIError("The model declined this request.")
|
|
43
58
|
except TypeError as e:
|
|
44
59
|
raise AIError(NOT_SET_UP) from e
|
|
45
|
-
except
|
|
60
|
+
except sdk().APIError as e:
|
|
46
61
|
raise AIError(f"Claude request failed: {e}") from e
|
|
47
62
|
|
|
48
63
|
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
"""The `papers` command: start the app and open it in your browser.
|
|
2
|
+
|
|
3
|
+
papers start on http://localhost:8000 and open the browser (the first time, a short setup)
|
|
4
|
+
papers setup the setup again: where your library is kept, which AI to use
|
|
5
|
+
papers --no-setup skip the setup (it's also skipped outside a terminal and with --data)
|
|
6
|
+
papers --port 9000 another port
|
|
7
|
+
papers --data D:\\Papers keep the database and PDFs somewhere else
|
|
8
|
+
papers --host 0.0.0.0 reachable from other devices on your network (no login: only on networks you trust)
|
|
9
|
+
papers --no-browser don't open the browser (servers, Docker)
|
|
10
|
+
"""
|
|
11
|
+
import argparse
|
|
12
|
+
import os
|
|
13
|
+
import shutil
|
|
14
|
+
import socket
|
|
15
|
+
import subprocess
|
|
16
|
+
import sys
|
|
17
|
+
import threading
|
|
18
|
+
import time
|
|
19
|
+
import urllib.request
|
|
20
|
+
import webbrowser
|
|
21
|
+
from contextlib import contextmanager
|
|
22
|
+
|
|
23
|
+
from papers import __version__
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def port_free(host: str, port: int) -> bool:
|
|
27
|
+
with socket.socket() as s:
|
|
28
|
+
return s.connect_ex(("127.0.0.1" if host in ("0.0.0.0", "::") else host, port)) != 0
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
GOOD_PYTHON = "3.13" # a released Python every library here supports
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
@contextmanager
|
|
35
|
+
def working(message: str):
|
|
36
|
+
"""A spinner with a few words while something slow happens, so the terminal never just sits there.
|
|
37
|
+
Loading the libraries takes seconds, and much longer the first time after installing."""
|
|
38
|
+
if not (sys.stdout.isatty() and not os.environ.get("CI")):
|
|
39
|
+
yield
|
|
40
|
+
return
|
|
41
|
+
from rich.console import Console
|
|
42
|
+
with Console().status(f"[dim]{message}[/]", spinner="dots", spinner_style="#6f8cf0"):
|
|
43
|
+
yield
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def python_problem() -> str | None:
|
|
47
|
+
"""Load the app's libraries; the reason, if this Python can't run them (a pre-release, or one too new)."""
|
|
48
|
+
try:
|
|
49
|
+
import pydantic
|
|
50
|
+
|
|
51
|
+
import papers.ai # noqa: F401 (the AI clients and everything they pull in)
|
|
52
|
+
|
|
53
|
+
class Probe(pydantic.BaseModel): # how pydantic reads a written-out type is what breaks first
|
|
54
|
+
value: "str"
|
|
55
|
+
return None
|
|
56
|
+
except Exception as e: # anything: these are other packages' errors
|
|
57
|
+
return f"{type(e).__name__}: {str(e).splitlines()[0] if str(e) else ''}"
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
def check_python(argv: list[str] | None = None, why: str | None = None) -> None:
|
|
61
|
+
"""On a Python the libraries can't run on, the app would crash halfway through setup. Instead it starts itself
|
|
62
|
+
again on a Python that works, when uv is there to fetch one, or says in one line what to do."""
|
|
63
|
+
why = why or python_problem()
|
|
64
|
+
if not why:
|
|
65
|
+
return
|
|
66
|
+
version = sys.version.split()[0]
|
|
67
|
+
uvx = shutil.which("uvx")
|
|
68
|
+
if uvx and not os.environ.get("PAPERS_PYTHON_RETRY"): # once: never loop
|
|
69
|
+
print(f"This Python ({version}) is not supported by one of Papers' libraries. "
|
|
70
|
+
f"Starting again on Python {GOOD_PYTHON}…\n")
|
|
71
|
+
args = sys.argv[1:] if argv is None else argv
|
|
72
|
+
again = [uvx, "--python", GOOD_PYTHON, f"papers-app=={__version__}", *args]
|
|
73
|
+
raise SystemExit(subprocess.call(again, env={**os.environ, "PAPERS_PYTHON_RETRY": "1"}))
|
|
74
|
+
print(f"Papers can't start on this Python ({version}): one of its libraries doesn't support it yet.")
|
|
75
|
+
print(f" {why}")
|
|
76
|
+
print("Run it on a released Python instead, for example:")
|
|
77
|
+
print(f" uvx --python {GOOD_PYTHON} papers-app")
|
|
78
|
+
raise SystemExit(1)
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
def wait_until_up(host: str, port: int, patience: float = 120) -> bool:
|
|
82
|
+
"""True once the app answers on its port (False after `patience` seconds)."""
|
|
83
|
+
address = f"http://{'127.0.0.1' if host in ('0.0.0.0', '::') else host}:{port}/api/health"
|
|
84
|
+
until = time.monotonic() + patience
|
|
85
|
+
while time.monotonic() < until:
|
|
86
|
+
try:
|
|
87
|
+
with urllib.request.urlopen(address, timeout=2) as answer:
|
|
88
|
+
if answer.status == 200:
|
|
89
|
+
return True
|
|
90
|
+
except OSError:
|
|
91
|
+
pass
|
|
92
|
+
time.sleep(0.25)
|
|
93
|
+
return False
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
def main(argv: list[str] | None = None) -> None:
|
|
97
|
+
parser = argparse.ArgumentParser(prog="papers", description="An AI reading companion for research papers.")
|
|
98
|
+
parser.add_argument("--port", type=int, default=int(os.environ.get("PAPERS_PORT", 8000)))
|
|
99
|
+
parser.add_argument("--host", default=os.environ.get("PAPERS_HOST", "127.0.0.1"))
|
|
100
|
+
parser.add_argument("--data", help="folder for the database, PDFs and figures")
|
|
101
|
+
parser.add_argument("--no-browser", action="store_true", help="don't open the browser")
|
|
102
|
+
parser.add_argument("--no-setup", action="store_true", help="don't ask the first-run questions")
|
|
103
|
+
parser.add_argument("command", nargs="?", choices=["setup"], help="setup: ask where to keep things and which AI to use")
|
|
104
|
+
parser.add_argument("--version", action="version", version=f"papers {__version__}")
|
|
105
|
+
args = parser.parse_args(argv)
|
|
106
|
+
|
|
107
|
+
if args.data:
|
|
108
|
+
os.environ["PAPERS_DATA"] = os.path.abspath(os.path.expanduser(args.data))
|
|
109
|
+
with working("Loading Papers…"):
|
|
110
|
+
why = python_problem()
|
|
111
|
+
if not why:
|
|
112
|
+
from papers import config, setup # after PAPERS_DATA is set
|
|
113
|
+
if why:
|
|
114
|
+
check_python(argv, why)
|
|
115
|
+
|
|
116
|
+
if args.command == "setup":
|
|
117
|
+
if not setup.interactive():
|
|
118
|
+
print("papers setup needs a terminal to ask its questions.")
|
|
119
|
+
raise SystemExit(1)
|
|
120
|
+
setup.run()
|
|
121
|
+
if input("\n Start Papers now? [Y/n] ").strip().lower() in ("n", "no"):
|
|
122
|
+
return
|
|
123
|
+
elif not args.no_setup and setup.needed():
|
|
124
|
+
setup.run()
|
|
125
|
+
|
|
126
|
+
url = f"http://localhost:{args.port}"
|
|
127
|
+
if not port_free(args.host, args.port):
|
|
128
|
+
print(f"Port {args.port} is in use. Is Papers already running? Open {url}, or start with --port 8001.")
|
|
129
|
+
raise SystemExit(1)
|
|
130
|
+
def announce() -> None:
|
|
131
|
+
"""Say where the app is, and open it, once it really answers: a link that leads to an error page is
|
|
132
|
+
worse than a few seconds of "Starting"."""
|
|
133
|
+
with working("Starting Papers…"):
|
|
134
|
+
ready = wait_until_up(args.host, args.port)
|
|
135
|
+
if setup.interactive():
|
|
136
|
+
setup.started(url, config.data_dir().resolve())
|
|
137
|
+
else:
|
|
138
|
+
print(f"Papers {__version__}: your library is in {config.data_dir()}", flush=True)
|
|
139
|
+
print(f"Open {url} (Ctrl+C to stop)", flush=True)
|
|
140
|
+
if not ready:
|
|
141
|
+
print(" It is taking long to start. If the page doesn't open yet, wait a moment and reload it.")
|
|
142
|
+
if not args.no_browser:
|
|
143
|
+
webbrowser.open(url)
|
|
144
|
+
threading.Thread(target=announce, daemon=True).start()
|
|
145
|
+
|
|
146
|
+
import uvicorn
|
|
147
|
+
uvicorn.run("papers.main:app", host=args.host, port=args.port, log_level="warning")
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
if __name__ == "__main__":
|
|
151
|
+
main()
|
|
@@ -25,6 +25,23 @@ def search_queries(goal: str) -> list[str]:
|
|
|
25
25
|
return ai.parse(prompt, Queries, effort="low").queries
|
|
26
26
|
|
|
27
27
|
|
|
28
|
+
class Landmarks(BaseModel):
|
|
29
|
+
titles: list[str]
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def landmark_titles(goal: str) -> list[str]:
|
|
33
|
+
"""The papers anyone starting on this goal reads first, by exact title. A keyword search often misses them
|
|
34
|
+
("attention mechanism" doesn't find "Attention Is All You Need"), so they're looked up by name. Each title is
|
|
35
|
+
checked against the paper databases afterwards, so one that doesn't exist is simply dropped."""
|
|
36
|
+
prompt = (
|
|
37
|
+
"A researcher describes what they want to understand. Name the papers a newcomer must read first: the "
|
|
38
|
+
"classic paper or papers that started the topic, and one good survey or tutorial if you know one. Give "
|
|
39
|
+
"each paper's exact published title and nothing else. At most 6, fewer is fine, and only papers you are "
|
|
40
|
+
f"sure exist. The goal may contain spelling mistakes; read past them.\n\n<goal>{goal}</goal>"
|
|
41
|
+
)
|
|
42
|
+
return [t.strip() for t in ai.parse(prompt, Landmarks, effort="low").titles if t.strip()][:6]
|
|
43
|
+
|
|
44
|
+
|
|
28
45
|
# Small (often local) models can't take a whole paper; Settings can cap how much of it is sent.
|
|
29
46
|
CONTEXT_CHARS = {"32k": 100_000, "8k": 24_000}
|
|
30
47
|
|
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
import io
|
|
2
|
+
import logging
|
|
2
3
|
import re
|
|
3
4
|
|
|
4
5
|
from pypdf import PdfReader
|
|
5
6
|
|
|
7
|
+
# pypdf reports every oddity in a PDF's fonts and structure as a warning, straight into the terminal the app was
|
|
8
|
+
# started from. They aren't something to act on: the text is still read. Real failures still show.
|
|
9
|
+
logging.getLogger("pypdf").setLevel(logging.ERROR)
|
|
10
|
+
|
|
6
11
|
|
|
7
12
|
def reflow(text: str) -> str:
|
|
8
13
|
"""Join lines wrapped by the PDF layout; keep breaks after sentences and short lines (headings)."""
|
|
@@ -64,32 +64,27 @@ def candidates(goal: str) -> list[dict]:
|
|
|
64
64
|
queries = llm.search_queries(goal)
|
|
65
65
|
except Exception:
|
|
66
66
|
queries = [goal]
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
except Exception:
|
|
73
|
-
continue
|
|
74
|
-
for p in results:
|
|
75
|
-
key = p["external_id"] or scholar.norm_title(p["title"])
|
|
76
|
-
if p["title"] and key not in seen:
|
|
77
|
-
seen.add(key)
|
|
78
|
-
found.append(p)
|
|
79
|
-
return found[:40]
|
|
67
|
+
try:
|
|
68
|
+
titles = llm.landmark_titles(goal) # the classics, which keyword searches tend to miss
|
|
69
|
+
except Exception:
|
|
70
|
+
titles = []
|
|
71
|
+
return scholar.gather([*queries, f"{queries[0]} survey"], titles, per_query=12, quiet=True)
|
|
80
72
|
|
|
81
73
|
|
|
82
74
|
def plan_with_ai(goal: str, found: list[dict]) -> Plan:
|
|
83
75
|
listing = "\n\n".join(
|
|
84
76
|
f"[{n}] {p['title']} ({p.get('year') or 'n.d.'}; {p.get('citations') or 'unknown'} citations;"
|
|
85
|
-
f" {'full text available' if p.get('pdf_url') else 'no free PDF'}
|
|
77
|
+
f" {'full text available' if p.get('pdf_url') else 'no free PDF'}"
|
|
78
|
+
f"{'; a classic of this topic' if p.get('landmark') else ''})\n{(p.get('abstract') or '')[:500]}"
|
|
86
79
|
for n, p in enumerate(found, 1))
|
|
87
80
|
prompt = (
|
|
88
81
|
"A researcher wants to reach this goal and needs a reading roadmap.\n\n"
|
|
89
82
|
f"<goal>{goal}</goal>\n\n<candidates>\n{listing}\n</candidates>\n\n"
|
|
90
83
|
"Pick the 5 to 10 candidates that best serve the goal and order them into 2 to 4 stages: the foundations a "
|
|
91
84
|
"newcomer needs first (a survey or the classic paper that started it), then the core methods, then the newest "
|
|
92
|
-
"or most advanced work.
|
|
85
|
+
"or most advanced work. Candidates marked \"a classic of this topic\" are the papers the field starts from: "
|
|
86
|
+
"put the ones that fit the goal in the first stage. Otherwise prefer well-cited and recent papers, and ones "
|
|
87
|
+
"with full text. Leave out papers that "
|
|
93
88
|
"are off-topic or repeat another pick. For each pick give its number, one plain sentence on why to read it "
|
|
94
89
|
"at that point (what it gives you), and about how many minutes a careful first read takes. Write a two-"
|
|
95
90
|
"sentence intro describing the path. Use plain words."
|
|
@@ -113,7 +108,7 @@ def build(topic_id: int, goal: str) -> dict:
|
|
|
113
108
|
stages.append({"title": st.title, "why": st.why, "items": items})
|
|
114
109
|
intro, by_ai = plan.intro, True
|
|
115
110
|
except Exception: # no AI (or it failed): the most cited results, as one stage
|
|
116
|
-
ranked = sorted(found, key=lambda p: -(p.get("citations") or 0))[:8]
|
|
111
|
+
ranked = sorted(found, key=lambda p: (not p.get("landmark"), -(p.get("citations") or 0)))[:8]
|
|
117
112
|
used = {found.index(p) + 1 for p in ranked}
|
|
118
113
|
stages = [{"title": "Most cited", "why": "Set up an AI model in Settings for a roadmap in reading order.",
|
|
119
114
|
"items": [{**p, "reason": "", "minutes": 0} for p in ranked]}] if ranked else []
|
|
@@ -62,13 +62,11 @@ def search_topic(topic_id: int):
|
|
|
62
62
|
queries = llm.search_queries(topic["goal"])
|
|
63
63
|
except Exception:
|
|
64
64
|
queries = [topic["goal"]]
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
found.append(p)
|
|
71
|
-
return found
|
|
65
|
+
try:
|
|
66
|
+
titles = llm.landmark_titles(topic["goal"]) # the classics first: keyword searches tend to miss them
|
|
67
|
+
except Exception:
|
|
68
|
+
titles = []
|
|
69
|
+
return scholar.gather(queries, titles)
|
|
72
70
|
|
|
73
71
|
|
|
74
72
|
# ---------- A reading roadmap: the best papers for the goal, in order ----------
|
|
@@ -135,6 +135,13 @@ def list_papers(topic_id: int | None = None, archived: bool = False):
|
|
|
135
135
|
return papers
|
|
136
136
|
|
|
137
137
|
|
|
138
|
+
@router.get("/with-pdf")
|
|
139
|
+
def papers_with_pdf() -> list[int]:
|
|
140
|
+
"""Which papers have their PDF by now. Covers waiting for a download ask this, then draw the first page."""
|
|
141
|
+
folder = db.pdf_path(0).parent
|
|
142
|
+
return sorted(int(f.stem) for f in folder.glob("*.pdf") if f.stem.isdigit()) if folder.is_dir() else []
|
|
143
|
+
|
|
144
|
+
|
|
138
145
|
@router.get("/{paper_id}")
|
|
139
146
|
def read_paper(paper_id: int):
|
|
140
147
|
return get_paper(paper_id)
|
|
@@ -11,13 +11,22 @@ API = "https://api.semanticscholar.org/graph/v1"
|
|
|
11
11
|
FIELDS = "title,authors,year,abstract,url,openAccessPdf,externalIds,citationCount"
|
|
12
12
|
|
|
13
13
|
|
|
14
|
+
_busy_until = 0.0 # Semantic Scholar said "too many requests" until then: go straight to arXiv meanwhile
|
|
15
|
+
|
|
16
|
+
|
|
14
17
|
def _get(path: str, **params) -> dict:
|
|
18
|
+
global _busy_until
|
|
15
19
|
headers = {"x-api-key": key} if (key := config.semantic_scholar_key()) else {}
|
|
16
|
-
|
|
20
|
+
if time.monotonic() < _busy_until:
|
|
21
|
+
raise httpx.HTTPError("Semantic Scholar is rate limited right now")
|
|
22
|
+
for attempt in range(3):
|
|
17
23
|
r = httpx.get(f"{API}{path}", params=params, headers=headers, timeout=30)
|
|
18
24
|
if r.status_code != 429:
|
|
19
25
|
break
|
|
20
|
-
|
|
26
|
+
if attempt < 2:
|
|
27
|
+
time.sleep(2 ** attempt) # the keyless API is rate limited; back off and retry
|
|
28
|
+
if r.status_code == 429: # still: don't make every following search wait for the same answer
|
|
29
|
+
_busy_until = time.monotonic() + 60
|
|
21
30
|
r.raise_for_status()
|
|
22
31
|
return r.json()
|
|
23
32
|
|
|
@@ -65,10 +74,17 @@ def parse_arxiv(xml: str) -> list[dict]:
|
|
|
65
74
|
return papers
|
|
66
75
|
|
|
67
76
|
|
|
68
|
-
def search_arxiv(query: str, limit: int = 10) -> list[dict]:
|
|
77
|
+
def search_arxiv(query: str, limit: int = 10, title: bool = False) -> list[dict]:
|
|
78
|
+
"""arXiv's own search. Every word must match (its default is any word, which returns papers about anything);
|
|
79
|
+
with `title`, the words are looked for as a phrase in the title."""
|
|
80
|
+
words = re.findall(r"[\w-]+", query)
|
|
81
|
+
if title:
|
|
82
|
+
terms = 'ti:"' + " ".join(words) + '"'
|
|
83
|
+
else:
|
|
84
|
+
terms = " AND ".join(f"all:{w}" for w in words[:8]) or f"all:{query}"
|
|
69
85
|
r = httpx.get(
|
|
70
86
|
"https://export.arxiv.org/api/query",
|
|
71
|
-
params={"search_query":
|
|
87
|
+
params={"search_query": terms, "max_results": limit, "sortBy": "relevance"},
|
|
72
88
|
timeout=30,
|
|
73
89
|
)
|
|
74
90
|
r.raise_for_status()
|
|
@@ -111,11 +127,39 @@ def norm_title(title: str) -> str:
|
|
|
111
127
|
|
|
112
128
|
def resolve(title: str) -> dict | None:
|
|
113
129
|
"""Find the search result that is this exact paper (by title), if any."""
|
|
130
|
+
exact = lambda results: next((r for r in results if norm_title(r["title"]) == norm_title(title)), None)
|
|
114
131
|
try:
|
|
115
|
-
|
|
116
|
-
|
|
132
|
+
if match := exact(search(title, limit=5)):
|
|
133
|
+
return match
|
|
134
|
+
return exact(search_arxiv(title, 5, title=True)) # the keyword search missed it: ask arXiv for the title
|
|
135
|
+
except (httpx.HTTPError, ET.ParseError):
|
|
117
136
|
return None
|
|
118
|
-
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
def gather(queries: list[str], titles: list[str] = (), per_query: int = 10, most: int = 40,
|
|
140
|
+
quiet: bool = False) -> list[dict]:
|
|
141
|
+
"""Candidates for a goal: the named papers first (each found by its exact title, marked `landmark`), then
|
|
142
|
+
what the keyword searches return, without repeats."""
|
|
143
|
+
seen, found = set(), []
|
|
144
|
+
|
|
145
|
+
def keep(p: dict) -> None:
|
|
146
|
+
key = norm_title(p["title"]) # the same paper comes back under different ids from the two sources
|
|
147
|
+
if p["title"] and key not in seen:
|
|
148
|
+
seen.add(key)
|
|
149
|
+
found.append(p)
|
|
150
|
+
for title in titles:
|
|
151
|
+
if match := resolve(title):
|
|
152
|
+
keep({**match, "landmark": True})
|
|
153
|
+
for query in queries:
|
|
154
|
+
try:
|
|
155
|
+
results = search(query, limit=per_query)
|
|
156
|
+
except (httpx.HTTPError, ET.ParseError):
|
|
157
|
+
if quiet: # one failed search shouldn't lose the others
|
|
158
|
+
continue
|
|
159
|
+
raise
|
|
160
|
+
for p in results:
|
|
161
|
+
keep(p)
|
|
162
|
+
return found[:most]
|
|
119
163
|
|
|
120
164
|
|
|
121
165
|
def references(external_id: str) -> list[dict]:
|