Skip to content

Commit 3fb1c3a

Browse files
Merge pull request #7 from MITLibraries/initial-setup
Completes initial setup
2 parents 8104a76 + 14e10d4 commit 3fb1c3a

File tree

3 files changed

+30
-34
lines changed

3 files changed

+30
-34
lines changed

README.md

Lines changed: 27 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,38 @@
11
# TACOS citation detector
22

3-
A lambda to apply a pre-trained algorithm to predict whether a given search string is in the form of a citation.
4-
5-
## Repo Setup (delete this section and above after initial function setup)
6-
7-
1. Rename "my_function" to the desired initial function name across the repo. (May be helpful to do a project-wide find-and-replace).
8-
2. Update Python version if needed (note: AWS lambda cannot currently support versions higher than 3.9).
9-
3. Install all dependencies with `make install` to create initial Pipfile.lock with latest dependency versions.
10-
4. Add initial function description to README and update initial required ENV variable documentation as needed.
11-
5. Update license if needed (check app-specific dependencies for licensing terms).
12-
6. Check Github repository settings:
13-
- Confirm repo branch protection settings are correct (see [dev docs](https://mitlibraries.github.io/guides/basics/github.html) for details)
14-
- Confirm that all of the following are enabled in the repo's code security and analysis settings:
15-
- Dependabot alerts
16-
- Dependabot security updates
17-
- Secret scanning
18-
7. Create a Sentry project for the app if needed (we want this for most apps):
19-
- Send initial exceptions to Sentry project for dev, stage, and prod environments to create them.
20-
- Create an alert for the prod environment only, with notifications sent to the appropriate team(s).
21-
- If *not* using Sentry, delete Sentry configuration from my_function.py and test_my_function_.py, and remove sentry_sdk from project dependencies.
22-
23-
# predict
24-
25-
This function will perform the following work:
3+
A lambda to apply a pre-trained algorithm to predict whether a given search string is in the form of a citation. This
4+
function will perform the following work:
265

276
1. Receives a set of parameters (submitted to the lambda via POST)
287
2. Loads a pickle file containing a pre-trained machine learning model.
298
3. Submits the parameters to the model to generate a binary prediction.
309
4. Returns the result of that prediction.
3110

11+
This lambda's operation is placed in context of our larger discovery ecosystem in the following diagram. The lambda is
12+
responsible for the shaded region.
13+
14+
```mermaid
15+
sequenceDiagram
16+
participant User
17+
participant UI
18+
participant Tacos
19+
box PaleVioletRed Citation detector
20+
participant Lambda
21+
participant S3
22+
end
23+
User->>UI: "popcorn"
24+
UI->>Tacos: "popcorn"
25+
Tacos-->Tacos: Extract features from "popcorn"
26+
Tacos-->Tacos: Load Lambda URL from Config Vars
27+
Tacos->>Lambda: {"features": {...}}
28+
Lambda-->Lambda: Load S3 address from ENV
29+
Lambda-->Lambda: Load default model filename "knn" from ENV
30+
Lambda-->>S3: Request "knn" model
31+
S3-->>Lambda: pkl file
32+
Lambda-->Lambda: Generate prediction
33+
Lambda->>Tacos: {"prediction": false}
34+
```
35+
3236
## Development
3337

3438
- To preview a list of available Makefile commands: `make help`
@@ -65,14 +69,6 @@ This function will perform the following work:
6569
"You have successfully called this lambda!"
6670
```
6771

68-
## Running a Specific Handler Locally with Docker
69-
70-
If this repo contains multiple lambda functions, you can call any handler you copy into the container (see Dockerfile) by name as part of the `docker run` command:
71-
72-
```bash
73-
docker run -p 9000:8080 predict:latest lambdas.<a-different-module>.lambda_handler
74-
```
75-
7672
## Environment Variables
7773

7874
### Required

lambdas/predict.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
logger.info("No Sentry DSN found, exceptions will not be sent to Sentry")
2424

2525

26-
def lambda_handler(event: dict) -> str:
26+
def lambda_handler(event: dict, _context: dict) -> str:
2727
if not os.getenv("WORKSPACE"):
2828
unset_workspace_error_message = "Required env variable WORKSPACE is not set"
2929
raise RuntimeError(unset_workspace_error_message)

tests/test_predict.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ def test_predict_doesnt_configure_sentry_if_dsn_not_present(caplog, monkeypatch)
2222
def test_lambda_handler_missing_workspace_env_raises_error(monkeypatch):
2323
monkeypatch.delenv("WORKSPACE", raising=False)
2424
with pytest.raises(RuntimeError) as error:
25-
predict.lambda_handler({})
25+
predict.lambda_handler({}, {})
2626
assert "Required env variable WORKSPACE is not set" in str(error)
2727

2828

2929
def test_predict():
30-
assert predict.lambda_handler({}) == "You have successfully called this lambda!"
30+
assert predict.lambda_handler({}, {}) == "You have successfully called this lambda!"

0 commit comments

Comments
 (0)