Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 16 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# AutoDoc - Git to Report 📚

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

---

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

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

5. **CSV Generation**
Expand All @@ -39,22 +39,24 @@ All settings are handled in the `appsettings.json` file:
"Culture": "en-US",
"OutputPath": "AutoDoc-Reports",
"CompletionsUri": "http://localhost:1234/v1/chat/completions",
"ApiKey": "your_api_key_here",
"DelayMilliseconds": 20000,
"ModelTemperature": 0.5,
"MaxRetries": 2
}
```

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

---

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

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

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

4 - Edit Context.txt with your project context.

5 - Make sure LM Studio server is running.
5 - Make sure AI server is reachable.

6 - Execute AutoDoc.exe

- Option 1: [StartDate] [EndDate] | Explanation: The folllowing arguments will generate 1 month of reports.
```text
PS C:\Users\eduar> C:\Users\eduar\Desktop\AutoDoc-win-x64\AutoDoc.exe 2025-01-01 2025-02-01
Expand Down
1 change: 1 addition & 0 deletions appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"Culture": "en-US",
"OutputPath": "AutoDoc-Reports",
"CompletionsUri": "http://localhost:1234/v1/chat/completions",
"ApiKey": "your_api_key_here",
"DelayMilliseconds": 20000,
"ModelTemperature": 0.5,
"MaxRetries": 2
Expand Down
38 changes: 29 additions & 9 deletions src/Clients/LMClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using AutoDoc.Models;
using System.Text.Json;
using AutoDoc.Extensions;
using System.Net.Http.Headers;
using Microsoft.Extensions.Logging;

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

var retriesCount = 1;
string message = string.Empty;
string json = string.Empty;
IEnumerable<Report>? result = null;

do
{
try
{
var content = BuildRequestBody(commits, modelContext, appSettings);

var response = await _httpClient.PostAsync(appSettings.CompletionsUri, content, ct);
response.EnsureSuccessStatusCode();

var response = await SendRequestAsync(commits, modelContext, appSettings, ct);
var responseString = await response.Content.ReadAsStringAsync(ct);

using var doc = JsonDocument.Parse(responseString);
message = doc.RootElement
json = doc.RootElement
.GetProperty("choices")[0]
.GetProperty("message")
.GetProperty("content")
.GetString()!;

result = JsonSerializer.Deserialize<IEnumerable<Report>>(message, _jsonOptions);
result = JsonSerializer.Deserialize<IEnumerable<Report>>(json, _jsonOptions);
}
catch (Exception ex)
{
logger?.LogError("Attempt: {Count}º", retriesCount);
logger?.LogError("{Error}", ex.Message);
logger?.LogError("{Json}", message);
logger?.LogError("{Json}", json);

retriesCount++;

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

private static async Task<HttpResponseMessage> SendRequestAsync(
IEnumerable<MyCommit> commits,
string modelContext,
AppSettings appSettings,
CancellationToken ct)
{
if (commits is null || !commits.Any())
return new HttpResponseMessage(System.Net.HttpStatusCode.BadRequest);

var content = BuildRequestBody(commits, modelContext, appSettings);

var request = new HttpRequestMessage(HttpMethod.Post, appSettings.CompletionsUri)
{
Content = content
};

if (!string.IsNullOrWhiteSpace(appSettings.ApiKey))
request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", appSettings.ApiKey);

var response = await _httpClient.SendAsync(request, ct);
return response.EnsureSuccessStatusCode();
}

private static StringContent BuildRequestBody(
IEnumerable<MyCommit> commits,
string modelContext,
Expand Down
3 changes: 3 additions & 0 deletions src/Models/AppSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public AppSettings()
Culture = string.Empty;
OutputPath = string.Empty;
CompletionsUri = string.Empty;
ApiKey = string.Empty;
}

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

public string CompletionsUri { get; set; }

public string ApiKey { get; set; }

public int DelayMilliseconds { get; set; }

public double ModelTemperature { get; set; }
Expand Down