Skip to content

Commit

Permalink
✨ Feature Prompt - Additional notes (#64)
Browse files Browse the repository at this point in the history
  • Loading branch information
SamBWagner authored Oct 7, 2023
1 parent 9176298 commit 1915612
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/TimesheetGPT.Core/Interfaces/IAiService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ namespace TimesheetGPT.Core.Interfaces;

public interface IAiService
{
public Task<string> GetSummary(string text, string extraPrompts);
public Task<string> GetSummary(string text, string extraPrompts, string additionalNotes);
}
6 changes: 5 additions & 1 deletion src/TimesheetGPT.Core/Prompts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,12 @@ Use the emails to determine tasks complete.
Only output a Markdown unordered list.
If there is no meetings or emails, respond with a joke about the user not doing any work on this day :)

{{${{{PromptVariables.Input}}}}}

{{${{{PromptVariables.ExtraPrompts}}}}}

{{${{{PromptVariables.AdditionalNotes}}}}}

{{${{{PromptVariables.Input}}}}}
""";

}
Expand All @@ -35,5 +38,6 @@ Only output a Markdown unordered list.
public static class PromptVariables
{
public const string ExtraPrompts = "extraPrompts";
public const string AdditionalNotes = "additionalNotes";
public const string Input = "inputContent";
}
2 changes: 1 addition & 1 deletion src/TimesheetGPT.Core/Services/LangChainAiService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ namespace TimesheetGPT.Core.Services;

public class LangChainAiService : IAiService
{
public async Task<string> GetSummary(string text, string extraPrompts)
public async Task<string> GetSummary(string text, string extraPrompts, string additionalNotes)

Check warning on line 7 in src/TimesheetGPT.Core/Services/LangChainAiService.cs

View workflow job for this annotation

GitHub Actions / build

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.
{
throw new NotImplementedException();
}
Expand Down
4 changes: 3 additions & 1 deletion src/TimesheetGPT.Core/Services/SemKerAiService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public SemKerAiService(IConfiguration configuration)
_apiKey = configuration["OpenAI:ApiKey"] ?? "";
}

public async Task<string> GetSummary(string text, string extraPrompts)
public async Task<string> GetSummary(string text, string extraPrompts, string additionalNotes = "")
{
Console.WriteLine(text);
var builder = new KernelBuilder();
Expand All @@ -32,11 +32,13 @@ public async Task<string> GetSummary(string text, string extraPrompts)

var kernel = builder.Build();

// Note: Token limit hurts things like additional notes. If you don't have enough, the prompt will suck
var summarizeFunction = kernel.CreateSemanticFunction(Prompts.SummarizeEmailsAndCalendar, maxTokens: 400, temperature: 0, topP: 0.5);

var context = kernel.CreateNewContext();

context.Variables.TryAdd(PromptVariables.Input, text);
context.Variables.TryAdd(PromptVariables.AdditionalNotes, additionalNotes);
context.Variables.TryAdd(PromptVariables.ExtraPrompts, extraPrompts);

var summary = await summarizeFunction.InvokeAsync(context);
Expand Down
8 changes: 5 additions & 3 deletions src/TimesheetGPT.Core/Services/TimesheetService.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.Collections;
using Microsoft.Graph;
using TimesheetGPT.Core.Interfaces;
using TimesheetGPT.Core.Models;
Expand All @@ -13,14 +14,14 @@ public TimesheetService(IAiService aiService)
_aiService = aiService;
}

public async Task<SummaryWithRaw> GenerateSummary(DateTime date, GraphServiceClient client, string extraPrompts = "")
public async Task<SummaryWithRaw> GenerateSummary(DateTime date, GraphServiceClient client, string extraPrompts = "", string additionalNotes = "")
{
IGraphService graphService = new GraphService(client);

var emailSubjects = await graphService.GetEmailSubjects(date);
var meetings = await graphService.GetMeetings(date);

var summary = await _aiService.GetSummary(StringifyData(emailSubjects, meetings), extraPrompts);
var summary = await _aiService.GetSummary(StringifyData(emailSubjects, meetings), extraPrompts, additionalNotes);

return new SummaryWithRaw
{
Expand All @@ -31,7 +32,7 @@ public async Task<SummaryWithRaw> GenerateSummary(DateTime date, GraphServiceCli
};
}

private string StringifyData(IList<string> emails, IList<Meeting> meetings)
private string StringifyData(List<string> emails, List<Meeting> meetings)
{
var result = "Sent emails (subject) \n";
foreach (var email in emails)
Expand All @@ -43,6 +44,7 @@ private string StringifyData(IList<string> emails, IList<Meeting> meetings)
{
result += $"{meeting.Name} - {meeting.Length} \n";
}

return result;
}
}
22 changes: 20 additions & 2 deletions src/TimesheetGPT.WebUI/Pages/Index.razor
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,17 @@
</MudButton>
</MudItem>

@if (additionalNotesError)
{
<MudAlert Severity="Severity.Error">Additional notes too long. You have @_additionalNotes.Length characters. We only accept 400 max.</MudAlert>
}

<MudExpansionPanel Text="Additional notes">
<MudItem xs="12">
<MudTextField @bind-Value="_additionalNotes"
Variant="Variant.Outlined"
Placeholder="I walked the dog for Adam..."
Lines="15"/>
Lines="7"/>
</MudItem>
</MudExpansionPanel>
</MudGrid>
Expand Down Expand Up @@ -133,6 +138,8 @@
string _additionalNotes = string.Empty;
string _generateButtonText = "Generate";

bool additionalNotesError;

protected override async Task OnInitializedAsync()
{
try
Expand All @@ -151,8 +158,14 @@
_loading = true;
try
{
additionalNotesError = false;
additionalNotesError = CheckAdditionalNotesIsntTooBig();
if (additionalNotesError)
{
return;
}
var dateTime = _date ?? DateTime.Today;
var summary = await TimesheetService.GenerateSummary(dateTime, GraphServiceClient, _extraPrompt ?? "");
var summary = await TimesheetService.GenerateSummary(dateTime, GraphServiceClient, _extraPrompt ?? "", _additionalNotes);

_emailSubjects = summary.Emails;
_meetings = summary.Meetings;
Expand All @@ -170,4 +183,9 @@
}

}

private bool CheckAdditionalNotesIsntTooBig()
{
return _additionalNotes.Length > 400;
}
}

0 comments on commit 1915612

Please sign in to comment.