Skip to content

Commit

Permalink
CLI updates (#1)
Browse files Browse the repository at this point in the history
* cli updates

* cli updates
  • Loading branch information
cgrant authored Feb 20, 2024
1 parent c5827e9 commit 3b1b3e1
Show file tree
Hide file tree
Showing 18 changed files with 102 additions and 75 deletions.
2 changes: 2 additions & 0 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions outer-loop-cli/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ share/python-wheels/
.installed.cfg
*.egg
MANIFEST
bdist.*/


# PyInstaller
Expand Down
110 changes: 77 additions & 33 deletions outer-loop-cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -19,53 +62,36 @@ 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.

```sh
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.

Expand All @@ -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

Expand All @@ -107,7 +133,7 @@ devai ai
devai echo
```

## Cleanup
### Cleanup

To uninstall the package run the following command

Expand All @@ -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
```
File renamed without changes.
4 changes: 4 additions & 0 deletions outer-loop-cli/src/devai/__main__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import devai.cli as cli

if __name__ == "__main__":
cli.devai()
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

import click

from commands import cmd, prompt, review, release
from devai.commands import cmd, prompt, review, release


@click.group()
Expand Down
1 change: 1 addition & 0 deletions outer-loop-cli/src/devai/commands/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import cmd, prompt, release, review
File renamed without changes.
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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:
Expand All @@ -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)

Expand All @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
Empty file.
File renamed without changes.
28 changes: 0 additions & 28 deletions outer-loop-cli/src/requirements.txt
Original file line number Diff line number Diff line change
@@ -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
10 changes: 6 additions & 4 deletions outer-loop-cli/src/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
],
},
)

0 comments on commit 3b1b3e1

Please sign in to comment.