diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 47ce1dc..2eb88cc 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -29,3 +29,5 @@ build-job: - echo $GOOGLE_CLOUD_CREDENTIALS > service-account-key.json - export GOOGLE_APPLICATION_CREDENTIALS="service-account-key.json" - devai review code -c ./cli-code-api/sample-app/src/main/java/anthos/samples/bankofanthos/balancereader + - devai review performance -c ./cli-code-api/sample-app/src/main/java/anthos/samples/bankofanthos/balancereader + - devai review security -c ./cli-code-api/sample-app/src/main/java/anthos/samples/bankofanthos/balancereader diff --git a/outer-loop-cli/.gitignore b/outer-loop-cli/.gitignore index cc08b12..f5809f5 100644 --- a/outer-loop-cli/.gitignore +++ b/outer-loop-cli/.gitignore @@ -24,6 +24,7 @@ share/python-wheels/ .installed.cfg *.egg MANIFEST +bdist.*/ # PyInstaller diff --git a/outer-loop-cli/README.md b/outer-loop-cli/README.md index 2de09d7..600b905 100644 --- a/outer-loop-cli/README.md +++ b/outer-loop-cli/README.md @@ -4,7 +4,50 @@ This example demonstrates ways to integrate LLM models into a custom command lin This directory contains a sample cli implementation called devai, as well as a tutorial describing how to use it. -## Getting started +## Install and use +The cli is provided as a package on PyPi for demonstration purposes only. It is not intended for production use as is. To install the package for use locally or in CICD systems run the following command + +```sh +pip install -i https://test.pypi.org/simple/ devai +``` + +## Local execution + +Once installed you can use the CLI with its short name `devai` as follows + +```sh +devai echo +devai echo +devai sub + +devai prompt with_context +devai prompt with_msg +devai prompt with_msg_streaming + +devai review code -c ../../sample-app/src/main/java +devai review performance -c ../../sample-app/src/main/java +devai review security -c ../../sample-app/src/main/java + +devai release notes_user_tag -t "v5.0.0" +devai release notes_user -s "main" -e "feature-branch-name" +``` + +## Use in CICD + +This can be added in any build pipeline following the examples below: + +GitHub Actions (Full example at ${repoRoot/.github/workflows/devai-review.yml}) + +```sh + - name: Code Review + run: echo '## Code Review Results 🚀' >> $GITHUB_STEP_SUMMARY + - run: echo "$(devai review code -c ${{ github.workspace }}/sample-app/src/main/java/anthos/samples/bankofanthos/balancereader)" >> $GITHUB_STEP_SUMMARY + shell: bash +``` + +## Developers Guide + +### Getting started To start, setup your virtualenv, install requirements and run the sample command @@ -19,39 +62,28 @@ Sample commands Change into the src directory -``` +```sh cd src ``` ```sh -python devai.py echo -python devai.py sub +python -m devai echo +python -m devai sub -python devai.py prompt with_context -python devai.py prompt with_msg -python devai.py prompt with_msg_streaming +python -m devai prompt with_context +python -m devai prompt with_msg +python -m devai prompt with_msg_streaming -python devai.py review code -c ../../sample-app/src/main/java -python devai.py review performance -c ../../sample-app/src/main/java -python devai.py review security -c ../../sample-app/src/main/java +python -m devai review code -c ../../sample-app/src/main/java +python -m devai review performance -c ../../sample-app/src/main/java +python -m devai review security -c ../../sample-app/src/main/java -python devai.py release notes_user_tag -t "v5.0.0" -python devai.py release notes_user -s "main" -e "feature-branch-name" +python -m devai release notes_user_tag -t "v5.0.0" +python -m devai release notes_user -s "main" -e "feature-branch-name" ``` -## Adding dependencies - -When adding new dependencies, first install the package with pip as seen in the following example. Then be sure to freeze the dependencies in the requirements.txt file. - -The following command is run from the projects base folder. - -```sh -pip install click -pip freeze > src/requirements.txt -``` - -## Working with an installable app +### Working with an installable app To create an installable CLI from the source, use setuptools to create the dai cli with the following command from the project base folder. @@ -59,13 +91,7 @@ To create an installable CLI from the source, use setuptools to create the dai c pip install --editable ./src ``` -Once installed you can use the CLI with its short name `devai` as follows - -```sh -devai echo -``` - -## Testing integrations with Cloud Build Jobs +### Testing integrations with Cloud Build Jobs There are multiple cloudbuild files included in order to facilitate local builds and tests as well as automated CICD for this repo. @@ -91,7 +117,7 @@ gcloud builds submit . --config=build/cloudbuild-pipeline-test.yaml ``` -## Containerized CLI +### Containerized CLI To work with the CLI inside the container, build it locally and run it with your .config folder mounted to provide access to gcloud credentials @@ -107,7 +133,7 @@ devai ai devai echo ``` -## Cleanup +### Cleanup To uninstall the package run the following command @@ -120,3 +146,21 @@ To deactivate virtual env run the following command ```sh deactivate ``` + +### Publish to PyPi + +```sh +pip install build twine +``` + +```sh +rm -rf src/dist +python3 -m build src/ + +python3 -m twine upload --repository testpypi src/dist/* --verbose +``` + +```sh +pip install -i https://test.pypi.org/simple/ devai==0.1.4.2 +devai +``` diff --git a/outer-loop-cli/src/commands/__init__.py b/outer-loop-cli/src/devai/__init__.py similarity index 100% rename from outer-loop-cli/src/commands/__init__.py rename to outer-loop-cli/src/devai/__init__.py diff --git a/outer-loop-cli/src/devai/__main__.py b/outer-loop-cli/src/devai/__main__.py new file mode 100644 index 0000000..abca2b3 --- /dev/null +++ b/outer-loop-cli/src/devai/__main__.py @@ -0,0 +1,4 @@ +import devai.cli as cli + +if __name__ == "__main__": + cli.devai() \ No newline at end of file diff --git a/outer-loop-cli/src/devai.py b/outer-loop-cli/src/devai/cli.py similarity index 94% rename from outer-loop-cli/src/devai.py rename to outer-loop-cli/src/devai/cli.py index 3378f4f..ec59b85 100644 --- a/outer-loop-cli/src/devai.py +++ b/outer-loop-cli/src/devai/cli.py @@ -14,7 +14,7 @@ import click -from commands import cmd, prompt, review, release +from devai.commands import cmd, prompt, review, release @click.group() diff --git a/outer-loop-cli/src/devai/commands/__init__.py b/outer-loop-cli/src/devai/commands/__init__.py new file mode 100644 index 0000000..a02d847 --- /dev/null +++ b/outer-loop-cli/src/devai/commands/__init__.py @@ -0,0 +1 @@ +from . import cmd, prompt, release, review diff --git a/outer-loop-cli/src/commands/cmd.py b/outer-loop-cli/src/devai/commands/cmd.py similarity index 100% rename from outer-loop-cli/src/commands/cmd.py rename to outer-loop-cli/src/devai/commands/cmd.py diff --git a/outer-loop-cli/src/devai/commands/msg/__init__.py b/outer-loop-cli/src/devai/commands/msg/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/outer-loop-cli/src/commands/msg/standard.py b/outer-loop-cli/src/devai/commands/msg/standard.py similarity index 97% rename from outer-loop-cli/src/commands/msg/standard.py rename to outer-loop-cli/src/devai/commands/msg/standard.py index 45c1940..461386d 100644 --- a/outer-loop-cli/src/commands/msg/standard.py +++ b/outer-loop-cli/src/devai/commands/msg/standard.py @@ -14,7 +14,7 @@ import click -from util.file_processor import get_text_files_contents +from devai.util.file_processor import get_text_files_contents from vertexai.language_models import CodeChatModel, ChatModel @click.command(name='with_msg') diff --git a/outer-loop-cli/src/commands/msg/streaming.py b/outer-loop-cli/src/devai/commands/msg/streaming.py similarity index 97% rename from outer-loop-cli/src/commands/msg/streaming.py rename to outer-loop-cli/src/devai/commands/msg/streaming.py index 92b2c27..fa25f6e 100644 --- a/outer-loop-cli/src/commands/msg/streaming.py +++ b/outer-loop-cli/src/devai/commands/msg/streaming.py @@ -14,7 +14,7 @@ import click -from util.file_processor import get_text_files_contents +from devai.util.file_processor import get_text_files_contents from vertexai.language_models import CodeChatModel, ChatModel @click.command(name='with_msg_streaming') diff --git a/outer-loop-cli/src/commands/prompt.py b/outer-loop-cli/src/devai/commands/prompt.py similarity index 92% rename from outer-loop-cli/src/commands/prompt.py rename to outer-loop-cli/src/devai/commands/prompt.py index 5933492..af604cc 100644 --- a/outer-loop-cli/src/commands/prompt.py +++ b/outer-loop-cli/src/devai/commands/prompt.py @@ -13,9 +13,9 @@ # limitations under the License. import click -from commands.msg import standard, streaming +from devai.commands.msg import standard, streaming -from util.file_processor import get_text_files_contents +from devai.util.file_processor import get_text_files_contents from vertexai.language_models import CodeChatModel, ChatModel diff --git a/outer-loop-cli/src/commands/release.py b/outer-loop-cli/src/devai/commands/release.py similarity index 96% rename from outer-loop-cli/src/commands/release.py rename to outer-loop-cli/src/devai/commands/release.py index ffa7808..667fa04 100644 --- a/outer-loop-cli/src/commands/release.py +++ b/outer-loop-cli/src/devai/commands/release.py @@ -13,7 +13,7 @@ # limitations under the License. import click -from util.file_processor import format_files_as_string, list_files, list_changes, list_commit_messages, list_commits_for_branches, list_tags, list_commits_for_tags +from devai.util.file_processor import format_files_as_string, list_files, list_changes, list_commit_messages, list_commits_for_branches, list_tags, list_commits_for_tags from vertexai.language_models import CodeChatModel diff --git a/outer-loop-cli/src/commands/review.py b/outer-loop-cli/src/devai/commands/review.py similarity index 96% rename from outer-loop-cli/src/commands/review.py rename to outer-loop-cli/src/devai/commands/review.py index 8db5a97..2ae4a22 100644 --- a/outer-loop-cli/src/commands/review.py +++ b/outer-loop-cli/src/devai/commands/review.py @@ -14,7 +14,7 @@ import click -from util.file_processor import format_files_as_string +from devai.util.file_processor import format_files_as_string from vertexai.language_models import CodeChatModel, ChatModel from vertexai.preview.language_models import CodeGenerationModel @@ -27,7 +27,7 @@ @click.command(name='code') @click.option('-c', '--context', required=False, type=str, default="") def code(context): - click.echo('code') + #click.echo('code') source=''' CODE: @@ -48,6 +48,7 @@ def code(context): source=source.format(format_files_as_string(context)) code_chat_model = CodeChatModel.from_pretrained("codechat-bison") + chat = code_chat_model.start_chat(context=source, **parameters) response = chat.send_message(qry) @@ -57,7 +58,7 @@ def code(context): @click.command() @click.option('-c', '--context', required=False, type=str, default="") def performance(context): - click.echo('performance') + #click.echo('performance') source=''' CODE: @@ -85,7 +86,7 @@ def performance(context): @click.command() @click.option('-c', '--context', required=False, type=str, default="") def security(context): - click.echo('simple security') + #click.echo('simple security') source=''' CODE: diff --git a/outer-loop-cli/src/devai/util/__init__.py b/outer-loop-cli/src/devai/util/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/outer-loop-cli/src/util/file_processor.py b/outer-loop-cli/src/devai/util/file_processor.py similarity index 100% rename from outer-loop-cli/src/util/file_processor.py rename to outer-loop-cli/src/devai/util/file_processor.py diff --git a/outer-loop-cli/src/requirements.txt b/outer-loop-cli/src/requirements.txt index 2d1ffb2..02f2e26 100644 --- a/outer-loop-cli/src/requirements.txt +++ b/outer-loop-cli/src/requirements.txt @@ -1,30 +1,2 @@ -cachetools==5.3.2 -certifi==2023.7.22 -charset-normalizer==3.3.1 click==8.1.7 -google-api-core==2.12.0 -google-auth==2.23.3 google-cloud-aiplatform==1.35.0 -google-cloud-bigquery==3.13.0 -google-cloud-core==2.3.3 -google-cloud-resource-manager==1.10.4 -google-cloud-storage==2.12.0 -google-crc32c==1.5.0 -google-resumable-media==2.6.0 -googleapis-common-protos==1.61.0 -grpc-google-iam-v1==0.12.6 -grpcio==1.59.2 -grpcio-status==1.59.2 -idna==3.4 -numpy==1.26.1 -packaging==23.2 -proto-plus==1.22.3 -protobuf==4.24.4 -pyasn1==0.5.0 -pyasn1-modules==0.3.0 -python-dateutil==2.8.2 -requests==2.31.0 -rsa==4.9 -shapely==2.0.2 -six==1.16.0 -urllib3==2.0.7 diff --git a/outer-loop-cli/src/setup.py b/outer-loop-cli/src/setup.py index 0591e45..5191cc3 100644 --- a/outer-loop-cli/src/setup.py +++ b/outer-loop-cli/src/setup.py @@ -12,18 +12,20 @@ # See the License for the specific language governing permissions and # limitations under the License. -from setuptools import setup +from setuptools import setup, find_packages setup( name='devai', - version='0.1.0', + version='0.1.4.2', + packages=find_packages(), py_modules=['devai'], install_requires=[ - 'Click', + 'click==8.1.7', + 'google-cloud-aiplatform' ], entry_points={ 'console_scripts': [ - 'devai = devai:devai', + 'devai = devai.cli:devai', ], }, ) \ No newline at end of file