feat: improve commit message generation with AI prompts (#596)

- Refactor the commit message generation process to utilize default prompts and enhance clarity while eliminating redundancy.
- Added new properties for subject and summary prompts, while improving cancellation support in async task handling.
- feat: add AI prompts for commit message generation.
- Updated the formatting of the package reference for consistency in the project file.
- Add properties for managing OpenAI subject and summary prompts in the Preference view model.
- Refactor layout and add new input fields for AI subject and summary prompts in the preferences view.
This commit is contained in:
Douglas Cunha 2024-10-23 22:31:05 -03:00 committed by GitHub
parent 547c28adb8
commit 2f68aed817
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 141 additions and 38 deletions

View file

@ -94,6 +94,18 @@ namespace SourceGit.Models
set;
}
public static string SubjectPrompt
{
get;
set;
}
public static string SummaryPrompt
{
get;
set;
}
public static bool IsValid
{
get => !string.IsNullOrEmpty(Server) && !string.IsNullOrEmpty(Model);
@ -113,14 +125,14 @@ namespace SourceGit.Models
try
{
var task = client.PostAsync(Server, req, cancellation);
task.Wait();
task.Wait(cancellation);
var rsp = task.Result;
if (!rsp.IsSuccessStatusCode)
throw new Exception($"AI service returns error code {rsp.StatusCode}");
var reader = rsp.Content.ReadAsStringAsync(cancellation);
reader.Wait();
reader.Wait(cancellation);
return JsonSerializer.Deserialize(reader.Result, JsonCodeGen.Default.OpenAIChatResponse);
}