diff --git a/README.md b/README.md
index 8baeb5bc..170e7bd6 100644
--- a/README.md
+++ b/README.md
@@ -87,6 +87,19 @@ For **Linux** users:
* Make sure [git-credential-manager](https://github.com/git-ecosystem/git-credential-manager/releases) is installed on your linux.
* Maybe you need to set environment variable `AVALONIA_SCREEN_SCALE_FACTORS`. See https://github.com/AvaloniaUI/Avalonia/wiki/Configuring-X11-per-monitor-DPI.
+## OpenAI
+
+This software supports using OpenAI or other AI service that has an OpenAI comaptible HTTP API to generate commit message. You need configurate the service in `Preference` window.
+
+For `OpenAI`:
+
+* `Server` must be `https://api.openai.com/v1/chat/completions`
+
+For other AI service:
+
+* The `Server` should fill in a URL equivalent to OpenAI's `https://api.openai.com/v1/chat/completions`
+* The `API Key` is optional that depends on the service
+
## External Tools
This app supports open repository in external tools listed in the table below.
diff --git a/src/Models/OpenAI.cs b/src/Models/OpenAI.cs
index 94a64189..3f2acc0a 100644
--- a/src/Models/OpenAI.cs
+++ b/src/Models/OpenAI.cs
@@ -95,7 +95,7 @@ namespace SourceGit.Models
public static bool IsValid
{
- get => !string.IsNullOrEmpty(Server) && !string.IsNullOrEmpty(ApiKey) && !string.IsNullOrEmpty(Model);
+ get => !string.IsNullOrEmpty(Server) && !string.IsNullOrEmpty(Model);
}
public static OpenAIChatResponse Chat(string prompt, string question, CancellationToken cancellation)
@@ -105,7 +105,8 @@ namespace SourceGit.Models
chat.AddMessage("user", question);
var client = new HttpClient() { Timeout = TimeSpan.FromSeconds(60) };
- client.DefaultRequestHeaders.Add("Authorization", $"Bearer {ApiKey}");
+ if (!string.IsNullOrEmpty(ApiKey))
+ client.DefaultRequestHeaders.Add("Authorization", $"Bearer {ApiKey}");
var req = new StringContent(JsonSerializer.Serialize(chat, JsonCodeGen.Default.OpenAIChatRequest));
try
diff --git a/src/Views/Preference.axaml b/src/Views/Preference.axaml
index 57ba9393..2ee1517d 100644
--- a/src/Views/Preference.axaml
+++ b/src/Views/Preference.axaml
@@ -364,22 +364,22 @@
Text="{Binding OpenAIServer, Mode=TwoWay}"/>
+ Text="{Binding OpenAIModel, Mode=TwoWay}"/>
+ Text="{Binding OpenAIApiKey, Mode=TwoWay}"/>