Skip to content

Add AddOllamaChatClient extensions for IChatClient interface#6

Open
rogerbarreto wants to merge 4 commits intomainfrom
issues/ollama-addchatclient
Open

Add AddOllamaChatClient extensions for IChatClient interface#6
rogerbarreto wants to merge 4 commits intomainfrom
issues/ollama-addchatclient

Conversation

@rogerbarreto
Copy link
Copy Markdown
Owner

Summary

Implements missing AddOllamaChatClient extension methods for the Ollama Connector targeting the IChatClient interface, following the same patterns as existing IChatCompletionService extensions.

Changes

🔧 Extension Methods Added

IServiceCollection Extensions (in OllamaServiceCollectionExtensions.DependencyInjection.cs):

  • AddOllamaChatClient(modelId, endpoint, serviceId) - Using URI endpoint
  • AddOllamaChatClient(modelId, httpClient, serviceId) - Using HttpClient
  • AddOllamaChatClient(ollamaClient, serviceId) - Using existing OllamaApiClient

IKernelBuilder Extensions (in OllamaKernelBuilderExtensions.cs):

  • AddOllamaChatClient(modelId, endpoint, serviceId) - Using URI endpoint
  • AddOllamaChatClient(modelId, httpClient, serviceId) - Using HttpClient
  • AddOllamaChatClient(ollamaClient, serviceId) - Using existing OllamaApiClient

🧪 Comprehensive Testing

Unit Tests Created:

  • OllamaServiceCollectionExtensionsChatClientTests.cs - 7 tests for service collection extensions
  • OllamaKernelBuilderExtensionsChatClientTests.cs - 6 tests for kernel builder extensions
  • OllamaChatClientTests.cs - 12 tests for IChatClient functionality

Integration Tests Created:

  • OllamaChatClientIntegrationTests.cs - 7 integration tests

🎯 Key Features

  • Same Signature Patterns: All extensions follow the exact same parameter signatures as existing IChatCompletionService extensions
  • IChatClient Target: Returns IChatClient instead of IChatCompletionService
  • Function Calling Support: Includes UseKernelFunctionInvocation() for function calling capabilities
  • No Experimental Attributes: Correctly inherits experimental nature from assembly-level [assembly: Experimental("SKEXP0070")]
  • Performance Optimized: All analyzer warnings resolved
  • Code Formatted: All files properly formatted with dotnet format

Test Results

  • 101 Tests Passing
  • ⏭️ 1 Test Skipped (expected - AutoFunctionInvocationFilter not supported)
  • 0 Tests Failed
  • ⚠️ 0 Warnings
  • 🏗️ Clean Build

Usage Examples

// Service Collection
services.AddOllamaChatClient("llama3.2", new Uri("http://localhost:11434"), "my-ollama");

// Kernel Builder
var kernel = Kernel.CreateBuilder()
    .AddOllamaChatClient("llama3.2", new Uri("http://localhost:11434"))
    .Build();

// Direct Usage
var chatClient = kernel.GetRequiredService<IChatClient>();
var response = await chatClient.GetResponseAsync(messages);

Files Modified/Created

Modified:

  • dotnet/src/Connectors/Connectors.Ollama/Extensions/OllamaServiceCollectionExtensions.DependencyInjection.cs
  • dotnet/src/Connectors/Connectors.Ollama/Extensions/OllamaKernelBuilderExtensions.cs

Created:

  • dotnet/src/Connectors/Connectors.Ollama.UnitTests/Extensions/OllamaServiceCollectionExtensionsChatClientTests.cs
  • dotnet/src/Connectors/Connectors.Ollama.UnitTests/Extensions/OllamaKernelBuilderExtensionsChatClientTests.cs
  • dotnet/src/Connectors/Connectors.Ollama.UnitTests/Services/OllamaChatClientTests.cs
  • dotnet/src/IntegrationTests/Connectors/Ollama/OllamaChatClientIntegrationTests.cs

The implementation is production-ready, follows all established patterns, includes comprehensive testing, and provides the same functionality as existing IChatCompletionService extensions but targeting the IChatClient interface instead.


Pull Request opened by Augment Code with guidance from the PR author

@rogerbarreto rogerbarreto deployed to integration June 16, 2025 13:50 — with GitHub Actions Active
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.

1 participant