Skip to content

Commit ab54ece

Browse files
committed
enhance: API Key is now optional
- Update README.md by adding tips for using OpenAI in this project
1 parent 6fc972c commit ab54ece

File tree

3 files changed

+20
-6
lines changed

3 files changed

+20
-6
lines changed

README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,19 @@ For **Linux** users:
8787
* Make sure [git-credential-manager](https://github.com/git-ecosystem/git-credential-manager/releases) is installed on your linux.
8888
* Maybe you need to set environment variable `AVALONIA_SCREEN_SCALE_FACTORS`. See https://github.com/AvaloniaUI/Avalonia/wiki/Configuring-X11-per-monitor-DPI.
8989

90+
## OpenAI
91+
92+
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.
93+
94+
For `OpenAI`:
95+
96+
* `Server` must be `https://api.openai.com/v1/chat/completions`
97+
98+
For other AI service:
99+
100+
* The `Server` should fill in a URL equivalent to OpenAI's `https://api.openai.com/v1/chat/completions`
101+
* The `API Key` is optional that depends on the service
102+
90103
## External Tools
91104

92105
This app supports open repository in external tools listed in the table below.

src/Models/OpenAI.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ public static string Model
9595

9696
public static bool IsValid
9797
{
98-
get => !string.IsNullOrEmpty(Server) && !string.IsNullOrEmpty(ApiKey) && !string.IsNullOrEmpty(Model);
98+
get => !string.IsNullOrEmpty(Server) && !string.IsNullOrEmpty(Model);
9999
}
100100

101101
public static OpenAIChatResponse Chat(string prompt, string question, CancellationToken cancellation)
@@ -105,7 +105,8 @@ public static OpenAIChatResponse Chat(string prompt, string question, Cancellati
105105
chat.AddMessage("user", question);
106106

107107
var client = new HttpClient() { Timeout = TimeSpan.FromSeconds(60) };
108-
client.DefaultRequestHeaders.Add("Authorization", $"Bearer {ApiKey}");
108+
if (!string.IsNullOrEmpty(ApiKey))
109+
client.DefaultRequestHeaders.Add("Authorization", $"Bearer {ApiKey}");
109110

110111
var req = new StringContent(JsonSerializer.Serialize(chat, JsonCodeGen.Default.OpenAIChatRequest));
111112
try

src/Views/Preference.axaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -364,22 +364,22 @@
364364
Text="{Binding OpenAIServer, Mode=TwoWay}"/>
365365

366366
<TextBlock Grid.Row="1" Grid.Column="0"
367-
Text="{DynamicResource Text.Preference.AI.ApiKey}"
367+
Text="{DynamicResource Text.Preference.AI.Model}"
368368
HorizontalAlignment="Right"
369369
Margin="0,0,16,0"/>
370370
<TextBox Grid.Row="1" Grid.Column="1"
371371
Height="28"
372372
CornerRadius="3"
373-
Text="{Binding OpenAIApiKey, Mode=TwoWay}"/>
373+
Text="{Binding OpenAIModel, Mode=TwoWay}"/>
374374

375375
<TextBlock Grid.Row="2" Grid.Column="0"
376-
Text="{DynamicResource Text.Preference.AI.Model}"
376+
Text="{DynamicResource Text.Preference.AI.ApiKey}"
377377
HorizontalAlignment="Right"
378378
Margin="0,0,16,0"/>
379379
<TextBox Grid.Row="2" Grid.Column="1"
380380
Height="28"
381381
CornerRadius="3"
382-
Text="{Binding OpenAIModel, Mode=TwoWay}"/>
382+
Text="{Binding OpenAIApiKey, Mode=TwoWay}"/>
383383
</Grid>
384384
</TabItem>
385385

0 commit comments

Comments
 (0)