Skip to content

Commit 733a37b

Browse files
committed
Add support for custom OpenAI API base URL
1 parent 0e7d319 commit 733a37b

File tree

2 files changed

+29
-8
lines changed

2 files changed

+29
-8
lines changed

README.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,4 +83,14 @@ determine the style guide. It is optional, but if it exists, it will be followed
8383
even if the rules there diverge from the norm.
8484

8585
If there is no repo style guide, `aicommit` will look for a user style guide
86-
in `~/COMMITS.md`.
86+
in `~/COMMITS.md`.
87+
88+
## Other Providers
89+
90+
You may set `OPENAI_BASE_URL` to use other OpenAI compatible APIs with `aicommit`.
91+
So far, I've tested it with [LiteLLM](https://github.com/BerriAI/litellm) across
92+
local models (via ollama) and Anthropic. I have yet to find a local model
93+
that is well-steered by the prompt design here, but the Anthropic Claude 3.5
94+
commit messages are on par with 4o. My theory for why local models don't work well
95+
is (even the "Instruct" fine-tuned models) have much worse instruction
96+
fine-tuning than the flagship commercial models.

cmd/aicommit/main.go

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -193,12 +193,13 @@ func run(inv *serpent.Invocation, opts runOptions) error {
193193
}
194194

195195
type runOptions struct {
196-
client *openai.Client
197-
model string
198-
dryRun bool
199-
amend bool
200-
ref string
201-
context []string
196+
client *openai.Client
197+
openAIBaseURL string
198+
model string
199+
dryRun bool
200+
amend bool
201+
ref string
202+
context []string
202203
}
203204

204205
func main() {
@@ -253,7 +254,9 @@ func main() {
253254
return nil
254255
}
255256

256-
client := openai.NewClient(openAIKey)
257+
oaiConfig := openai.DefaultConfig(openAIKey)
258+
oaiConfig.BaseURL = opts.openAIBaseURL
259+
client := openai.NewClientWithConfig(oaiConfig)
257260
opts.client = client
258261
if len(inv.Args) > 0 {
259262
opts.ref = inv.Args[0]
@@ -268,6 +271,14 @@ func main() {
268271
Flag: "openai-key",
269272
Value: serpent.StringOf(&cliOpenAIKey),
270273
},
274+
{
275+
Name: "openai-base-url",
276+
Description: "The base URL to use for the OpenAI API.",
277+
Env: "OPENAI_BASE_URL",
278+
Flag: "openai-base-url",
279+
Value: serpent.StringOf(&opts.openAIBaseURL),
280+
Default: "https://api.openai.com/v1",
281+
},
271282
{
272283
Name: "model",
273284
Description: "The model to use, e.g. gpt-4o or gpt-4o-mini.",

0 commit comments

Comments
 (0)