In this lesson, we expand our Vibe application by adding OpenAI as an alternative AI provider for generating commit messages. Since OpenAI is a paid service, we start by setting up API keys securely—either through environment variables, a .env file (which must be added to .gitignore!), or a password manager. We install the OpenAI Go SDK and create a new package structure under `internal/llm/chatgpt` to mirror our existing Ollama implementation.
The implementation involves creating a `GenerateCommitMessage` function that uses OpenAI's chat completions API. We craft a prompt using both system and user messages—the system message defines the AI's role as a senior developer who writes well-formed commit messages using conventional commit types (feat, fix, chore, etc.), while the user message contains the actual git diff. After swapping out the Ollama call for our new ChatGPT implementation, we test it and immediately see improved commit message quality compared to the local model. This sets us up perfectly for the next lesson where we'll add CLI flags to let users choose between providers.