Skip to content

Commit

Permalink
Add support for custom OpenAI API base URL
Browse files Browse the repository at this point in the history
  • Loading branch information
ammario committed Oct 13, 2024
1 parent 0e7d319 commit 733a37b
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 8 deletions.
12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,14 @@ determine the style guide. It is optional, but if it exists, it will be followed
even if the rules there diverge from the norm.

If there is no repo style guide, `aicommit` will look for a user style guide
in `~/COMMITS.md`.
in `~/COMMITS.md`.

## Other Providers

You may set `OPENAI_BASE_URL` to use other OpenAI compatible APIs with `aicommit`.
So far, I've tested it with [LiteLLM](https://github.com/BerriAI/litellm) across
local models (via ollama) and Anthropic. I have yet to find a local model
that is well-steered by the prompt design here, but the Anthropic Claude 3.5
commit messages are on par with 4o. My theory for why local models don't work well
is (even the "Instruct" fine-tuned models) have much worse instruction
fine-tuning than the flagship commercial models.
25 changes: 18 additions & 7 deletions cmd/aicommit/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,12 +193,13 @@ func run(inv *serpent.Invocation, opts runOptions) error {
}

type runOptions struct {
client *openai.Client
model string
dryRun bool
amend bool
ref string
context []string
client *openai.Client
openAIBaseURL string
model string
dryRun bool
amend bool
ref string
context []string
}

func main() {
Expand Down Expand Up @@ -253,7 +254,9 @@ func main() {
return nil
}

client := openai.NewClient(openAIKey)
oaiConfig := openai.DefaultConfig(openAIKey)
oaiConfig.BaseURL = opts.openAIBaseURL
client := openai.NewClientWithConfig(oaiConfig)
opts.client = client
if len(inv.Args) > 0 {
opts.ref = inv.Args[0]
Expand All @@ -268,6 +271,14 @@ func main() {
Flag: "openai-key",
Value: serpent.StringOf(&cliOpenAIKey),
},
{
Name: "openai-base-url",
Description: "The base URL to use for the OpenAI API.",
Env: "OPENAI_BASE_URL",
Flag: "openai-base-url",
Value: serpent.StringOf(&opts.openAIBaseURL),
Default: "https://api.openai.com/v1",
},
{
Name: "model",
Description: "The model to use, e.g. gpt-4o or gpt-4o-mini.",
Expand Down

0 comments on commit 733a37b

Please sign in to comment.