Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jan 3, 2026

  • Create GrokEmbeddingGenerator class implementing IEmbeddingGenerator<string, Embedding<float>>
  • Add extension methods to GrokClientExtensions for creating embedding generators
  • Add null validation to extension methods
  • Create tests for the new embedding generator implementation
  • Ensure build and tests pass
  • Address code review feedback: use pattern matching for null check

Summary

This PR implements the IEmbeddingGenerator<string, Embedding<float>> interface on top of the Embedder.EmbedderClient from the xAI Protocol. The implementation follows the same patterns as the existing GrokChatClient implementation and the reference OpenAI implementation from the dotnet/extensions repository.

Changes

  1. New GrokEmbeddingGenerator class (src/xAI/GrokEmbeddingGenerator.cs)

    • Implements IEmbeddingGenerator<string, Embedding<float>>
    • GenerateAsync method converts input strings to EmbedInput protocol messages and calls the gRPC Embed service
    • Supports model ID from options or default
    • Supports EndUserId from client options
    • GetService implementation returns metadata and underlying client
    • Maps EmbeddingUsage response to UsageDetails
  2. Extension methods in GrokClientExtensions (src/xAI/GrokClientExtensions.cs)

    • AsIEmbeddingGenerator(this GrokClient client, string defaultModelId)
    • AsIEmbeddingGenerator(this Embedder.EmbedderClient client, string defaultModelId)
    • Added null validation using Throw.IfNull for all extension methods
  3. Comprehensive tests (src/xAI.Tests/EmbeddingGeneratorTests.cs)

    • Integration test with actual API (requires XAI_API_KEY)
    • Null argument validation
    • Metadata retrieval
    • GetService returning proper types
    • Full request/response flow with usage details
    • Missing usage handling
    • Custom model ID support
Original prompt

This section details on the original issue you should resolve

<issue_title>Implement IEmbeddingGenerator interface on top of Embedder.EmbedderClient</issue_title>
<issue_description>Inspect how OpenAI is implemented:

Back this issue
Back this issue

<agent_instructions>Create implementation and tests</agent_instructions>

Comments on the Issue (you are @copilot in this section)


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

@kzu
Copy link
Member

kzu commented Jan 3, 2026

26 passed 26 passed 13 skipped

🧪 Details on Ubuntu 24.04.3 LTS

from retest v1.1.0 on .NET 10.0.1 with 💜 by @devlooped

Copilot AI changed the title [WIP] Implement IEmbeddingGenerator interface on EmbedderClient Implement IEmbeddingGenerator interface on top of Embedder.EmbedderClient Jan 3, 2026
Copilot AI requested a review from kzu January 3, 2026 22:25
Copilot finished work on behalf of kzu January 3, 2026 22:25
Copy link
Contributor Author

Copilot AI commented Jan 5, 2026

Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • pkg.kzu.app
    • Triggering command: /usr/bin/dotnet dotnet build src/xAI/xAI.csproj (dns block)
    • Triggering command: /usr/bin/dotnet dotnet build src/xAI/xAI.csproj --ignore-failed-sources (dns block)
    • Triggering command: /usr/bin/dotnet dotnet run --file protofix.cs /home/REDACTED/work/xAI/xAI/src/xAI.Protocol (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot AI requested a review from kzu January 5, 2026 13:24
Copilot finished work on behalf of kzu January 5, 2026 13:24
@kzu kzu closed this Jan 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement IEmbeddingGenerator interface on top of Embedder.EmbedderClient

2 participants