Contributing

To contribute to this tool, first checkout the code. Then run the tests with uv run:

cd llm
uv run pytest

You can run your development copy of llm using uv run as well:

uv run llm --help

Updating recorded HTTP API interactions and associated snapshots

This project uses pytest-recording to record OpenAI API responses for some of the tests, and syrupy to capture snapshots of their results.

If you add a new test that calls the API you can capture the API response and snapshot like this:

PYTEST_OPENAI_API_KEY="$(llm keys get openai)" uv run pytest --record-mode once --snapshot-update

Then review the new snapshots in tests/__snapshots__/ to make sure they look correct.

Debugging tricks

The default OpenAI plugin has a debugging mechanism for showing the exact requests and responses that were sent to the OpenAI API.

Set the LLM_OPENAI_SHOW_RESPONSES environment variable like this:

LLM_OPENAI_SHOW_RESPONSES=1 uv run llm -m chatgpt 'three word slogan for an an otter-run bakery'

This will output details of the API requests and responses to the console.

Use --no-stream to see a more readable version of the body that avoids streaming the response:

LLM_OPENAI_SHOW_RESPONSES=1 uv run llm -m chatgpt --no-stream \
  'three word slogan for an an otter-run bakery'

Documentation

Documentation for this project uses MyST - it is written in Markdown and rendered using Sphinx.

To build the documentation locally, run the following:

just docs

This will start a live preview server, using sphinx-autobuild.

The CLI --help examples in the documentation are managed using Cog. Update those files like this:

just cog

You'll need Just installed to run these commands.

Release process

To release a new version:

  1. Update docs/changelog.md with the new changes.

  2. Update the version number in pyproject.toml

  3. Run just cog to update docs/fragments.md with the new version number.

  4. Create a GitHub release for the new version.

  5. Wait for the package to push to PyPI and then...

  6. Run the regenerate.yaml workflow to update the Homebrew tap to the latest version.