-
Notifications
You must be signed in to change notification settings - Fork 178
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
AUTH-421 Fargate FastAPI container #15287
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
190a95d
feat(ai-server): fastapi and fargate
y3rsh 803d050
Merge branch 'edge' into AUTH-421-fastapi
y3rsh 47708c6
Merge branch 'edge' into AUTH-421-fastapi
y3rsh 9ce53c7
undo accidental change on conflict fix
y3rsh e411ecb
fix(ai-server): logging and feedback
y3rsh 738d649
Merge branch 'edge' into AUTH-421-fastapi
y3rsh 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
There are no files selected for viewing
This file contains 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 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,9 +1,13 @@ | ||
.env | ||
*.env | ||
results | ||
package | ||
function.zip | ||
requirements.txt | ||
test.env | ||
cached_token.txt | ||
tests/helpers/cached_token.txt | ||
tests/helpers/prod_cached_token.txt | ||
tests/helpers/staging_cached_token.txt | ||
tests/helpers/*_cached_token.txt | ||
tests/helpers/test.env | ||
tests/helpers/*.env |
This file contains 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,13 +1,16 @@ | ||
FROM --platform=linux/amd64 public.ecr.aws/lambda/python:3.12 | ||
FROM --platform=linux/amd64 python:3.12-slim | ||
|
||
COPY --from=public.ecr.aws/datadog/lambda-extension:57 /opt/. /opt/ | ||
ENV PYTHONUNBUFFERED True | ||
ENV DOCKER_RUNNING True | ||
|
||
WORKDIR ${LAMBDA_TASK_ROOT} | ||
WORKDIR /code | ||
|
||
COPY requirements.txt . | ||
COPY ./requirements.txt /code/requirements.txt | ||
|
||
RUN pip install -r requirements.txt | ||
RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt | ||
|
||
COPY api ${LAMBDA_TASK_ROOT}/api | ||
COPY ./api /code/api | ||
|
||
CMD [ "datadog_lambda.handler.handler" ] | ||
EXPOSE 8000 | ||
|
||
CMD ["ddtrace-run", "uvicorn", "api.handler.fast:app", "--proxy-headers", "--host", "0.0.0.0", "--port", "8000", "--timeout-keep-alive", "190", "--workers", "3"] |
This file contains 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 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
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains 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 |
---|---|---|
|
@@ -20,42 +20,41 @@ The Opentrons AI application's server. | |
1. This will create a `.python-version` file in this directory | ||
1. select the node version with `nvs` or `nvm` currently 18.19\* | ||
1. Install pipenv and python dependencies `make setup` | ||
1. to build and deploy you must have | ||
1. AWS credentials and the right roles | ||
1. docker installed | ||
|
||
## For building and deploying | ||
|
||
1. AWS credentials and config | ||
1. docker | ||
|
||
## Install a dev dependency | ||
|
||
`python -m pipenv install pytest==8.2.0 --dev` | ||
|
||
## Install a production dependency | ||
|
||
`python -m pipenv install openai==1.25.1` | ||
`python -m pipenv install openai==1.30.4` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should not keep changing the version please. Reproducibility is already difficult due to GPT model itself. |
||
|
||
## Lambda Code Organizations and Separation of Concerns | ||
## FastAPI Code Organization and Separation of Concerns | ||
|
||
- handler | ||
- the lambda handler | ||
- the router and request/response handling | ||
- domain | ||
- the business logic | ||
- business logic | ||
- integration | ||
- the integration with other services | ||
- integration with other services | ||
|
||
## Dev process | ||
|
||
1. Make your changes | ||
1. Fix what can be automatically then lent and unit test like CI will `make pre-commit` | ||
1. Fix what can be automatically then lint and unit test like CI will `make pre-commit` | ||
1. `make pre-commit` passes | ||
1. deploy to sandbox `make deploy test-live ENV=sandbox AWS_PROFILE=the-profile` | ||
|
||
## Custom runtime | ||
|
||
- Due to the size requirements of `llama-index` and our data we switched to a custom runtime | ||
- This also allows us to use HTTP streaming | ||
- The runtime is defined in the `Dockerfile` | ||
- deploy.py contains the steps to | ||
1. build the container image | ||
1. tag the container image (currently uses the epoch until versioning in place) | ||
1. log into and push to the correct ECR | ||
1. create a new lambda version against the new image | ||
1. await the function to be ready | ||
1. run locally `make run` this runs the FastAPI server directly at localhost:8000 | ||
1. this watches for changes and restarts the server | ||
1. test locally `make live-test` (ENV=local is the default in the Makefile) | ||
1. use the live client `make live-client` | ||
|
||
## ECS Fargate | ||
|
||
- Our first version of this service is a long running POST that may take from 1-3 minutes to complete | ||
- This forces us to use CloudFront(Max 180) + Load Balancer + ECS Fargate FastAPI container | ||
- An AWS service ticket is needed to increase the max CloudFront response time from 60 to 180 seconds |
This file contains 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 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
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
better to stick to 1.25.1, AI projects are updated fast. it may damage things unexpectedly.