Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions src/xAI/GrokClient.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Collections.Concurrent;
using System.Net.Http.Headers;
using Grpc.Net.Client;
using xAI.Protocol;

namespace xAI;

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

/// <summary>Gets a new instance of <see cref="Auth.AuthClient"/> that reuses the client configuration details provided to the <see cref="GrokClient"/> instance.</summary>
public Auth.AuthClient GetAuthClient() => new(Channel);

/// <summary>Gets a new instance of <see cref="Chat.ChatClient"/> that reuses the client configuration details provided to the <see cref="GrokClient"/> instance.</summary>
public Chat.ChatClient GetChatClient() => new(Channel);

/// <summary>Gets a new instance of <see cref="Documents.DocumentsClient"/> that reuses the client configuration details provided to the <see cref="GrokClient"/> instance.</summary>
public Documents.DocumentsClient GetDocumentsClient() => new(Channel);

/// <summary>Gets a new instance of <see cref="Embedder.EmbedderClient"/> that reuses the client configuration details provided to the <see cref="GrokClient"/> instance.</summary>
public Embedder.EmbedderClient GetEmbedderClient() => new(Channel);

/// <summary>Gets a new instance of <see cref="Image.ImageClient"/> that reuses the client configuration details provided to the <see cref="GrokClient"/> instance.</summary>
public Image.ImageClient GetImageClient() => new(Channel);

/// <summary>Gets a new instance of <see cref="Models.ModelsClient"/> that reuses the client configuration details provided to the <see cref="GrokClient"/> instance.</summary>
public Models.ModelsClient GetModelsClient() => new(Channel);

/// <summary>Gets a new instance of <see cref="Tokenize.TokenizeClient"/> that reuses the client configuration details provided to the <see cref="GrokClient"/> instance.</summary>
public Tokenize.TokenizeClient GetTokenizeClient() => new(Channel);

internal GrpcChannel Channel => channels.GetOrAdd((Endpoint, ApiKey), key =>
{
var handler = new AuthenticationHeaderHandler(ApiKey)
Expand Down
7 changes: 6 additions & 1 deletion src/xAI/GrokClientExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.ComponentModel;
using Microsoft.Extensions.AI;
using xAI.Protocol;

namespace xAI;

Expand All @@ -10,4 +11,8 @@ public static class GrokClientExtensions
/// <summary>Creates a new <see cref="IChatClient"/> from the specified <see cref="GrokClient"/> using the given model as the default.</summary>
public static IChatClient AsIChatClient(this GrokClient client, string defaultModelId)
=> new GrokChatClient(client.Channel, client.Options, defaultModelId);
}

/// <summary>Creates a new <see cref="IChatClient"/> from the specified <see cref="Chat.ChatClient"/> using the given model as the default.</summary>
public static IChatClient AsIChatClient(this Chat.ChatClient client, string defaultModelId)
=> new GrokChatClient(client, defaultModelId);
}