Skip to content

Commit

Permalink
⚡️ Use stringBuilder
Browse files Browse the repository at this point in the history
  • Loading branch information
bradystroud committed Oct 24, 2023
1 parent 9a5f751 commit a14e863
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/TimesheetGPT.Core/Interfaces/IGraphService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ public interface IGraphService
public Task<List<Email>> GetSentEmails(DateTime date, CancellationToken cancellationToken);
public Task<List<Meeting>> GetMeetings(DateTime date, CancellationToken cancellationToken);
public Task<List<TeamsCall>> GetTeamsCalls(DateTime date);
Task<Email> GetEmailBody(string subject);
Task<Email> GetEmailBody(string subject, CancellationToken ct);
}
3 changes: 2 additions & 1 deletion src/TimesheetGPT.Core/Plugins.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class GraphPlugins(IGraphService graphService)
[SKFunction, Description("Get email body from Id")]
public async Task<string?> GetEmailBody(string id)
{
return (await graphService.GetEmailBody(id)).Body;
return (await graphService.GetEmailBody(id, new CancellationToken())).Body;
}

[SKFunction, Description("Get sent emails (subject, to, Id) for a date)")]
Expand All @@ -32,6 +32,7 @@ public async Task<string> GetMeetings(DateTime dateTime)
[SKFunction, Description("Get todays date")]
public string GetTodaysDate(DateTime dateTime)
{
//TODO: Use browser datetime
return DateTime.Today.ToString(CultureInfo.InvariantCulture);

}
Expand Down
2 changes: 1 addition & 1 deletion src/TimesheetGPT.Core/PromptTemplates.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Generate a concise timesheet summary in chronological order from my meetings and
For meetings, follow the format 'Meeting Name - Meeting Length'
Skip non-essential meetings like Daily Scrums.
Treat all-day (or 9-hour) meetings as bookings. They indicate the client I worked for or, if tagged with 'SSW,' an internal focus day.
Treat all-day (or 9-hour) meetings as bookings e.g. Brady was booked as the Bench Master.
Use email subjects to figure out what tasks were completed.
Note that emails starting with 'RE:' are replies, not new tasks.
An email titled 'Sprint X Review' means I led that Sprint review/retro.
Expand Down
4 changes: 2 additions & 2 deletions src/TimesheetGPT.Core/Services/GraphService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,14 +112,14 @@ public async Task<List<TeamsCall>> GetTeamsCalls(DateTime date)
return new List<TeamsCall>();
}

public async Task<Email> GetEmailBody(string id)
public async Task<Email> GetEmailBody(string id, CancellationToken ct)
{
var message = await _client.Me.Messages[id]
.GetAsync(rc =>
{
rc.QueryParameters.Select =
new[] { "bodyPreview", "toRecipients" };
});
}, ct);

if (message != null)
{
Expand Down
18 changes: 12 additions & 6 deletions src/TimesheetGPT.Core/Services/SemKerAiService.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Microsoft.Extensions.Configuration;
using Microsoft.SemanticKernel;
using Microsoft.SemanticKernel.Planners;
using System.Text;
using TimesheetGPT.Core.Interfaces;
using TimesheetGPT.Core.Models;

Expand Down Expand Up @@ -68,22 +69,27 @@ public async Task<string> GetSummaryBoring(IList<Email> emails, IEnumerable<Meet

private static string StringifyMeetings(IEnumerable<Meeting> meetings)
{
var result = "Calendar Events (name - length) \n";
var sb = new StringBuilder();
sb.AppendLine("Calendar Events (name - length)");

foreach (var meeting in meetings)
{
result += $"{meeting.Name} - {meeting.Length} \n";
sb.AppendLine($"{meeting.Name} - {meeting.Length}");
}

return result;
return sb.ToString();
}

private static string StringifyEmails(IEnumerable<Email> emails)
{
var result = "Sent emails (recipients - subject - bodyPreview) \n";
var sb = new StringBuilder();
sb.AppendLine("Sent emails (recipients - subject - bodyPreview)");

foreach (var email in emails)
{
result += $"{email.To} - {email.Subject} \n";
sb.AppendLine($"{email.To} - {email.Subject}");
}

return result;
return sb.ToString();
}
}

0 comments on commit a14e863

Please sign in to comment.