File tree Expand file tree Collapse file tree 20 files changed +498
-16
lines changed Expand file tree Collapse file tree 20 files changed +498
-16
lines changed Original file line number Diff line number Diff line change @@ -3,7 +3,7 @@ default_language_version:
3
3
python : python3.11
4
4
repos :
5
5
- repo : https://github.com/codespell-project/codespell
6
- rev : v2.3.0
6
+ rev : v2.4.1
7
7
hooks :
8
8
- id : codespell
9
9
args : ["--ignore-words=codespell.txt"]
29
29
hooks :
30
30
- id : flake8
31
31
- repo : https://github.com/PyCQA/isort
32
- rev : 5.13.2
32
+ rev : 6.0.0
33
33
hooks :
34
34
- id : isort
35
35
args : ["--settings-path=pyproject.toml"]
41
41
language : script
42
42
types : [python]
43
43
- repo : https://github.com/PyCQA/bandit
44
- rev : 1.7.10
44
+ rev : 1.8.2
45
45
hooks :
46
46
- id : bandit
47
47
args : ["-ll"]
@@ -69,14 +69,14 @@ repos:
69
69
- id : check-merge-conflict
70
70
- id : debug-statements
71
71
- repo : https://github.com/gruntwork-io/pre-commit
72
- rev : v0.1.24 # Get the latest from: https://github.com/gruntwork-io/pre-commit/releases
72
+ rev : v0.1.25 # Get the latest from: https://github.com/gruntwork-io/pre-commit/releases
73
73
hooks :
74
74
- id : terraform-fmt
75
75
- id : helmlint
76
76
- id : terraform-validate
77
77
- id : tflint
78
78
- repo : https://github.com/alessandrojcm/commitlint-pre-commit-hook
79
- rev : v9.18 .0
79
+ rev : v9.20 .0
80
80
hooks :
81
81
- id : commitlint
82
82
stages : [commit-msg]
Original file line number Diff line number Diff line change
1
+ # ------------------------------------------------------------------------------
2
+ # written by: Lawrence McDaniel
3
+ # https://lawrencemcdaniel.com/
4
+ #
5
+ # date: feb-2024
6
+ #
7
+ # usage: build and upload a Docker image to AWS Elastic Container Registry (ECR)
8
+ # ------------------------------------------------------------------------------
9
+ locals {
10
+ ecr_repo = " chat_api"
11
+ ecr_source_directory = " ${ path . module } ../python/openai_api/"
12
+
13
+ ecr_build_path = " ${ path . module } /ecr_build"
14
+ ecr_build_script = " ${ local . ecr_build_path } /build.sh"
15
+ }
16
+
17
+ resource "aws_ecr_repository" "chat_api" {
18
+ name = local. ecr_repo
19
+ image_tag_mutability = " IMMUTABLE"
20
+
21
+ image_scanning_configuration {
22
+ scan_on_push = true
23
+ }
24
+ tags = var. tags
25
+
26
+ }
27
+
28
+ # ##############################################################################
29
+ # Python package
30
+ # ##############################################################################
31
+ resource "null_resource" "chat_api" {
32
+ triggers = {
33
+ always_redeploy = timestamp ()
34
+ }
35
+
36
+ provisioner "local-exec" {
37
+ interpreter = [" /bin/bash" ]
38
+ command = local. ecr_build_script
39
+
40
+ environment = {
41
+ BUILD_PATH = local.ecr_build_path
42
+ CONTAINER_NAME = local.ecr_repo
43
+ AWS_REGION = var.aws_region
44
+ AWS_ACCOUNT_ID = var.aws_account_id
45
+ }
46
+ }
47
+
48
+ depends_on = [aws_ecr_repository . chat_api ]
49
+ }
Original file line number Diff line number Diff line change
1
+ * .zip
2
+ venv
3
+ archive
Original file line number Diff line number Diff line change
1
+ # Use an AWS Lambda Python runtime as the base image
2
+ # https://hub.docker.com/r/amazon/aws-lambda-python
3
+ # ------------------------------------------------------
4
+ FROM --platform=linux/amd64 python:3.11-buster
5
+
6
+ WORKDIR /app
7
+
8
+ COPY openai_api .
9
+ COPY requirements.txt .
10
+
11
+ RUN apt-get update && apt-get install -y zip
12
+ RUN pip install -r requirements.txt
13
+
14
+ CMD ["python" , "service_controller.py" ]
15
+
16
+ EXPOSE 8000
17
+
18
+ ENV DEBUG_MODE=False
19
+ ARG OPENAI_API_KEY
20
+ ARG PINECONE_API_KEY
21
+ ARG PINECONE_ENVIRONMENT
22
+ ARG GOOGLE_MAPS_API_KEY
Original file line number Diff line number Diff line change
1
+ # AWS Lambda Layer for OpenAI/Langchain Lambdas
2
+
3
+ This layer contains the combined pip requirements for both lambda_langchain and lambda_openai_v2.
Original file line number Diff line number Diff line change
1
+ #! /bin/bash
2
+ # ------------------------------------------------------------------------------
3
+ # written by: Lawrence McDaniel
4
+ # https://lawrencemcdaniel.com/
5
+ #
6
+ # date: nov-2023
7
+ #
8
+ # usage: Lambda Python packaging tool.
9
+ # Called by Terraform "null_resource". Copies python
10
+ # module(s) plus any requirements to a dedicated folder so that
11
+ # it can be archived to a zip file for upload to
12
+ # AWS Lambda by Terraform.
13
+ # ------------------------------------------------------------------------------
14
+ cd $BUILD_PATH
15
+
16
+ pwd
17
+ cp -R ../../python/openai_api/ ./openai_api
18
+
19
+ # Step 1: Build your Docker image
20
+ docker build -t $CONTAINER_NAME .
21
+
22
+ # Step 2: Authenticate Docker to your Amazon ECR registry
23
+ aws ecr get-login-password --region $AWS_REGION | docker login --username AWS --password-stdin $AWS_ACCOUNT_ID .dkr.ecr.$AWS_REGION .amazonaws.com
24
+
25
+ # Step 3: Tag your Docker image
26
+ docker tag chat_api:latest $AWS_ACCOUNT_ID .dkr.ecr.$AWS_REGION .amazonaws.com/chat_api:latest
27
+
28
+ # Step 4: Push your Docker image
29
+ docker push $AWS_ACCOUNT_ID .dkr.ecr.$AWS_REGION .amazonaws.com/chat_api:latest
30
+
31
+ rm -r ./openai_api
Original file line number Diff line number Diff line change
1
+ # -----------------------------------------------------------------------------
2
+ # written by: Lawrence McDaniel
3
+ # https://lawrencemcdaniel.com
4
+ #
5
+ # usage: Python requirements for AWS Lambda functions. Create a virtual
6
+ # environment in the root of this repository named `venv`. Terraform
7
+ # modules will look for and include these requirements in the zip
8
+ # packages for each Python-based Lambda function.
9
+ # -----------------------------------------------------------------------------
10
+
11
+ # misc
12
+ # ------------
13
+ boto3 == 1.34.25
14
+ botocore == 1.34.29
15
+ requests == 2.31.0
16
+
17
+ # Lambda layer: openai
18
+ # ------------
19
+ openai == 1.10.0
20
+ pyyaml == 6.0.1
21
+
22
+ # Lambda layer: common
23
+ # ------------
24
+ python-dotenv == 1.0.1
25
+ pydantic == 2.5.3
26
+ pydantic-settings == 2.1.0
27
+ python-hcl2 == 4.3.2
28
+
29
+ # Lambda layer: langchain
30
+ # ------------
31
+ langchain == 0.1.1
32
+ langchain-openai == 0.0.5
33
+
34
+ # Lambda layer: nlp
35
+ # ------------
36
+ python-Levenshtein == 0.23.0
37
+ nltk == 3.8.1
38
+ textblob == 0.17.1
39
+
40
+ # weather function
41
+ googlemaps == 4.10.0
42
+ openmeteo-requests == 1.1.0
43
+ requests-cache == 1.1.1
44
+ retry-requests == 2.0.0
Original file line number Diff line number Diff line change
1
+ # --------------------------------------------------------------
2
+ # Deploy containerized application to an existing Kubernetes cluster
3
+ # --------------------------------------------------------------
4
+
5
+ provider "kubernetes" {
6
+ config_path = " ~/.kube/config"
7
+ }
8
+
9
+ # resource "kubernetes_manifest" "deployment" {
10
+ # manifest = yamldecode(data.template_file.deployment.rendered)
11
+ # }
12
+
13
+ # 1. namespace
14
+ # 2. service
15
+ # 3. horizontal scaling policy
16
+ # 4. vertical scaling policy
17
+ # 5. certificate
18
+ # 6. ingress
19
+ # 7. route53 dns record
Original file line number Diff line number Diff line change
1
+ # ------------------------------------------------------------------------------
2
+ # written by: Lawrence McDaniel
3
+ # https://lawrencemcdaniel.com/
4
+ #
5
+ # date: July-2023
6
+ #
7
+ # usage: Terraform configuration
8
+ # ------------------------------------------------------------------------------
9
+
10
+ terraform {
11
+ required_version = " ~> 1.5"
12
+ backend "s3" {
13
+ bucket = " 090511222473-tfstate-openai"
14
+ key = " chat_api/terraform.tfstate"
15
+ region = " us-east-1"
16
+ dynamodb_table = " 090511222473-tfstate-lock-openai"
17
+ profile = " lawrence"
18
+ encrypt = false
19
+ }
20
+
21
+ required_providers {
22
+ aws = {
23
+ source = " hashicorp/aws"
24
+ version = " ~> 5.35"
25
+ }
26
+ null = {
27
+ source = " hashicorp/null"
28
+ version = " ~> 3.2"
29
+ }
30
+ kubernetes = {
31
+ source = " hashicorp/kubernetes"
32
+ version = " ~> 2.25"
33
+ }
34
+ }
35
+ }
Original file line number Diff line number Diff line change
1
+ # ------------------------------------------------------------------------------
2
+ # written by: Lawrence McDaniel
3
+ # https://lawrencemcdaniel.com/
4
+ #
5
+ # date: sep-2023
6
+ #
7
+ # usage: override default variable values
8
+ # ------------------------------------------------------------------------------
9
+
10
+ # ##############################################################################
11
+ # AWS CLI parameters
12
+ # ##############################################################################
13
+ aws_account_id = " 090511222473"
14
+ tags = {
15
+ " terraform" = " true" ,
16
+ " project" = " chatGPT microservice"
17
+ " contact" = " Lawrence McDaniel - https://lawrencemcdaniel.com/"
18
+ }
19
+ aws_region = " us-east-2"
20
+ aws_profile = " lawrence"
21
+
22
+ # ##############################################################################
23
+ # OpenAI API parameters
24
+ # ##############################################################################
25
+ openai_endpoint_image_n = 4
26
+ openai_endpoint_image_size = " 1024x768"
27
+
28
+
29
+ # ##############################################################################
30
+ # CloudWatch logging parameters
31
+ # ##############################################################################
32
+ logging_level = " INFO"
33
+
34
+
35
+ # ##############################################################################
36
+ # APIGateway parameters
37
+ # ##############################################################################
38
+ root_domain = " lawrencemcdaniel.com"
39
+ shared_resource_identifier = " openai"
40
+ stage = " v1"
You can’t perform that action at this time.
0 commit comments