Skip to content

Commit 229c42c

Browse files
committed
Drop ctor overload not receiving a model
This will likely mean that sooner or later, an older enough library will default to a deprecated model and fail. So avoid that altogether.
1 parent 35ad864 commit 229c42c

File tree

3 files changed

+5
-23
lines changed

3 files changed

+5
-23
lines changed

src/AI.Tests/GrokTests.cs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public async Task GrokInvokesTools()
1616
{ "user", "What day is today?" },
1717
};
1818

19-
var chat = new GrokChatClient(Configuration["XAI_API_KEY"]!);
19+
var chat = new GrokChatClient(Configuration["XAI_API_KEY"]!, "grok-3");
2020

2121
var options = new GrokChatOptions
2222
{
@@ -143,15 +143,12 @@ public async Task GrokThinksHard()
143143
var messages = new Chat()
144144
{
145145
{ "system", "You are an intelligent AI assistant that's an expert on financial matters." },
146-
{ "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?" },
146+
{ "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)" },
147147
};
148148

149149
var grok = new GrokClient(Configuration["XAI_API_KEY"]!)
150150
.GetChatClient("grok-3")
151-
.AsIChatClient()
152-
.AsBuilder()
153-
.UseFunctionInvocation()
154-
.Build();
151+
.AsIChatClient();
155152

156153
var options = new GrokChatOptions
157154
{

src/AI/Grok/GrokChatClient.cs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,15 @@ namespace Devlooped.Extensions.AI;
1313
public class GrokChatClient : IChatClient
1414
{
1515
readonly ConcurrentDictionary<string, IChatClient> clients = new();
16-
readonly string apiKey;
1716
readonly string modelId;
1817
readonly ClientPipeline pipeline;
1918
readonly OpenAIClientOptions options;
2019

21-
/// <summary>
22-
/// Initializes the client with the specified API key and the default model ID "grok-3-mini".
23-
/// </summary>
24-
public GrokChatClient(string apiKey) : this(apiKey, "grok-3-mini", null) { }
25-
2620
/// <summary>
2721
/// Initializes the client with the specified API key, model ID, and optional OpenAI client options.
2822
/// </summary>
2923
public GrokChatClient(string apiKey, string modelId, OpenAIClientOptions? options = default)
3024
{
31-
this.apiKey = apiKey;
3225
this.modelId = modelId;
3326
this.options = options ?? new();
3427
this.options.Endpoint ??= new Uri("https://api.x.ai/v1");
@@ -79,9 +72,9 @@ IChatClient GetChatClient(string modelId) => clients.GetOrAdd(modelId, model
7972
{
8073
result.ReasoningEffortLevel = grok.ReasoningEffort switch
8174
{
82-
ReasoningEffort.Low => OpenAI.Chat.ChatReasoningEffortLevel.Low,
8375
ReasoningEffort.High => OpenAI.Chat.ChatReasoningEffortLevel.High,
84-
_ => throw new ArgumentException($"Unsupported reasoning effort {grok.ReasoningEffort}")
76+
// Grok does not support Medium, so we map it to Low too
77+
_ => OpenAI.Chat.ChatReasoningEffortLevel.Low,
8578
};
8679
}
8780

src/AI/GrokExtensions.cs

Lines changed: 0 additions & 8 deletions
This file was deleted.

0 commit comments

Comments
 (0)