Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[AOT] Clean up some AOT issues in Advanced Paste module #36297

Merged
merged 16 commits into from
Jan 21, 2025
Merged
39 changes: 36 additions & 3 deletions src/modules/AdvancedPaste/AdvancedPaste/Helpers/LogEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,50 @@

using System.Text.Json;
using AdvancedPaste.Models.KernelQueryCache;
using AdvancedPaste.Telemetry;

namespace AdvancedPaste.Helpers
{
public class LogEvent
{
public LogEvent(object message)
public LogEvent(bool cacheUsed, bool isSavedQuery, int promptTokens, int completionTokens, string modelName, string actionChain)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this constructor needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, we don't need it anymore. Removed

{
this.message = message;
CacheUsed = cacheUsed;
IsSavedQuery = isSavedQuery;
PromptTokens = promptTokens;
CompletionTokens = completionTokens;
ModelName = modelName;
ActionChain = actionChain;
}

private object message;
public LogEvent(AdvancedPasteSemanticKernelFormatEvent semanticKernalFormatEvent)
{
CacheUsed = semanticKernalFormatEvent.CacheUsed;
IsSavedQuery = semanticKernalFormatEvent.IsSavedQuery;
PromptTokens = semanticKernalFormatEvent.PromptTokens;
CompletionTokens = semanticKernalFormatEvent.CompletionTokens;
ModelName = semanticKernalFormatEvent.ModelName;
ActionChain = semanticKernalFormatEvent.ActionChain;
}

public LogEvent(AdvancedPasteGenerateCustomFormatEvent generateCustomFormatEvent)
{
PromptTokens = generateCustomFormatEvent.PromptTokens;
CompletionTokens = generateCustomFormatEvent.CompletionTokens;
ModelName = generateCustomFormatEvent.ModelName;
}

public bool IsSavedQuery { get; set; }

public bool CacheUsed { get; set; }

public int PromptTokens { get; set; }

public int CompletionTokens { get; set; }

public string ModelName { get; set; }

public string ActionChain { get; set; }

public string ToJsonString() => JsonSerializer.Serialize(this, AdvancedPasteJsonSerializerContext.Default.PersistedCache);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ private void LogResult(bool cacheUsed, bool isSavedQuery, IEnumerable<ActionChai
{
AdvancedPasteSemanticKernelFormatEvent telemetryEvent = new(cacheUsed, isSavedQuery, usage.PromptTokens, usage.CompletionTokens, ModelName, AdvancedPasteSemanticKernelFormatEvent.FormatActionChain(actionChain));
PowerToysTelemetry.Log.WriteEvent(telemetryEvent);
var logEvent = new LogEvent(new { telemetryEvent.CacheUsed, telemetryEvent.IsSavedQuery, telemetryEvent.PromptTokens, telemetryEvent.CompletionTokens, telemetryEvent.ModelName, telemetryEvent.ActionChain });
var logEvent = new LogEvent(telemetryEvent);
Logger.LogDebug($"{nameof(TransformClipboardAsync)} complete; {logEvent.ToJsonString()}");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ public async Task<string> TransformTextAsync(string prompt, string inputText)
var usage = response.Usage;
AdvancedPasteGenerateCustomFormatEvent telemetryEvent = new(usage.PromptTokens, usage.CompletionTokens, ModelName);
PowerToysTelemetry.Log.WriteEvent(telemetryEvent);
var logEvent = new LogEvent(telemetryEvent);

var logEvent = new LogEvent(new { telemetryEvent.PromptTokens, telemetryEvent.CompletionTokens, telemetryEvent.ModelName });
Logger.LogDebug($"{nameof(TransformTextAsync)} complete; {logEvent.ToJsonString()}");

return response.Choices[0].Text;
Expand Down
Loading