In this project we will deploy a simple rust fuction which uses an LLM from huggingface to continue the text given to it. The function will be deployed as a lambda function on AWS.
Make sure you have the following installed:
- Create a new rust project using cargo lambda
cargo lambda new <project-name>
-
Use the desired model from huggingface, in this case, we used a rustformers/pythia-ggml model. don't forget to add the correct path to the model in the file
-
Build the rust code as required, in this case we take in the query from the user and complete it using the model. In case there is no query, we use a default query to start the completion.
-
Test the code locally using the following command
cargo lambda watch
-
We can use services like postman to send and receive the requests from the lambda function.
-
Once the functionality is working as expected, make the production build
-
Do docker init in the project directory
-
modify the Dockerfile as required
-
verify that the image is created either using the docker images command or viewing in the docker desktop
We will use AWS ECR service to store our docker image so that we can use it to build the lambda function.
- Create a new private repository in ECR
- once the repository is created, click on the "view push commands" button to get the commands to push the image to the repository
- Run the commands in the terminal to push the image to the repository
- Verify that the image is pushed to the repository by checking the repository in the AWS console
- copy the URI of the image to use it in the lambda function
- Go to AWS lambda and create a new function
- select the container image as the source
- paste the URI of the image we copied earlier in the repository URI
- select the other settings as required
- Create the function
- Once the function is created, goto configurations and enable function URL
- The lambda function is now ready to be used
With no query, uses the default starter:
Github Actions is used to automatically perform functions like Linting, formatting etc. whenever there is an update in the repository.