Spaces:
Running on Zero
Running on Zero
Commit ·
c64eff0
1
Parent(s): fb830e1
Switch from mailto to API key
Browse files
app.py
CHANGED
|
@@ -173,7 +173,7 @@ def get_index(dir: Path, search_time_s: float) -> Dataset:
|
|
| 173 |
return index
|
| 174 |
|
| 175 |
|
| 176 |
-
def execute_request(ids: list[str],
|
| 177 |
if len(ids) > 100:
|
| 178 |
raise ValueError("querying /works endpoint with more than 100 works")
|
| 179 |
|
|
@@ -181,8 +181,8 @@ def execute_request(ids: list[str], mailto: str | None) -> list[Work]:
|
|
| 181 |
search_filter = f"openalex_id:{'|'.join(ids)}"
|
| 182 |
search_select = ",".join(["id"] + Work.get_raw_fields())
|
| 183 |
params = {"filter": search_filter, "select": search_select, "per-page": 100}
|
| 184 |
-
if
|
| 185 |
-
params["
|
| 186 |
response = requests.get("https://api.openalex.org/works", params)
|
| 187 |
response.raise_for_status()
|
| 188 |
|
|
@@ -278,7 +278,7 @@ def main():
|
|
| 278 |
repo = get_env_var("REPO", str)
|
| 279 |
search_time_s = get_env_var("SEARCH_TIME_S", float, default=1)
|
| 280 |
k = get_env_var("K", int, default=20) # TODO: can't go higher than 20 yet
|
| 281 |
-
|
| 282 |
|
| 283 |
if dir is None: # acquire the index if it's not local
|
| 284 |
if repo is None:
|
|
@@ -344,7 +344,7 @@ def main():
|
|
| 344 |
distances, faiss_ids = index.search("embedding", query_embedding, k * 2)
|
| 345 |
|
| 346 |
openalex_ids = index[faiss_ids]["id"]
|
| 347 |
-
works = execute_request(openalex_ids,
|
| 348 |
|
| 349 |
# TODO: Some IDs existed in OpenAlex v1 but not v2. Until the index is
|
| 350 |
# updated, query double the works and cut down to k (best-effort!).
|
|
|
|
| 173 |
return index
|
| 174 |
|
| 175 |
|
| 176 |
+
def execute_request(ids: list[str], api_key: str | None) -> list[Work]:
|
| 177 |
if len(ids) > 100:
|
| 178 |
raise ValueError("querying /works endpoint with more than 100 works")
|
| 179 |
|
|
|
|
| 181 |
search_filter = f"openalex_id:{'|'.join(ids)}"
|
| 182 |
search_select = ",".join(["id"] + Work.get_raw_fields())
|
| 183 |
params = {"filter": search_filter, "select": search_select, "per-page": 100}
|
| 184 |
+
if api_key is not None:
|
| 185 |
+
params["api_key"] = api_key
|
| 186 |
response = requests.get("https://api.openalex.org/works", params)
|
| 187 |
response.raise_for_status()
|
| 188 |
|
|
|
|
| 278 |
repo = get_env_var("REPO", str)
|
| 279 |
search_time_s = get_env_var("SEARCH_TIME_S", float, default=1)
|
| 280 |
k = get_env_var("K", int, default=20) # TODO: can't go higher than 20 yet
|
| 281 |
+
api_key = get_env_var("API_KEY", str, None)
|
| 282 |
|
| 283 |
if dir is None: # acquire the index if it's not local
|
| 284 |
if repo is None:
|
|
|
|
| 344 |
distances, faiss_ids = index.search("embedding", query_embedding, k * 2)
|
| 345 |
|
| 346 |
openalex_ids = index[faiss_ids]["id"]
|
| 347 |
+
works = execute_request(openalex_ids, api_key)
|
| 348 |
|
| 349 |
# TODO: Some IDs existed in OpenAlex v1 but not v2. Until the index is
|
| 350 |
# updated, query double the works and cut down to k (best-effort!).
|