|
1 | 1 | using Devlooped.Extensions.AI; |
| 2 | +using Devlooped.Extensions.AI.Grok; |
2 | 3 | using Microsoft.Agents.AI; |
3 | 4 | using Microsoft.Extensions.AI; |
4 | 5 | using Microsoft.Extensions.Configuration; |
@@ -211,5 +212,42 @@ public void CanSetOpenAIReasoningAndVerbosity() |
211 | 212 | Assert.Equal(Verbosity.Low, options?.ChatOptions?.Verbosity); |
212 | 213 | Assert.Equal(ReasoningEffort.Minimal, options?.ChatOptions?.ReasoningEffort); |
213 | 214 | } |
| 215 | + |
| 216 | + [Fact] |
| 217 | + public void CanSetGrokOptions() |
| 218 | + { |
| 219 | + var builder = new HostApplicationBuilder(); |
| 220 | + |
| 221 | + builder.Configuration.AddInMemoryCollection(new Dictionary<string, string?> |
| 222 | + { |
| 223 | + ["ai:clients:grok:modelid"] = "grok-4", |
| 224 | + ["ai:clients:grok:apikey"] = "xai-asdfasdf", |
| 225 | + ["ai:clients:grok:endpoint"] = "https://api.x.ai", |
| 226 | + ["ai:agents:bot:client"] = "grok", |
| 227 | + ["ai:agents:bot:options:reasoningeffort"] = "low", |
| 228 | + ["ai:agents:bot:options:search"] = "auto", |
| 229 | + }); |
| 230 | + |
| 231 | + var app = builder.AddAIAgents().Build(); |
| 232 | + var agent = app.Services.GetRequiredKeyedService<AIAgent>("bot"); |
| 233 | + var options = agent.GetService<ChatClientAgentOptions>(); |
| 234 | + |
| 235 | + var grok = Assert.IsType<GrokChatOptions>(options?.ChatOptions); |
| 236 | + |
| 237 | + Assert.Equal(ReasoningEffort.Low, grok.ReasoningEffort); |
| 238 | + Assert.Equal(GrokSearch.Auto, grok.Search); |
| 239 | + |
| 240 | + var configuration = (IConfigurationRoot)app.Services.GetRequiredService<IConfiguration>(); |
| 241 | + configuration["ai:agents:bot:options:reasoningeffort"] = "high"; |
| 242 | + configuration["ai:agents:bot:options:search"] = "off"; |
| 243 | + // NOTE: the in-memory provider does not support reload on change, so we must trigger it manually. |
| 244 | + configuration.Reload(); |
| 245 | + |
| 246 | + options = agent.GetService<ChatClientAgentOptions>(); |
| 247 | + grok = Assert.IsType<GrokChatOptions>(options?.ChatOptions); |
| 248 | + |
| 249 | + Assert.Equal(ReasoningEffort.High, grok.ReasoningEffort); |
| 250 | + Assert.Equal(GrokSearch.Off, grok.Search); |
| 251 | + } |
214 | 252 | } |
215 | 253 |
|
0 commit comments