Current home for the Viam SDK AI Updater
This repository houses an AI-powered updater for the Viam SDKs. Its primary purpose is to automatically analyze protobuf definition changes as a git diff and generate corresponding updates to the Viam SDK's code and tests (more functionality to come).
This repository includes a reusable GitHub Actions workflow (.github/workflows/ai-updater.yml) that can be called by other repositories (e.g., an SDK repository) to automate the AI update process.
The workflow is triggered by workflow_call and expects the following inputs:
target_branch(required): The branch in the calling SDK repository that needs to be updated.sdk(required): The language of the calling SDK repository that needs to be updated (currently supportspython,typescript,cpp,flutter)
And the following secrets:
GOOGLE_API_KEY: A Google Generative AI API key.GIT_ACCESS_TOKEN: Viam Git Access Token. This will cause the AI generated PR to be made by 'viambot' so CI tests will automatically run.
To call this workflow from another repository's workflow (e.g., viam-python-sdk):
# .github/workflows/sdk-update-trigger.yml (in the SDK repository)
name: Trigger AI SDK Update
on:
push:
branches:
- workflow/update-proto # Or any branch that triggers the update
jobs:
call-ai-updater:
runs-on: ubuntu-latest
steps:
- name: Call AI Updater Workflow
uses: ggottlob/viam-ai-updater/.github/workflows/ai-updater.yml@main # Replace 'main' with your desired branch/tag
with:
target_branch: ${{ github.ref_name }} # Passes the current branch name of the SDK repo
secrets:
GOOGLE_API_KEY: ${{ secrets.GOOGLE_API_KEY }}
GIT_ACCESS_TOKEN: ${{ secrets.GIT_ACCESS_TOKEN }}To set up your local development environment, follow these steps:
-
Clone the Repository:
git clone https://github.com/your-org/viam-ai-updater.git cd viam-ai-updater -
Create a Python Virtual Environment: It's highly recommended to use a virtual environment to manage project dependencies.
python3 -m venv .venv
-
Activate the Virtual Environment:
source .venv/bin/activate -
Install Dependencies: Install the required Python packages using
pip install -r requirements.txtfrom therequirements.txtfile.pip install -r requirements.txt
The ai_updater.py script can be run in two primary modes: for testing against a mock SDK or for actual updates within a GitHub Workflow (as shown above).
--debug: (Optional) Enable debug mode to print various helpful files and additional logging.--noai: (Optional) Disable AI model calls (useful for testing the script's logic without incurring API costs).--patch: (Optional) Attempt to apply changes as patches to existing files rather than regenerating the entire file. If patching fails, the file will be regenerated.--sdk <sdk_name>: (Required) Specify the SDK that is being updated. Currently supportspython,cpp,typescript, andflutter.--test <path_to_test_repo>: (Mutually Exclusive with--work) Enable test mode. Supply the path to the root directory of the test repository.--work <path_to_sdk_repo>: (Mutually Exclusive with--test) Enable workflow mode. Supply the path to the root directory of the SDK repository that is being updated.
To run the AI updater locally for development or testing:
# Make sure your virtual environment is activated
source .venv/bin/activate
# Example: Running against a local test scenario (replace 'path/to/scenario-1-repo' with your test data)
python ai_updater/ai_updater.py --debug --test /path/to/scenario-1-repoThis repo comes with a testing suite containing various examples of past proto updates to the Python SDK so you can test how the AI would act in that scenario.
Tests are written using pytest and are located in the ai_updater/tests/ directory.
From the project root, with your virtual environment activated:
source .venv/bin/activate
pytest ai_updater/tests/To run tests for a specific scenario (e.g., scenario-1), use the -k flag:
source .venv/bin/activate
pytest ai_updater/tests/test_ai_updater.py -k "scenario-1"The test_ai_updater.py script can also be run directly. When executed this way, it will run all defined scenarios with the comparison step skipped. This is useful for quickly debugging the AI Updater's generation process.
From the project root, with your virtual environment activated:
source .venv/bin/activate
python ai_updater/tests/test_ai_updater.py