diff --git a/src/AI.Tests/OpenAITests.cs b/src/AI.Tests/OpenAITests.cs index 3356e87..022b6a5 100644 --- a/src/AI.Tests/OpenAITests.cs +++ b/src/AI.Tests/OpenAITests.cs @@ -119,6 +119,54 @@ public async Task GPT5_ThinksFast() Assert.Equal("minimal", search["effort"]?.GetValue()); }); } + + [SecretsTheory("OPENAI_API_KEY")] + [InlineData(ReasoningEffort.Minimal)] + [InlineData(ReasoningEffort.Low)] + [InlineData(ReasoningEffort.Medium)] + [InlineData(ReasoningEffort.High)] + public async Task GPT5_ThinkingTime(ReasoningEffort effort) + { + var messages = new Chat() + { + { "system", "You are an intelligent AI assistant that's an expert on financial matters." }, + { "user", "If you have a debt of 100k and accumulate a compounding 5% debt on top of it every year, how long before you are a negative millonaire? (round up to full integer value)" }, + }; + + var requests = new List(); + + var chat = new OpenAIChatClient(Configuration["OPENAI_API_KEY"]!, "gpt-5-nano", + OpenAIClientOptions.Observable(requests.Add).WriteTo(output)); + + var options = new ChatOptions + { + ModelId = "gpt-5", + ReasoningEffort = effort + }; + + var watch = System.Diagnostics.Stopwatch.StartNew(); + var response = await chat.GetResponseAsync(messages, options); + watch.Stop(); + + var text = response.Text; + + Assert.Contains("48 years", text); + // NOTE: the chat client was requested as grok-3 but the chat options wanted a + // different model and the grok client honors that choice. + Assert.StartsWith("gpt-5", response.ModelId); + Assert.DoesNotContain("nano", response.ModelId); + + // Reasoning should have been set to medium + Assert.All(requests, x => + { + var search = Assert.IsType(x["reasoning"]); + Assert.Equal(effort.ToString().ToLowerInvariant(), search["effort"]?.GetValue()); + }); + + output.WriteLine($"Effort: {effort}, Time: {watch.ElapsedMilliseconds}ms, Tokens: {response.Usage?.TotalTokenCount}"); + } + + [SecretsFact("OPENAI_API_KEY")] public async Task WebSearchCountryHighContext() {