-
Notifications
You must be signed in to change notification settings - Fork 0
feat: added facets endpoint #737 #741
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
b0f369f
feat: added facets endpoint #737
MillenniumFalconMechanic 884e619
fix: added model docs #737
MillenniumFalconMechanic 0c94bc2
fix: linting #737
MillenniumFalconMechanic 017d065
fix: linting #737
MillenniumFalconMechanic 54abbf7
fix: updated README #737
MillenniumFalconMechanic File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,8 @@ | ||
| node_modules/ | ||
| lib/ | ||
| .vscode/ | ||
| .venv/ | ||
| __pycache__/ | ||
| *.pyc | ||
| .DS_Store | ||
| .idea |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| # Findable Backend (FastAPI) | ||
|
|
||
| This folder contains a minimal FastAPI backend that exposes a stubbed **query-to-facets** endpoint for experimentation and PoC work. | ||
|
|
||
| ## Requirements | ||
|
|
||
| - Python 3.9+ | ||
| - `pip` | ||
|
|
||
| ## Set up a Python virtual environment | ||
|
|
||
| From the repo root: | ||
|
|
||
| ```bash | ||
| python -m venv backend/.venv | ||
| source backend/.venv/bin/activate | ||
| python -m pip install --upgrade pip | ||
| ``` | ||
|
|
||
| ## Install dependencies | ||
|
|
||
| From the repo root: | ||
|
|
||
| ```bash | ||
| pip install -r backend/requirements.txt | ||
| ``` | ||
|
|
||
| ## Run the server | ||
|
|
||
| From the repo root: | ||
|
|
||
| ```bash | ||
| uvicorn backend.main:app --reload | ||
| ``` | ||
|
|
||
| The app will start on `http://127.0.0.1:8000` by default. | ||
|
|
||
| ## Format code | ||
|
|
||
| From the repo root: | ||
|
|
||
| ```bash | ||
| python -m black backend | ||
| ``` | ||
|
|
||
| ### Endpoint | ||
|
|
||
| - **Method:** `POST` | ||
| - **Path:** `/api/v0/facets` | ||
| - **Request body:** | ||
|
|
||
| ```json | ||
| { "query": "string" } | ||
| ``` | ||
|
|
||
| - **Example request:** | ||
|
|
||
| ```bash | ||
| curl -sS -X POST "http://127.0.0.1:8000/api/v0/facets" \ | ||
| -H "Content-Type: application/json" \ | ||
| -d '{ "query": "public bam files for latino patients with diabetes" }' | ||
| ``` | ||
|
|
||
| - **Response:** currently returns a **hard-coded** JSON structure representing resolved facets for the query. This is intentionally stubbed for PoC and will be replaced by a real implementation later. |
Empty file.
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| from fastapi import APIRouter | ||
|
|
||
| from backend.services.facets_service import compute_facets_from_query | ||
| from backend.services.models import FacetsResponse | ||
|
|
||
| from backend.controllers.models import FacetsRequest | ||
|
|
||
| router = APIRouter(prefix="/api/v0/facets", tags=["facets"]) | ||
|
|
||
|
|
||
| @router.post("") | ||
| def get_facets(payload: FacetsRequest) -> FacetsResponse: | ||
MillenniumFalconMechanic marked this conversation as resolved.
Show resolved
Hide resolved
MillenniumFalconMechanic marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| """ | ||
| Return a stubbed query-to-facets response for PoC purposes. | ||
| """ | ||
| return compute_facets_from_query() | ||
MillenniumFalconMechanic marked this conversation as resolved.
Show resolved
Hide resolved
MillenniumFalconMechanic marked this conversation as resolved.
Show resolved
Hide resolved
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| from pydantic import BaseModel | ||
|
|
||
|
|
||
| class FacetsRequest(BaseModel): | ||
MillenniumFalconMechanic marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| """ | ||
| Request model for the /api/v0/facets endpoint. | ||
MillenniumFalconMechanic marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| Attributes: | ||
| query (str): The search query string to retrieve facets for. | ||
| """ | ||
|
|
||
| query: str | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| from fastapi import FastAPI | ||
|
|
||
| from backend.controllers.facets_controller import router as facets_router | ||
|
|
||
|
|
||
| app = FastAPI(title="Findable API") | ||
|
|
||
| # Register controller(s) | ||
| app.include_router(facets_router) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| fastapi==0.115.0 | ||
| uvicorn[standard]==0.30.0 | ||
| pydantic==2.9.0 | ||
| black==24.10.0 |
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| from __future__ import annotations | ||
|
|
||
| from backend.services.models import FacetsResponse | ||
|
|
||
|
|
||
| def compute_facets_from_query() -> FacetsResponse: | ||
MillenniumFalconMechanic marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| """Return a stubbed query-to-facets response for PoC purposes. | ||
|
|
||
| This function will later be replaced by a real implementation that uses | ||
| LLM-backed intent parsing and facet resolution. | ||
MillenniumFalconMechanic marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| """ | ||
|
|
||
| return FacetsResponse.model_validate( | ||
| { | ||
| "query": "public bam files for latino foobar patients with diabetes or foobaz", | ||
| "facets": [ | ||
| { | ||
| "facet": "Access", | ||
| "selectedValues": [ | ||
| { | ||
| "term": "Granted", | ||
| "mention": "public", | ||
| } | ||
| ], | ||
| }, | ||
| { | ||
| "facet": "Diagnosis", | ||
| "selectedValues": [ | ||
| { | ||
| "term": "MONDO:0005015", | ||
| "mention": "diabetes", # Mention resolved but value does not exist in dev | ||
| }, | ||
| { | ||
| "term": "unknown", | ||
| "mention": "foobaz", # Mention resolved to a disease but does not match a known term | ||
| }, | ||
| ], | ||
| }, | ||
| { | ||
| "facet": "File Format", | ||
| "selectedValues": [ | ||
| { | ||
| "term": ".bam", | ||
| "mention": "bam", | ||
| } | ||
| ], | ||
| }, | ||
| { | ||
| "facet": "Reported Ethnicity", | ||
| "selectedValues": [ | ||
| { | ||
| "term": "Hispanic or Latino", | ||
| "mention": "latino", | ||
| }, | ||
| ], | ||
| }, | ||
| { | ||
| "facet": "unknown", | ||
| "selectedValues": [ | ||
| { | ||
| "term": "unknown", | ||
| "mention": "foobar", # Mention not resolved to a facet or facet term | ||
| } | ||
| ], | ||
| }, | ||
| ], | ||
| } | ||
| ) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| from pydantic import BaseModel | ||
|
|
||
|
|
||
| # Model of a selected facet value and its mention (that is, the original query text that resolved to the value). | ||
| class SelectedValue(BaseModel): | ||
| """ | ||
| Represents a selected facet value and its mention in the original query text. | ||
|
|
||
| Attributes: | ||
| term (str): The resolved facet value. | ||
| mention (str): The original query text that resolved to the value. | ||
| """ | ||
|
|
||
| term: str | ||
| mention: str | ||
|
|
||
|
|
||
| # Model of a selected facet and its resolved values. | ||
| class FacetSelection(BaseModel): | ||
| """ | ||
| Represents a selected facet and its resolved values. | ||
|
|
||
| Attributes: | ||
| facet (str): The name of the facet. | ||
| selectedValues (list[SelectedValue]): The list of selected values for this facet. | ||
| """ | ||
|
|
||
| facet: str | ||
| selectedValues: list[SelectedValue] | ||
MillenniumFalconMechanic marked this conversation as resolved.
Show resolved
Hide resolved
MillenniumFalconMechanic marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
|
|
||
| # Model of the selected facets for a given query, resolved and normalized via LLM. | ||
| class FacetsResponse(BaseModel): | ||
| """ | ||
| Represents the selected facets for a given query, resolved and normalized via LLM. | ||
|
|
||
| Attributes: | ||
| query (str): The original query string. | ||
| facets (list[FacetSelection]): The list of selected facets and their values. | ||
| """ | ||
|
|
||
| query: str | ||
| facets: list[FacetSelection] | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.