Skip to content

Commit ef613b5

Browse files
Merge pull request #10 from IseduardoRezende/dev-eduardo
✨feat: Add LMClient api-key support
2 parents 50cd417 + 5298c58 commit ef613b5

File tree

4 files changed

+49
-23
lines changed

4 files changed

+49
-23
lines changed

README.md

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# AutoDoc - Git to Report 📚
22

33
**AutoDoc** is a simple but powerful multiplatform tool that automatically analyzes Git commits and generates structured daily CSV reports.
4-
It leverages [LM Studio](https://lmstudio.ai/) as the AI engine to transform commit history into meaningful documentation with context-aware summaries.
4+
It leverages AI to transform commit history into meaningful documentation with context-aware summaries.
55

66
---
77

@@ -19,7 +19,7 @@ It leverages [LM Studio](https://lmstudio.ai/) as the AI engine to transform com
1919
- Each part is sent to the model for structured summarization.
2020

2121
4. **AI Integration**
22-
- Uses LM Studio's local API (`/v1/chat/completions`).
22+
- Can use OpenAI APIs like (`/v1/chat/completions`).
2323
- Automatically retries failed requests and waits between calls to avoid memory overload.
2424

2525
5. **CSV Generation**
@@ -39,22 +39,24 @@ All settings are handled in the `appsettings.json` file:
3939
"Culture": "en-US",
4040
"OutputPath": "AutoDoc-Reports",
4141
"CompletionsUri": "http://localhost:1234/v1/chat/completions",
42+
"ApiKey": "your_api_key_here",
4243
"DelayMilliseconds": 20000,
4344
"ModelTemperature": 0.5,
4445
"MaxRetries": 2
4546
}
4647
```
4748

4849
🔢 Explanation of Parameters:
49-
- RepositoryPath → Path to the Git repository to analyze.
50-
- OwnerEmail → Git email address for filtering commits.
51-
- OwnerName → Who is responsible for the commits.
52-
- Culture → Defines reporting culture/locale (e.g., pt-BR, en-US).
53-
- OutputPath → Directory where daily CSV files are saved.
54-
- CompletionsUri → API endpoint of LM Studio.
55-
- DelayMilliseconds → Delay between requests (prevents RAM overload).
56-
- ModelTemperature → Controls creativity of the model (0 = focused, 1 = creative).
57-
- MaxRetries → How many times to retry if a request fails.
50+
- RepositoryPath → Path to the Git repository to analyze.
51+
- OwnerEmail → Git email address for filtering commits.
52+
- OwnerName → Who is responsible for the commits.
53+
- Culture → Defines reporting culture/locale (e.g., pt-BR, en-US).
54+
- OutputPath → Directory where daily CSV files are saved.
55+
- CompletionsUri → API endpoint.
56+
- ApiKey → API Key if applicable.
57+
- DelayMilliseconds → Delay between requests (prevents RAM overload).
58+
- ModelTemperature → Controls creativity of the model (0 = focused, 1 = creative).
59+
- MaxRetries → How many times to retry if a request fails.
5860

5961
---
6062

@@ -74,8 +76,7 @@ The project is developed in/with: [Your Project languages and tools].
7476
---
7577

7678
## 📦 Requirements
77-
LM Studio installed and running locally.
78-
Start LM Studio server with your preferred model.
79+
Access to an AI server.
7980
Ensure it listens on the same port as configured in appsettings.json (default: http://localhost:1234).
8081

8182
---
@@ -90,9 +91,10 @@ Ensure it listens on the same port as configured in appsettings.json (default: h
9091

9192
4 - Edit Context.txt with your project context.
9293

93-
5 - Make sure LM Studio server is running.
94+
5 - Make sure AI server is reachable.
9495

9596
6 - Execute AutoDoc.exe
97+
9698
- Option 1: [StartDate] [EndDate] | Explanation: The folllowing arguments will generate 1 month of reports.
9799
```text
98100
PS C:\Users\eduar> C:\Users\eduar\Desktop\AutoDoc-win-x64\AutoDoc.exe 2025-01-01 2025-02-01

appsettings.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"Culture": "en-US",
66
"OutputPath": "AutoDoc-Reports",
77
"CompletionsUri": "http://localhost:1234/v1/chat/completions",
8+
"ApiKey": "your_api_key_here",
89
"DelayMilliseconds": 20000,
910
"ModelTemperature": 0.5,
1011
"MaxRetries": 2

src/Clients/LMClient.cs

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using AutoDoc.Models;
33
using System.Text.Json;
44
using AutoDoc.Extensions;
5+
using System.Net.Http.Headers;
56
using Microsoft.Extensions.Logging;
67

78
namespace AutoDoc.Clients
@@ -86,34 +87,30 @@ private static async Task<IEnumerable<Report>> CallModelAsync(
8687
return [];
8788

8889
var retriesCount = 1;
89-
string message = string.Empty;
90+
string json = string.Empty;
9091
IEnumerable<Report>? result = null;
9192

9293
do
9394
{
9495
try
9596
{
96-
var content = BuildRequestBody(commits, modelContext, appSettings);
97-
98-
var response = await _httpClient.PostAsync(appSettings.CompletionsUri, content, ct);
99-
response.EnsureSuccessStatusCode();
100-
97+
var response = await SendRequestAsync(commits, modelContext, appSettings, ct);
10198
var responseString = await response.Content.ReadAsStringAsync(ct);
10299

103100
using var doc = JsonDocument.Parse(responseString);
104-
message = doc.RootElement
101+
json = doc.RootElement
105102
.GetProperty("choices")[0]
106103
.GetProperty("message")
107104
.GetProperty("content")
108105
.GetString()!;
109106

110-
result = JsonSerializer.Deserialize<IEnumerable<Report>>(message, _jsonOptions);
107+
result = JsonSerializer.Deserialize<IEnumerable<Report>>(json, _jsonOptions);
111108
}
112109
catch (Exception ex)
113110
{
114111
logger?.LogError("Attempt: {Count}º", retriesCount);
115112
logger?.LogError("{Error}", ex.Message);
116-
logger?.LogError("{Json}", message);
113+
logger?.LogError("{Json}", json);
117114

118115
retriesCount++;
119116

@@ -128,6 +125,29 @@ private static async Task<IEnumerable<Report>> CallModelAsync(
128125
return result!;
129126
}
130127

128+
private static async Task<HttpResponseMessage> SendRequestAsync(
129+
IEnumerable<MyCommit> commits,
130+
string modelContext,
131+
AppSettings appSettings,
132+
CancellationToken ct)
133+
{
134+
if (commits is null || !commits.Any())
135+
return new HttpResponseMessage(System.Net.HttpStatusCode.BadRequest);
136+
137+
var content = BuildRequestBody(commits, modelContext, appSettings);
138+
139+
var request = new HttpRequestMessage(HttpMethod.Post, appSettings.CompletionsUri)
140+
{
141+
Content = content
142+
};
143+
144+
if (!string.IsNullOrWhiteSpace(appSettings.ApiKey))
145+
request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", appSettings.ApiKey);
146+
147+
var response = await _httpClient.SendAsync(request, ct);
148+
return response.EnsureSuccessStatusCode();
149+
}
150+
131151
private static StringContent BuildRequestBody(
132152
IEnumerable<MyCommit> commits,
133153
string modelContext,

src/Models/AppSettings.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ public AppSettings()
1212
Culture = string.Empty;
1313
OutputPath = string.Empty;
1414
CompletionsUri = string.Empty;
15+
ApiKey = string.Empty;
1516
}
1617

1718
public string RepositoryPath { get; set; }
@@ -30,6 +31,8 @@ public AppSettings()
3031

3132
public string CompletionsUri { get; set; }
3233

34+
public string ApiKey { get; set; }
35+
3336
public int DelayMilliseconds { get; set; }
3437

3538
public double ModelTemperature { get; set; }

0 commit comments

Comments
 (0)