You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
.Net: Add Ollama ChatClient Extensions + UT (#12476)
### Motivation and Context
Successfully implemented the missing AddOllamaChatClient extensions for
the Ollama Connector with comprehensive testing.:
## Key Features Implemented
Same Signature Patterns: All extensions follow the exact same parameter
signatures as the existing IChatCompletionService extensions
IChatClient Target: Returns IChatClient instead of
IChatCompletionService
Function Calling Support: Includes UseKernelFunctionInvocation() for
function calling capabilities
Comprehensive Testing: Full test coverage for all scenarios including
error handling, service registration, and functionality
Integration Ready: Integration tests are ready to run when secrets are
configured
- ### Implementation
- Extension Methods Added
- IServiceCollection Extensions: 3 overloads in
OllamaServiceCollectionExtensions.DependencyInjection.cs
- IKernelBuilder Extensions: 3 overloads in
OllamaKernelBuilderExtensions.cs
- ### 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
// Ollama Sharp does not support non-streaming and always perform streaming calls, for this reason, the inner content of a non-streaming result is a list of the generated chunks.
150
-
varmessageContent=functionResult.GetValue<ChatMessageContent>();// Retrieves underlying chat message content from FunctionResult.
151
-
varreplyInnerContent=messageContent!.InnerContentasChatDoneResponseStream;// Retrieves inner content from ChatMessageContent.
148
+
varmessageContent=functionResult.GetValue<ChatResponse>();// Retrieves underlying chat message content from FunctionResult.
149
+
varollamaSharpRawRepresentation=messageContent!.RawRepresentationasOllamaSharp.Models.Chat.ChatDoneResponseStream;// Retrieves inner content from ChatMessageContent.
chatHistory.Add(new(Microsoft.Extensions.AI.ChatRole.User,"I love history and philosophy, I'd like to learn something new about Greece, any suggestion?"));
@@ -51,58 +86,56 @@ public async Task UsingServiceStreamingWithOllama()
51
86
}
52
87
53
88
/// <summary>
54
-
/// This example demonstrates retrieving underlying library information through chat completion streaming inner contents.
89
+
/// This example demonstrates retrieving underlying OllamaSharp library information through <see cref="IChatClient" /> streaming raw representation (breaking glass) approach.
55
90
/// </summary>
56
91
/// <remarks>
57
92
/// This is a breaking glass scenario and is more susceptible to break on newer versions of OllamaSharp library.
0 commit comments