Skip to content
Merged
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
9 changes: 8 additions & 1 deletion src/AI/Grok/GrokChatClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public partial class GrokChatClient : IChatClient
readonly string modelId;
readonly ClientPipeline pipeline;
readonly OpenAIClientOptions options;
readonly ChatClientMetadata metadata;

/// <summary>
/// Initializes the client with the specified API key, model ID, and optional OpenAI client options.
Expand All @@ -27,6 +28,7 @@ public GrokChatClient(string apiKey, string modelId, OpenAIClientOptions? option
this.modelId = modelId;
this.options = options ?? new();
this.options.Endpoint ??= new Uri("https://api.x.ai/v1");
metadata = new ChatClientMetadata("x.ai", this.options.Endpoint, modelId);

// NOTE: by caching the pipeline, we speed up creation of new chat clients per model,
// since the pipeline will be the same for all of them.
Expand Down Expand Up @@ -114,7 +116,12 @@ IChatClient GetChatClient(string modelId) => clients.GetOrAdd(modelId, model

void IDisposable.Dispose() { }

public object? GetService(Type serviceType, object? serviceKey = null) => null;
/// <inheritdoc />
public object? GetService(Type serviceType, object? serviceKey = null) => serviceType switch
{
Type t when t == typeof(ChatClientMetadata) => metadata,
_ => null
};

// Allows creating the base OpenAIClient with a pre-created pipeline.
class PipelineClient(ClientPipeline pipeline, OpenAIClientOptions options) : OpenAIClient(pipeline, options) { }
Expand Down
Loading