the-cafe / git-ai-commit

let AI write your commit messages
https://pypi.org/project/git-ai-commit/
52 stars 0 forks source link

🐞Bug-fix: handle max AI Model errors #53

Closed Seif-Mamdouh closed 3 months ago

Seif-Mamdouh commented 3 months ago

Description

In this PR we enhanced error handling for AI-generated commit messages, focusing on Anthropic, OpenAI and ollama API integration.

Implemented a error mapping and improved error reporting in git hooks and cli providing users with clearer guidance on how to proceed when encountering issues such as token limit

Reason behind current approach

This approach implements a sort of centralized way of error handling that is highly scalable! By catching and mapping errors at the service level and then moving them upwards, it allows for consistent error handling and reporting in the higher-level in the upper infra components such as CLI and Git Hook commit processes.

Main Goals

Dev's experience : This design improves user experience by providing more meaningful error messages,

User's experience: Makes it easier to add support for new AI services or error types in the future.

Diagram

Screenshot 2024-08-15 at 2 38 37 AM

Test Plan

CLI

create a .py file and add 8000 random lines of code to it 🤓

 pip install . && pre-commit install && pre-commit autoupdate

Test Procedure (Repeat for each model: OpenAI, Anthropic, Llama)

git-ai-commit config --model=<model_name>
> git add .

> gac

Expected Output:

Error generating commit message: <Model-Name> error: ERROR TYPE

Git Hook

create a .py file and add 8000 random lines of code to it 🤓

 pip install . && pre-commit install && pre-commit autoupdate

Test Procedure (Repeat for each model: OpenAI, Anthropic, Llama)

git-ai-commit config --model=<model_name>
> git add .

> git commit

Expected Output:

Screenshot 2024-08-15 at 7 03 48 PM