Spaces:
Running
Running
update endpoint
Browse files1067 unmodified lines106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931 unmodified line109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511563 unmodified lines1160116111621163116411651166116711681169117011711172117311741067 unmodified lines<p class="subtitle">Semantic search over Mathlib. Send a query, get back ranked Lean declarations.</p><h2>Endpoint</h2><p><span class="badge method">POST</span> <code>https://bxrituxuhpc70w8w.us-east-1.aws.endpoints.huggingface.cloud</code></p><p>The service runs on a Hugging Face Inference Endpoint. Every request needs a bearer token that has access to the endpoint. Send a JSON body and set these headers:</p><pre><code>Accept: application/jsonContent-Type: application/jsonAuthorization: Bearer YOUR_HF_TOKEN</code></pre><h2>Request body</h2><table><tr><th>Field</th><th>Type</th><th>Description</th></tr><tr><td><code>inputs</code></td><td>string</td><td>Required. Your query text.</td></tr><tr><td><code>top_k</code></td><td>int</td><td>How many results to return. Recommended. Example: 5.</td></tr><tr><td><code>version</code></td><td>string</td><td>Mathlib index to search. One of v4.19.0, v4.24.0, v4.28.0. Pick the one that matches your project so the names it returns exist in your build.</td></tr></table><h3>What <code>inputs</code> can be</h3><ul><li><b>Informal statement</b>: a natural-language version of a Lean statement.</li><li><b>Question</b>: a free-form question about Lean or Mathlib.</li><li><b>Proof state</b>: a pasted goal state, optionally with what you want to do next.</li><li><b>Lean fragment</b>: a rough snippet or draft of the declaration you want.</li></ul><pre><code>{"inputs": "continuous function on a compact set is bounded above","top_k": 5,1 unmodified line}</code></pre><h2>Response</h2><p>A JSON object with a <code>results</code> array, ordered from most to least relevant.</p><pre><code>{"results": [{"formal_name": "IsCompact.bddAbove_image","informal_name": "A continuous function on a compact set is bounded above","kind": "theorem","type": "...","informal_description": "...","path": "Mathlib/Topology/Order/Compact","score": 0.87}]}</code></pre><table><tr><th>Field</th><th>Meaning</th></tr><tr><td><code>formal_name</code></td><td>The Lean declaration name you use in code.</td></tr><tr><td><code>informal_name</code></td><td>Short natural-language name.</td></tr><tr><td><code>kind</code></td><td>Declaration kind: theorem, lemma, def, structure, instance, and so on.</td></tr><tr><td><code>type</code></td><td>The Lean type signature.</td></tr><tr><td><code>informal_description</code></td><td>Natural-language description of the declaration.</td></tr><tr><td><code>path</code></td><td>Module path in slash form. The Lean file is <code><path>.lean</code> in mathlib4.</td></tr><tr><td><code>score</code></td><td>Relevance score. Higher means a closer match.</td></tr></table><p>Build a link to the mathlib repo from <code>path</code> and <code>version</code>:</p><pre><code>https://github.com/leanprover-community/mathlib4/tree/v4.28.0/Mathlib/Topology/Order/Compact.lean</code></pre><h2>Python example</h2><pre><code>import requestsENDPOINT = "https://bxrituxuhpc70w8w.us-east-1.aws.endpoints.huggingface.cloud"HF_TOKEN = "hf_your_token_here" # a token with access to the endpointdef lean_finder(query, top_k=5, version="v4.28.0"):headers = {"Accept": "application/json","Content-Type": "application/json","Authorization": f"Bearer {HF_TOKEN}",}payload = {"inputs": query,"top_k": top_k,"version": version,}resp = requests.post(ENDPOINT, json=payload, headers=headers, timeout=60)resp.raise_for_status()return resp.json().get("results", [])for r in lean_finder("continuous function on a compact set is bounded above"):print(round(r["score"], 3), r["formal_name"])print(" ", r["informal_name"])print(" ", r["type"])</code></pre><h2>Handling cold starts</h2><p>The endpoint can scale to zero when idle. The first call after an idle period may fail or return a 503 while the model loads, which takes about 1 to 2 minutes. Retry until it responds.</p><pre><code>import time, requestsdef lean_finder_retry(query, max_wait=300, **kwargs):start = time.time()3 unmodified linesexcept requests.exceptions.RequestException:if time.time() - start > max_wait:raisetime.sleep(2) # endpoint is warming up, try again</code></pre><div class="note">A 401 or 403 that keeps repeating means the token is missing or lacks access to the endpoint, not a cold start. Check your token first.</div><h2>curl example</h2><pre><code>curl https://bxrituxuhpc70w8w.us-east-1.aws.endpoints.huggingface.cloud \-X POST \-H "Authorization: Bearer hf_your_token_here" \-H "Content-Type: application/json" \-d '{"inputs": "continuous function on a compact set is bounded above", "top_k": 5, "version": "v4.28.0"}'</code></pre><div class="foot">Lean Finder | Semantic Search for Mathlib | <a href="https://arxiv.org/abs/2510.15940" target="_blank" rel="noopener">Paper</a> | <a href="https://github.com/delta-lab-ai/lean-finder" target="_blank" rel="noopener">Code</a> | <a href="https://huggingface.co/delta-lab-ai/lean-finder" target="_blank" rel="noopener">Model</a></div></div>1067 unmodified lines106810691070107110721073107410751076107710781079108010811082108310841 unmodified line108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011413 unmodified lines11451146114711481149115011511067 unmodified lines<p class="subtitle">Semantic search over Mathlib. Send a query, get back ranked Lean declarations.</p><h2>Endpoint</h2><p><span class="badge method">POST</span> <code>https://lean-lsp-proxy.leanfinder.workers.dev</code></p><p>No API key needed. Send a JSON body with <code>Content-Type: application/json</code>.</p><h2>Request body</h2><table><tr><th>Field</th><th>Type</th><th>Description</th></tr><tr><td><code>inputs</code></td><td>string</td><td>Required. Your query text.</td></tr><tr><td><code>top_k</code></td><td>int</td><td>Number of results. Default 10.</td></tr><tr><td><code>version</code></td><td>string</td><td>Mathlib index to search: <code>v4.19.0</code>, <code>v4.24.0</code> or <code>v4.28.0</code>. Match your project so returned names exist in your build.</td></tr></table><p><code>inputs</code> can be an informal statement, a question about Lean or Mathlib, a pasted proof state, or a rough Lean snippet.</p><pre><code>{"inputs": "continuous function on a compact set is bounded above","top_k": 5,1 unmodified line}</code></pre><h2>Response</h2><p>A <code>results</code> array, most relevant first.</p><pre><code>{"results": [{"formal_name": "IsCompact.bddAbove_image","informal_name": "Continuous Image of Compact Set is Bounded Above ...","kind": "theorem","type": "...","informal_description": "...","path": "Mathlib/Topology/Order/Compact","url": "https://leanprover-community.github.io/mathlib4_docs/find/?pattern=IsCompact.bddAbove_image#doc","score": 0.876}]}</code></pre><table><tr><th>Field</th><th>Meaning</th></tr><tr><td><code>formal_name</code></td><td>Lean declaration name.</td></tr><tr><td><code>informal_name</code></td><td>Short natural-language name.</td></tr><tr><td><code>kind</code></td><td>theorem, def, structure, instance, ...</td></tr><tr><td><code>type</code></td><td>Lean type signature.</td></tr><tr><td><code>informal_description</code></td><td>Natural-language description.</td></tr><tr><td><code>path</code></td><td>Module path; the file is <code><path>.lean</code> in mathlib4.</td></tr><tr><td><code>url</code></td><td>Link to the declaration in the Mathlib docs.</td></tr><tr><td><code>score</code></td><td>Relevance score. Higher is better.</td></tr></table><div class="note">Errors come back as <code>{"error": "..."}</code>. A missing <code>inputs</code> returns HTTP 400; an unknown <code>version</code> returns HTTP 200 with an <code>error</code> key, so check for it.</div><h2>curl</h2><pre><code>curl https://lean-lsp-proxy.leanfinder.workers.dev \-H "Content-Type: application/json" \-d '{"inputs": "continuous function on a compact set is bounded above", "top_k": 5, "version": "v4.28.0"}'</code></pre><h2>Python</h2><pre><code>import requestsENDPOINT = "https://lean-lsp-proxy.leanfinder.workers.dev"def lean_finder(query, top_k=5, version="v4.28.0"):payload = {"inputs": query, "top_k": top_k, "version": version}resp = requests.post(ENDPOINT, json=payload, timeout=60)resp.raise_for_status()return resp.json().get("results", [])for r in lean_finder("continuous function on a compact set is bounded above"):print(round(r["score"], 3), r["formal_name"])</code></pre><h2>Cold starts</h2><p>The backend scales to zero when idle. The first request after a quiet period may fail or return 503 for 1 to 2 minutes while the model loads. Retry until it responds.</p><pre><code>import timedef lean_finder_retry(query, max_wait=300, **kwargs):start = time.time()3 unmodified linesexcept requests.exceptions.RequestException:if time.time() - start > max_wait:raisetime.sleep(5)</code></pre><div class="foot">Lean Finder | Semantic Search for Mathlib | <a href="https://arxiv.org/abs/2510.15940" target="_blank" rel="noopener">Paper</a> | <a href="https://github.com/delta-lab-ai/lean-finder" target="_blank" rel="noopener">Code</a> | <a href="https://huggingface.co/delta-lab-ai/lean-finder" target="_blank" rel="noopener">Model</a></div></div>
app.py+31-54