GitHub Models CLI Extension

repository·main·Indexed 41 days ago

https://github.com/github/gh-models

A CLI extension (`gh models`) for interacting with AI models via the GitHub Models service. It supports model listing, REPL and single-shot inference, prompt evaluation using `.prompt.yml` files, and automated test case generation based on the PromptPex methodology.

Tokens
9.7K
Snippets
36
Records
62
Agent score
52%

What's inside GitHub Models

  1. Run linting and unit tests

    main

    Before submitting a pull request, run the following commands to ensure code quality:

    • make check: Runs lint tests, unit tests, and all other Go-related checks.
    • make test: Runs tests.
    • make fmt: Automatically formats the code.
    • make vet: Finds suspicious constructs.
    • make tidy: Keeps dependencies up-to-date.
    make check
  2. Run integration tests for gh-models

    main

    Integration tests for the gh-models CLI extension use the actual compiled binary rather than mocked clients. They verify the basic functionality of commands like list, run, view, and eval.

    Tests are designed to be environment-aware: they will skip tests requiring live endpoints if GitHub authentication is not detected, allowing the suite to run partially even without credentials.

    # From the integration directory
    go test -v
  3. Set up the development environment for gh-models

    main

    To develop with gh-models, ensure you have the following prerequisites installed:

    1. gh CLI: Must be installed and available in your PATH. You must also be authenticated via gh auth.
    2. Go: A minimum version of 1.22 is required.
    go version
    go version go1.22.x <arch>
  4. Prerequisites for running integration tests

    main

    Before running integration tests, you must build the gh-models binary. For full test coverage (including live endpoint testing), you should also be authenticated via the GitHub CLI.

    1. Build the binary: Run the build script from the repository root.
    2. Authenticate (Optional): Use gh auth login to enable tests that require live GitHub endpoints.
    # 1. Build the binary
    cd ..
    script/build
    
    # 2. (Optional) Authenticate for full testing
    gh auth login
  5. Install the GitHub Models CLI extension

    main

    To use the GitHub Models service from your terminal, you must first have the gh CLI installed and authenticated via gh auth. You can install the extension using the following command:

    gh extension install https://github.com/github/gh-models
  6. Run integration tests

    main

    Integration tests are located in the integration/ directory and test the compiled binary against live endpoints. Note that tests requiring authentication will be automatically skipped if no GitHub token is available.

    To run them:

    1. Build the binary first.
    2. Navigate to the integration directory.
    3. Run go test -v.
    make build
    cd integration
    go test -v
  7. Release a new version of gh-models

    main

    Because gh extension install and gh extension upgrade pull the latest release rather than the latest commit, you must create a new Git tag to publish changes. Tagging triggers the release action, which performs the production build.

    git tag v0.0.x main
    git push origin tag v0.0.x
  8. How to add new integration tests

    main

    When adding new commands or features to gh-models, follow these guidelines for creating integration tests:

    1. Pattern: Follow the existing pattern of checking for binary existence and checking for authentication status.
    2. Authentication Awareness: Ensure tests skip live endpoint checks if authentication is unavailable so the suite doesn't fail in unauthenticated environments.
    3. Assertions: Keep assertions minimal but meaningful. Focus on:
      • Successful command execution without errors.
      • Presence and correct formatting of help text.
      • Basic output format compliance.
      • Respecting authentication requirements.
  9. How the Rules Compliance Evaluator works

    main

    The GenerateRulesEvaluator is a specialized evaluator used during the generation process to determine if a chatbot's output complies with its provided description and specific extracted rules.

    Evaluation Logic

    The evaluator uses an LLM to compare the <chatbot_output> against the original <prompt> and the <output_rules>. It follows these core principles:

    1. Direct Compliance Only: Judgment must be grounded exclusively in the textual content provided; do not speculate or infer.
    2. Compliance Scoring: The evaluator assigns a score between 0 and 100 based on the severity and importance of rule violations.
    3. Reasoning First: The evaluator is instructed to first generate a reasoning draft (minimum 20 words) in English before providing the final evaluation.
    4. Focus on Rules, Not Functional Correctness: The primary goal is to check if the output adheres to the constraints and rules, rather than evaluating the functional correctness of the reasoning itself (though it may use the provided <input> to verify rule compliance).

    Response Format

    The evaluator expects a response that includes reasoning followed by a qualitative label. The internal mapping for these labels is:

    • poor: completely wrong or irrelevant
    • below_average: partially correct but missing key information
    • average: mostly correct with minor gaps
    • good: accurate and complete with clear explanation
    • excellent: exceptionally accurate, complete, and well-explained