diff --git a/README.md b/README.md index d03c648..1e45afc 100644 --- a/README.md +++ b/README.md @@ -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. --- @@ -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** @@ -39,6 +39,7 @@ 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 @@ -46,15 +47,16 @@ All settings are handled in the `appsettings.json` file: ``` πŸ”’ 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. --- @@ -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). --- @@ -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 diff --git a/appsettings.json b/appsettings.json index ca0002c..a757ea1 100644 --- a/appsettings.json +++ b/appsettings.json @@ -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 diff --git a/src/Clients/LMClient.cs b/src/Clients/LMClient.cs index 2e02385..6af5dbd 100644 --- a/src/Clients/LMClient.cs +++ b/src/Clients/LMClient.cs @@ -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 @@ -86,34 +87,30 @@ private static async Task> CallModelAsync( return []; var retriesCount = 1; - string message = string.Empty; + string json = string.Empty; IEnumerable? 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>(message, _jsonOptions); + result = JsonSerializer.Deserialize>(json, _jsonOptions); } catch (Exception ex) { logger?.LogError("Attempt: {Count}ΒΊ", retriesCount); logger?.LogError("{Error}", ex.Message); - logger?.LogError("{Json}", message); + logger?.LogError("{Json}", json); retriesCount++; @@ -128,6 +125,29 @@ private static async Task> CallModelAsync( return result!; } + private static async Task SendRequestAsync( + IEnumerable 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 commits, string modelContext, diff --git a/src/Models/AppSettings.cs b/src/Models/AppSettings.cs index 129712c..9364766 100644 --- a/src/Models/AppSettings.cs +++ b/src/Models/AppSettings.cs @@ -12,6 +12,7 @@ public AppSettings() Culture = string.Empty; OutputPath = string.Empty; CompletionsUri = string.Empty; + ApiKey = string.Empty; } public string RepositoryPath { get; set; } @@ -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; }