$ show microsoft/gpt-review
gpt-review is a Python CLI tool that integrates OpenAI/Azure OpenAI models to assist with software development workflows. It provides three main functionalities: asking questions to GPT models (with optional file/context), reviewing GitHub pull requests and posting AI-generated comments, and generating git commit messages based on staged changes. The application uses a modular architecture with separate components for different functionalities: question answering (_ask.py), PR review (_review.py), git operations (_git.py), document indexing (_llama_index.py), and API wrappers (_openai.py). It leverages the knack library for CLI structure, GitPython for git operations, Requests for GitHub API calls, and LlamaIndex for context-aware queries. The tool supports both direct OpenAI API and Azure OpenAI with automatic fallback to Azure Key Vault for credentials.
The LLM identified 4 files worth highlighting for reuse:
Implements a robust exponential backoff algorithm for handling API rate limits. The function dynamically calculates wait times based on retry count and honors Retry-After headers when available. This self-contained utility demonstrates thoughtful error handling practices and could be easily extracted for use in any project making external API calls.
Manages configuration for Azure/OpenAI services with a well-defined precedence hierarchy: config file → environment variables → Azure Key Vault. The implementation cleanly handles multiple configuration sources and provides a typed Context object. This component shows strong separation of concerns and could be reused in other projects needing flexible configuration management.
Wraps OpenAI API calls with intelligent model selection based on prompt length and expected token usage. Automatically chooses between GPT-3.5 Turbo, GPT-4, and GPT-4-32K models to optimize for cost and performance. Includes proper retry logic for rate limits. This abstraction demonstrates non-obvious skill in LLM integration and could be extracted as a standalone LLM client library.
Provides a simplified interface over LlamaIndex for document indexing and question answering. Handles multiple data sources (local files, directories, GitHub repositories) and manages indexing/caching automatically. This component effectively abstracts a complex library into an easy-to-use API for context-aware queries, demonstrating good library wrapping practices.