Skip to content

Commit d7447fa

Browse files
committed
Expose specific protocol clients from GrokClient
This approach aligns with the approach in OpenAIClient.
1 parent d769fbc commit d7447fa

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

src/xAI/GrokClient.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System.Collections.Concurrent;
22
using System.Net.Http.Headers;
33
using Grpc.Net.Client;
4+
using xAI.Protocol;
45

56
namespace xAI;
67

@@ -23,6 +24,27 @@ public sealed class GrokClient(string apiKey, GrokClientOptions options) : IDisp
2324
/// <summary>Gets the options used to configure the client.</summary>
2425
public GrokClientOptions Options { get; } = options;
2526

27+
/// <summary>Gets a new instance of <see cref="Auth.AuthClient"/> that reuses the client configuration details provided to the <see cref="GrokClient"/> instance.</summary>
28+
public Auth.AuthClient GetAuthClient() => new(Channel);
29+
30+
/// <summary>Gets a new instance of <see cref="Chat.ChatClient"/> that reuses the client configuration details provided to the <see cref="GrokClient"/> instance.</summary>
31+
public Chat.ChatClient GetChatClient() => new(Channel);
32+
33+
/// <summary>Gets a new instance of <see cref="Documents.DocumentsClient"/> that reuses the client configuration details provided to the <see cref="GrokClient"/> instance.</summary>
34+
public Documents.DocumentsClient GetDocumentsClient() => new(Channel);
35+
36+
/// <summary>Gets a new instance of <see cref="Embedder.EmbedderClient"/> that reuses the client configuration details provided to the <see cref="GrokClient"/> instance.</summary>
37+
public Embedder.EmbedderClient GetEmbedderClient() => new(Channel);
38+
39+
/// <summary>Gets a new instance of <see cref="Image.ImageClient"/> that reuses the client configuration details provided to the <see cref="GrokClient"/> instance.</summary>
40+
public Image.ImageClient GetImageClient() => new(Channel);
41+
42+
/// <summary>Gets a new instance of <see cref="Models.ModelsClient"/> that reuses the client configuration details provided to the <see cref="GrokClient"/> instance.</summary>
43+
public Models.ModelsClient GetModelsClient() => new(Channel);
44+
45+
/// <summary>Gets a new instance of <see cref="Tokenize.TokenizeClient"/> that reuses the client configuration details provided to the <see cref="GrokClient"/> instance.</summary>
46+
public Tokenize.TokenizeClient GetTokenizeClient() => new(Channel);
47+
2648
internal GrpcChannel Channel => channels.GetOrAdd((Endpoint, ApiKey), key =>
2749
{
2850
var handler = new AuthenticationHeaderHandler(ApiKey)

src/xAI/GrokClientExtensions.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System.ComponentModel;
22
using Microsoft.Extensions.AI;
3+
using xAI.Protocol;
34

45
namespace xAI;
56

@@ -10,4 +11,8 @@ public static class GrokClientExtensions
1011
/// <summary>Creates a new <see cref="IChatClient"/> from the specified <see cref="GrokClient"/> using the given model as the default.</summary>
1112
public static IChatClient AsIChatClient(this GrokClient client, string defaultModelId)
1213
=> new GrokChatClient(client.Channel, client.Options, defaultModelId);
13-
}
14+
15+
/// <summary>Creates a new <see cref="IChatClient"/> from the specified <see cref="Chat.ChatClient"/> using the given model as the default.</summary>
16+
public static IChatClient AsIChatClient(this Chat.ChatClient client, string defaultModelId)
17+
=> new GrokChatClient(client, defaultModelId);
18+
}

0 commit comments

Comments
 (0)