Skip to content

[Feature]: Add support for OpenAI and Anthropic Claude as remote AI providers alongside the existing Ollama integration so users without a local GPU can use Gitbun with a cloud API key #74

Description

@divyanshim27

Summary

Gitbun currently supports local AI via Ollama and mentions "remote APIs" in the README feature list, but the implementation appears to be Ollama-only for the AI path. Users who do not have the hardware to run a local LLM (which requires 4–16GB of VRAM depending on the model) have no cloud API fallback other than the rule-based engine. Adding OpenAI (gpt-4o-mini) and Anthropic Claude (claude-haiku-4-5) as lightweight, affordable remote providers would dramatically expand the tool's usability.

Problem

  • The README says "Leverages local LLMs (via Ollama) or remote APIs" — but the "remote APIs" path is either not implemented or not documented anywhere.
  • npx gitbun for a developer without Ollama installed always falls back to the rule-based engine, producing lower-quality commit messages than the AI path.
  • gpt-4o-mini costs ~$0.00015 per 1K input tokens — a typical git diff for a small commit is under 2K tokens, making cloud AI cost essentially negligible (< $0.001 per commit).
  • The .smartcommitrc and .gitbunrc config files have no provider or apiKey fields documented.
  • Users in enterprise environments who cannot install Ollama on their machines have no AI path at all.

Proposed Solution

1. Add a provider field to the config schema:

// src/types/config.ts
export interface GitbunConfig {
  model?: string;
  ai?: boolean;
  interactive?: boolean;
  customPrompt?: string;
  provider?: 'ollama' | 'openai' | 'anthropic'; // NEW
  apiKey?: string;                                // NEW — read from config OR env var
}

2. Add an OpenAIProvider class alongside the existing Ollama integration:

// src/providers/openai.provider.ts
import OpenAI from 'openai';

export class OpenAIProvider {
  private client: OpenAI;
  private model: string;

  constructor(apiKey: string, model = 'gpt-4o-mini') {
    this.client = new OpenAI({ apiKey });
    this.model = model;
  }

  async generateCommitMessage(diff: string, prompt: string): Promise<string> {
    const response = await this.client.chat.completions.create({
      model: this.model,
      messages: [
        { role: 'system', content: prompt },
        { role: 'user', content: `Git diff:\n\`\`\`\n${diff}\n\`\`\`` },
      ],
      max_tokens: 200,
      temperature: 0.3,
    });
    return response.choices[0].message.content?.trim() ?? '';
  }
}

3. Add an AnthropicProvider class:

// src/providers/anthropic.provider.ts
import Anthropic from '@anthropic-ai/sdk';

export class AnthropicProvider {
  private client: Anthropic;
  private model: string;

  constructor(apiKey: string, model = 'claude-haiku-4-5') {
    this.client = new Anthropic({ apiKey });
    this.model = model;
  }

  async generateCommitMessage(diff: string, prompt: string): Promise<string> {
    const response = await this.client.messages.create({
      model: this.model,
      max_tokens: 200,
      messages: [{ role: 'user', content: `${prompt}\n\nGit diff:\n\`\`\`\n${diff}\n\`\`\`` }],
    });
    return (response.content[0] as { text: string }).text.trim();
  }
}

4. Provider resolution order in the main AI engine:

// src/ai/engine.ts
function resolveProvider(config: GitbunConfig): AIProvider {
  const apiKey = config.apiKey
    || process.env.OPENAI_API_KEY
    || process.env.ANTHROPIC_API_KEY;

  if (config.provider === 'openai' && process.env.OPENAI_API_KEY) {
    return new OpenAIProvider(process.env.OPENAI_API_KEY, config.model);
  }
  if (config.provider === 'anthropic' && process.env.ANTHROPIC_API_KEY) {
    return new AnthropicProvider(process.env.ANTHROPIC_API_KEY, config.model);
  }
  // Default: try Ollama, fall back to rule-based
  return new OllamaProvider(config.model);
}

5. Updated .gitbunrc example:

{
  "provider": "openai",
  "model": "gpt-4o-mini",
  "ai": true,
  "interactive": true
}

The API key is read from OPENAI_API_KEY or ANTHROPIC_API_KEY environment variables — it is never stored in the config file.

Additional Notes

  • New npm dependencies: openai (official SDK), @anthropic-ai/sdk (official SDK). Both are lightweight and have no native addons.
  • API keys are never stored in .gitbunrc or .smartcommitrc — they are read from environment variables only, to prevent accidental credential commits.
  • The diff sent to cloud APIs is truncated at 8,000 characters to stay within cost and token limits — the same truncation applied to Ollama prompts.

Could you assign this issue to me?

Labels: enhancement, feature, help wanted, GSSoC 2026

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions