|
| 1 | +namespace AotSmoke; |
| 2 | + |
| 3 | +using System.Text.Json.Serialization; |
| 4 | +using ManagedCode.CodexSharpSDK.Client; |
| 5 | +using ManagedCode.CodexSharpSDK.Extensions.AI; |
| 6 | +using ManagedCode.CodexSharpSDK.Models; |
| 7 | +using Microsoft.Extensions.AI; |
| 8 | +using CodexRunResult = ManagedCode.CodexSharpSDK.Models.RunResult<Payload>; |
| 9 | + |
| 10 | +internal static class Program |
| 11 | +{ |
| 12 | + public static void Main() |
| 13 | + { |
| 14 | + var schema = StructuredOutputSchema.Map<Payload>(properties: [(payload => payload.Value, StructuredOutputSchema.PlainText())]); |
| 15 | + using var client = new CodexChatClient(); |
| 16 | + Func<CodexThread, Task<CodexRunResult>> typedRun = thread => thread.RunAsync<Payload>("AOT smoke", schema, AotJsonContext.Default.Payload); |
| 17 | + Func<IChatClient, IEnumerable<ChatMessage>, ChatOptions?, CancellationToken, Task<ChatResponse>> response = |
| 18 | + (chatClient, messages, options, token) => chatClient.GetResponseAsync(messages, options, token); |
| 19 | + Func<IChatClient, IEnumerable<ChatMessage>, ChatOptions?, CancellationToken, IAsyncEnumerable<ChatResponseUpdate>> stream = |
| 20 | + (chatClient, messages, options, token) => chatClient.GetStreamingResponseAsync(messages, options, token); |
| 21 | + GC.KeepAlive(typedRun); |
| 22 | + GC.KeepAlive(response); |
| 23 | + GC.KeepAlive(stream); |
| 24 | + Console.WriteLine(AotJsonContext.Default.Payload.Type.Name); |
| 25 | + } |
| 26 | +} |
| 27 | + |
| 28 | +internal sealed class Payload { public string? Value { get; set; } } |
| 29 | +[JsonSerializable(typeof(Payload))] |
| 30 | +internal sealed partial class AotJsonContext : JsonSerializerContext; |
0 commit comments