Skip to content

Commit 358ad4d

Browse files
authored
Merge pull request #205 from FullStackWithLawrence/next
v0.7.0 - Pydantic Settings class + unit test automations
2 parents f4cd8f2 + 9a2b00d commit 358ad4d

File tree

179 files changed

+4214
-1992
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

179 files changed

+4214
-1992
lines changed

.github/actions/tests/python/action.yml

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,6 @@ pinecone-environment:
2828
required: true
2929
type: string
3030

31-
env:
32-
REQUIREMENTS_PATH: "api/terraform/python/layer_genai/requirements.txt"
33-
3431
runs:
3532
using: "composite"
3633
steps:
@@ -96,7 +93,6 @@ runs:
9693
- name: Install dependencies
9794
shell: bash
9895
run: |
99-
cp -R ./api/terraform/python/layer_genai/openai_utils ${{ env.SITE_PACKAGES_PATH }}
10096
pip install -r ./requirements.txt
10197
env:
10298
SITE_PACKAGES_PATH: ${{ env.SITE_PACKAGES_PATH }}
@@ -109,20 +105,14 @@ runs:
109105
echo "OPENAI_API_KEY=${{ env.OPENAI_API_KEY }}" >> ./.env
110106
echo "PINECONE_API_KEY=${{ env.PINECONE_API_KEY }}" >> ./.env
111107
echo "PINECONE_ENVIRONMENT=${{ env.PINECONE_ENVIRONMENT }}" >> ./.env
108+
echo "DEBUG_MODE=False" >> ./.env
112109
env:
113110
OPENAI_API_ORGANIZATION: ${{ inputs.openai-api-organization }}
114111
OPENAI_API_KEY: ${{ inputs.openai-api-key }}
115112
PINECONE_API_KEY: ${{ inputs.pinecone-api-key }}
116113
PINECONE_ENVIRONMENT: ${{ inputs.pinecone-environment }}
117114

118-
- name: Test lambda_openai_v2
119-
shell: bash
120-
run: |
121-
cd ./api/terraform/python/lambda_openai_v2
122-
pytest -v -s tests/
123-
124-
- name: Test lambda_langchain
115+
- name: Run Python unit tests
125116
shell: bash
126117
run: |
127-
cd ./api/terraform/python/lambda_langchain
128-
pytest -v -s tests/
118+
make api-test

.github/workflows/auto-assign.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
name: Auto Assign
2+
on:
3+
issues:
4+
types: [opened]
5+
pull_request:
6+
types: [opened]
7+
jobs:
8+
run:
9+
runs-on: ubuntu-latest
10+
permissions:
11+
issues: write
12+
pull-requests: write
13+
steps:
14+
- name: "Auto-assign issue"
15+
uses: pozil/auto-assign-issue@v1
16+
with:
17+
repo-token: ${{ secrets.GITHUB_TOKEN }}
18+
assignees: lpm0073
19+
numOfAssignee: 1

.github/workflows/runTests.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,13 @@ jobs:
1717
id: checkout
1818
uses: actions/checkout@v4
1919

20+
- name: Configure AWS credentials
21+
uses: aws-actions/configure-aws-credentials@v4
22+
with:
23+
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
24+
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
25+
aws-region: ${{ secrets.AWS_REGION }}
26+
2027
- name: Run Python tests
2128
uses: ./.github/actions/tests/python
2229
with:

.github/workflows/semanticVersionBump.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ jobs:
2424
runs-on: ubuntu-latest
2525
env:
2626
VERSION_FILE: __version__.py
27-
PACKAGE_PATH: ${{ github.workspace }}/api/terraform/python/layer_genai/openai_utils/
27+
PACKAGE_PATH: ${{ github.workspace }}/api/terraform/python/openai_api/
2828

2929
steps:
3030
- uses: actions/checkout@v4
@@ -110,8 +110,9 @@ jobs:
110110
id: update_version
111111
run: |
112112
echo "# -*- coding: utf-8 -*-" > ${{ env.VERSION_FILE }}
113-
echo "__version__ = '${{ env.NEXT_VERSION }}'" >> ${{ env.VERSION_FILE }}
114-
echo "" >> ${{ env.VERSION_FILE }}
113+
echo "# DO NOT EDIT." >> ${{ env.VERSION_FILE }}
114+
echo "# Managed via automated CI/CD in .github/workflows/semanticVersionBump.yml." >> ${{ env.VERSION_FILE }}
115+
echo "__version__ = \"${{ env.NEXT_VERSION }}\"" >> ${{ env.VERSION_FILE }}
115116
git config --local user.email "[email protected]"
116117
git config --local user.name "GitHub Action"
117118
git add ${{ env.VERSION_FILE }}

.github/workflows/testsPython.yml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: Python Unit Tests
2+
3+
on:
4+
workflow_dispatch:
5+
pull_request:
6+
paths:
7+
- "**.py"
8+
push:
9+
paths:
10+
- "**.py"
11+
12+
env:
13+
python-version: "3.11"
14+
15+
jobs:
16+
python-unit-tests:
17+
runs-on: ubuntu-latest
18+
steps:
19+
- name: Checkout code
20+
id: checkout
21+
uses: actions/checkout@v4
22+
23+
- name: Configure AWS credentials
24+
uses: aws-actions/configure-aws-credentials@v4
25+
with:
26+
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
27+
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
28+
aws-region: ${{ secrets.AWS_REGION }}
29+
30+
- name: Run Python tests
31+
uses: ./.github/actions/tests/python
32+
with:
33+
python-version: "${{ env.python-version}}"
34+
openai-api-organization: "${{ secrets.OPENAI_API_ORGANIZATION }}"
35+
openai-api-key: "${{ secrets.OPENAI_API_KEY }}"
36+
pinecone-api-key: "${{ secrets.PINECONE_API_KEY }}"
37+
pinecone-environment: "${{ secrets.PINECONE_ENVIRONMENT }}"

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
# Jupyter Notebook
22
.ipynb_checkpoints
3+
build
4+
dist
35

46
.DS_Store
7+
58
# Local .terraform directories
9+
.terraform.lock.hcl
10+
*.tfstate
11+
*.tfstate.*
612
.terraform/
713
.env
814
lambda_dist_pkg

.pre-commit-config.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,19 @@ repos:
1717
types: [javascript]
1818
files: ^client/
1919
- repo: https://github.com/pre-commit/mirrors-prettier
20-
rev: v3.1.0
20+
rev: v4.0.0-alpha.4
2121
hooks:
2222
- id: prettier
2323
- repo: https://github.com/psf/black
24-
rev: 23.11.0
24+
rev: 23.12.0
2525
hooks:
2626
- id: black
2727
- repo: https://github.com/PyCQA/flake8
2828
rev: 6.1.0
2929
hooks:
3030
- id: flake8
3131
- repo: https://github.com/PyCQA/isort
32-
rev: 5.12.0
32+
rev: 5.13.2
3333
hooks:
3434
- id: isort
3535
args: ["--settings-path=pyproject.toml"]
@@ -41,7 +41,7 @@ repos:
4141
language: script
4242
types: [python]
4343
- repo: https://github.com/PyCQA/bandit
44-
rev: 1.7.5
44+
rev: 1.7.6
4545
hooks:
4646
- id: bandit
4747
args: ["-ll"]

.pylintrc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
[MASTER]
2-
init-hook='import sys; print(sys.executable); sys.path.append("/absolute/path/to/api/terraform/python/layer_genai/openai_utils")'
32
ignore-paths =
43
api/terraform/python/lambda_openai_v2/lambda_dist_pkg,
54
api/terraform/python/lambda_openai/lambda_dist_pkg,

CHANGELOG.md

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,30 @@
1-
## [0.6.5](https://github.com/FullStackWithLawrence/aws-openai/compare/v0.6.4...v0.6.5) (2023-12-05)
1+
# Change Log
2+
3+
All notable changes to this project will be documented in this file.
4+
5+
The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/).
6+
7+
## [0.7.0]
28

9+
- replace Terraform template_file() with templatefile()
10+
- restructure Python modules. Place original lambda source code under openai_api and refactor common module so that it no longer needs to be pip installed. remove legacy lambda_openai.
11+
- refactor layer_genai to remove pip-installed common code.
12+
- refactor makefile and Github Actions so that these no longer have any special handling of Python source code.
13+
- switch from pytest to built-in python unittest
14+
- add Pydantic-based Settings class
15+
- add unit testing of both lambdas + common code
16+
17+
## [0.6.5](https://github.com/FullStackWithLawrence/aws-openai/compare/v0.6.4...v0.6.5) (2023-12-05)
318

419
### Bug Fixes
520

6-
* force a new release ([b5f8ee6](https://github.com/FullStackWithLawrence/aws-openai/commit/b5f8ee6541befb08c7e7f6b3a13bd841bc44680f))
21+
- force a new release ([b5f8ee6](https://github.com/FullStackWithLawrence/aws-openai/commit/b5f8ee6541befb08c7e7f6b3a13bd841bc44680f))
722

823
## [0.6.4](https://github.com/FullStackWithLawrence/aws-openai/compare/v0.6.3...v0.6.4) (2023-11-24)
924

10-
1125
### Bug Fixes
1226

13-
* simulated bug to trigger new release ([f373039](https://github.com/FullStackWithLawrence/aws-openai/commit/f37303924693b4ffeae424476d9fdf3595efb311))
27+
- simulated bug to trigger new release ([f373039](https://github.com/FullStackWithLawrence/aws-openai/commit/f37303924693b4ffeae424476d9fdf3595efb311))
1428

1529
## [0.6.3](https://github.com/FullStackWithLawrence/aws-openai/compare/v0.6.2...v0.6.3) (2023-11-21)
1630

Makefile

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ else
88
$(shell echo -e "OPENAI_API_ORGANIZATION=PLEASE-ADD-ME\nOPENAI_API_KEY=PLEASE-ADD-ME\nPINECONE_API_KEY=PLEASE-ADD-ME\nPINECONE_ENVIRONMENT=gcp-starter\nDEBUG_MODE=True\n" >> .env)
99
endif
1010

11-
.PHONY: analyze api-init api-activate api-lint api-clean api-test client-init client-lint client-update client-run client-build client-release
11+
.PHONY: analyze pre-commit api-init api-activate api-lint api-clean api-test client-init client-lint client-update client-run client-build client-release
1212

1313
# Default target executed when no arguments are given to make.
1414
all: help
@@ -19,6 +19,14 @@ analyze:
1919
release:
2020
git commit -m "fix: force a new release" --allow-empty && git push
2121

22+
# -------------------------------------------------------------------------
23+
# Install and run pre-commit hooks
24+
# -------------------------------------------------------------------------
25+
pre-commit:
26+
pre-commit install
27+
pre-commit autoupdate
28+
pre-commit run --all-files
29+
2230
######################
2331
# AWS API Gateway + Lambda + OpenAI
2432
######################
@@ -32,14 +40,12 @@ api-init:
3240
source venv/bin/activate && \
3341
pip install --upgrade pip && \
3442
pip install -r requirements.txt && \
35-
cp -R ./api/terraform/python/layer_genai/openai_utils ./venv/lib/python3.11/site-packages/ && \
3643
deactivate && \
3744
cd ./api/terraform/python/layer_genai/ && \
3845
python3.11 -m venv venv && \
3946
source venv/bin/activate && \
4047
pip install --upgrade pip && \
4148
pip install -r requirements.txt && \
42-
cp -R ./openai_utils ./venv/lib/python3.11/site-packages/ && \
4349
deactivate && \
4450
pre-commit install
4551

@@ -48,20 +54,11 @@ api-activate:
4854
pip install -r requirements.txt
4955

5056
api-test:
51-
cd ./api/terraform/python/lambda_langchain/ && pytest -v -s tests/
52-
cd ../../../..
53-
cd ./api/terraform/python/lambda_openai_v2/ && pytest -v -s tests/
54-
cd ../../../..
55-
cd ./api/terraform/python/lambda_openai/ && pytest -v -s tests/
56-
cd ../../../..
57+
python -m unittest discover -s api/terraform/python/openai_api/
5758

5859
api-lint:
59-
venv/bin/python3 -m pylint api/terraform/python/lambda_langchain/lambda_handler.py && \
60-
venv/bin/python3 -m pylint api/terraform/python/lambda_openai/lambda_handler.py && \
61-
venv/bin/python3 -m pylint api/terraform/python/lambda_openai_v2/lambda_handler.py && \
62-
venv/bin/python3 -m pylint api/terraform/python/layer_genai/openai_utils && \
63-
terraform fmt -recursive && \
64-
pre-commit run --all-files && \
60+
terraform fmt -recursive
61+
pre-commit run --all-files
6562
black ./api/terraform/python/
6663

6764
api-clean:
@@ -123,7 +120,7 @@ client-release:
123120
help:
124121
@echo '===================================================================='
125122
@echo 'analyze - generate code analysis report'
126-
@echo 'relase - force a new release'
123+
@echo 'release - force a new release'
127124
@echo '-- AWS API Gateway + Lambda --'
128125
@echo 'api-init - create a Python virtual environment and install dependencies'
129126
@echo 'api-activate - activate the Python virtual environment'

0 commit comments

Comments
 (0)