[AOT] Clean up some AOT issues in Advanced Paste module (#36297)
* Clean up the aot build issue. * Merge main and clean up new AOT build issue * Update LogEvent define. * Update src/modules/AdvancedPaste/AdvancedPaste/Helpers/LogEvent.cs Co-authored-by: Jeremy Sinclair <4016293+snickler@users.noreply.github.com> * update typo bug * Remove unused allow list item * Create a new folder to place source generation context * Merge main and rename LogEvent to AIServiceFormatEvent --------- Co-authored-by: Yu Leng (from Dev Box) <yuleng@microsoft.com> Co-authored-by: Jeremy Sinclair <4016293+snickler@users.noreply.github.com>
This commit is contained in:
Родитель
ddcad65796
Коммит
4d787e9434
|
@ -265,4 +265,4 @@ onefuzz
|
||||||
leilzh
|
leilzh
|
||||||
|
|
||||||
#Tools
|
#Tools
|
||||||
OIP
|
OIP
|
|
@ -0,0 +1,45 @@
|
||||||
|
// Copyright (c) Microsoft Corporation
|
||||||
|
// The Microsoft Corporation licenses this file to you under the MIT license.
|
||||||
|
// See the LICENSE file in the project root for more information.
|
||||||
|
|
||||||
|
using System.Text.Json;
|
||||||
|
using AdvancedPaste.Models.KernelQueryCache;
|
||||||
|
using AdvancedPaste.SerializationContext;
|
||||||
|
using AdvancedPaste.Telemetry;
|
||||||
|
|
||||||
|
namespace AdvancedPaste.Helpers
|
||||||
|
{
|
||||||
|
public class AIServiceFormatEvent
|
||||||
|
{
|
||||||
|
public AIServiceFormatEvent(AdvancedPasteSemanticKernelFormatEvent semanticKernelFormatEvent)
|
||||||
|
{
|
||||||
|
CacheUsed = semanticKernelFormatEvent.CacheUsed;
|
||||||
|
IsSavedQuery = semanticKernelFormatEvent.IsSavedQuery;
|
||||||
|
PromptTokens = semanticKernelFormatEvent.PromptTokens;
|
||||||
|
CompletionTokens = semanticKernelFormatEvent.CompletionTokens;
|
||||||
|
ModelName = semanticKernelFormatEvent.ModelName;
|
||||||
|
ActionChain = semanticKernelFormatEvent.ActionChain;
|
||||||
|
}
|
||||||
|
|
||||||
|
public AIServiceFormatEvent(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, SourceGenerationContext.Default.AIServiceFormatEvent);
|
||||||
|
}
|
||||||
|
}
|
|
@ -18,7 +18,7 @@ namespace AdvancedPaste.Helpers
|
||||||
|
|
||||||
internal static int Size
|
internal static int Size
|
||||||
{
|
{
|
||||||
get { return Marshal.SizeOf(typeof(INPUT)); }
|
get { return Marshal.SizeOf<INPUT>(); }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -16,7 +16,7 @@ using Microsoft.PowerToys.Settings.UI.Library.Utilities;
|
||||||
|
|
||||||
namespace AdvancedPaste.Settings
|
namespace AdvancedPaste.Settings
|
||||||
{
|
{
|
||||||
internal sealed class UserSettings : IUserSettings, IDisposable
|
internal sealed partial class UserSettings : IUserSettings, IDisposable
|
||||||
{
|
{
|
||||||
private readonly SettingsUtils _settingsUtils;
|
private readonly SettingsUtils _settingsUtils;
|
||||||
private readonly TaskScheduler _taskScheduler;
|
private readonly TaskScheduler _taskScheduler;
|
||||||
|
|
|
@ -7,6 +7,7 @@ using System.Text.Json;
|
||||||
using System.Text.Json.Serialization;
|
using System.Text.Json.Serialization;
|
||||||
|
|
||||||
using AdvancedPaste.Helpers;
|
using AdvancedPaste.Helpers;
|
||||||
|
using AdvancedPaste.SerializationContext;
|
||||||
using Microsoft.PowerToys.Settings.UI.Library.Interfaces;
|
using Microsoft.PowerToys.Settings.UI.Library.Interfaces;
|
||||||
|
|
||||||
namespace AdvancedPaste.Models.KernelQueryCache;
|
namespace AdvancedPaste.Models.KernelQueryCache;
|
||||||
|
@ -15,15 +16,7 @@ public sealed class PersistedCache : ISettingsConfig
|
||||||
{
|
{
|
||||||
public record class CacheItem(CacheKey CacheKey, CacheValue CacheValue);
|
public record class CacheItem(CacheKey CacheKey, CacheValue CacheValue);
|
||||||
|
|
||||||
private static readonly JsonSerializerOptions SerializerOptions = new()
|
public static PersistedCache FromJsonString(string json) => JsonSerializer.Deserialize<PersistedCache>(json, SourceGenerationContext.Default.PersistedCache);
|
||||||
{
|
|
||||||
Converters =
|
|
||||||
{
|
|
||||||
new JsonStringEnumConverter(),
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
public static PersistedCache FromJsonString(string json) => JsonSerializer.Deserialize<PersistedCache>(json, SerializerOptions);
|
|
||||||
|
|
||||||
public string Version { get; init; }
|
public string Version { get; init; }
|
||||||
|
|
||||||
|
@ -31,7 +24,7 @@ public sealed class PersistedCache : ISettingsConfig
|
||||||
|
|
||||||
public string GetModuleName() => Constants.AdvancedPasteModuleName;
|
public string GetModuleName() => Constants.AdvancedPasteModuleName;
|
||||||
|
|
||||||
public string ToJsonString() => JsonSerializer.Serialize(this, SerializerOptions);
|
public string ToJsonString() => JsonSerializer.Serialize(this, SourceGenerationContext.Default.PersistedCache);
|
||||||
|
|
||||||
public override string ToString() => ToJsonString();
|
public override string ToString() => ToJsonString();
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,16 @@
|
||||||
|
// Copyright (c) Microsoft Corporation
|
||||||
|
// The Microsoft Corporation licenses this file to you under the MIT license.
|
||||||
|
// See the LICENSE file in the project root for more information.
|
||||||
|
|
||||||
|
using System.Text.Json.Serialization;
|
||||||
|
using AdvancedPaste.Helpers;
|
||||||
|
using AdvancedPaste.Models.KernelQueryCache;
|
||||||
|
|
||||||
|
namespace AdvancedPaste.SerializationContext;
|
||||||
|
|
||||||
|
[JsonSerializable(typeof(PersistedCache))]
|
||||||
|
[JsonSerializable(typeof(AIServiceFormatEvent))]
|
||||||
|
[JsonSourceGenerationOptions(UseStringEnumConverter = true)]
|
||||||
|
public sealed partial class SourceGenerationContext : JsonSerializerContext
|
||||||
|
{
|
||||||
|
}
|
|
@ -174,9 +174,8 @@ public abstract class KernelServiceBase(IKernelQueryCacheService queryCacheServi
|
||||||
{
|
{
|
||||||
AdvancedPasteSemanticKernelFormatEvent telemetryEvent = new(cacheUsed, isSavedQuery, usage.PromptTokens, usage.CompletionTokens, ModelName, AdvancedPasteSemanticKernelFormatEvent.FormatActionChain(actionChain));
|
AdvancedPasteSemanticKernelFormatEvent telemetryEvent = new(cacheUsed, isSavedQuery, usage.PromptTokens, usage.CompletionTokens, ModelName, AdvancedPasteSemanticKernelFormatEvent.FormatActionChain(actionChain));
|
||||||
PowerToysTelemetry.Log.WriteEvent(telemetryEvent);
|
PowerToysTelemetry.Log.WriteEvent(telemetryEvent);
|
||||||
|
var logEvent = new AIServiceFormatEvent(telemetryEvent);
|
||||||
var logEvent = new { telemetryEvent.CacheUsed, telemetryEvent.IsSavedQuery, telemetryEvent.PromptTokens, telemetryEvent.CompletionTokens, telemetryEvent.ModelName, telemetryEvent.ActionChain };
|
Logger.LogDebug($"{nameof(TransformClipboardAsync)} complete; {logEvent.ToJsonString()}");
|
||||||
Logger.LogDebug($"{nameof(TransformClipboardAsync)} complete; {JsonSerializer.Serialize(logEvent)}");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private Kernel CreateKernel()
|
private Kernel CreateKernel()
|
||||||
|
|
|
@ -85,9 +85,9 @@ Output:
|
||||||
var usage = response.Usage;
|
var usage = response.Usage;
|
||||||
AdvancedPasteGenerateCustomFormatEvent telemetryEvent = new(usage.PromptTokens, usage.CompletionTokens, ModelName);
|
AdvancedPasteGenerateCustomFormatEvent telemetryEvent = new(usage.PromptTokens, usage.CompletionTokens, ModelName);
|
||||||
PowerToysTelemetry.Log.WriteEvent(telemetryEvent);
|
PowerToysTelemetry.Log.WriteEvent(telemetryEvent);
|
||||||
|
var logEvent = new AIServiceFormatEvent(telemetryEvent);
|
||||||
|
|
||||||
var logEvent = new { telemetryEvent.PromptTokens, telemetryEvent.CompletionTokens, telemetryEvent.ModelName };
|
Logger.LogDebug($"{nameof(TransformTextAsync)} complete; {logEvent.ToJsonString()}");
|
||||||
Logger.LogDebug($"{nameof(TransformTextAsync)} complete; {JsonSerializer.Serialize(logEvent)}");
|
|
||||||
|
|
||||||
return response.Choices[0].Text;
|
return response.Choices[0].Text;
|
||||||
}
|
}
|
||||||
|
|
Загрузка…
Ссылка в новой задаче