Skip to content

pull main#749

Merged
Bryan-Roe merged 0 commit intoBryan-Roe-ai:mainfrom
microsoft:main
Sep 28, 2025
Merged

pull main#749
Bryan-Roe merged 0 commit intoBryan-Roe-ai:mainfrom
microsoft:main

Conversation

@Bryan-Roe
Copy link
Collaborator

@Bryan-Roe Bryan-Roe commented Jun 16, 2025

Summary by Sourcery

Unify and extend Ollama chat client support across .NET and Python SDKs: refactor samples to use the new IChatClient API with streaming helpers, introduce DI and kernel builder extension methods for registering Ollama chat clients, add audio content support in the Python connector, enhance agent orchestration to expose streaming callbacks, and bolster coverage with new unit and integration tests.

New Features:

  • Add AddOllamaChatClient extension methods for IServiceCollection and IKernelBuilder to register Ollama IChatClient
  • Introduce Python connector support for AudioContent in MCP<->Kernel content conversions
  • Provide a vision sample using IChatClient to send images alongside text for Ollama models

Enhancements:

  • Refactor .NET chat completion samples to use IChatClient and IChatCompletionService with unified streaming helpers
  • Extend AgentOrchestration and AgentActor to support streaming callbacks via new OnIntermediateMessage and StreamingResponseCallback
  • Consolidate raw streaming content handling by renaming and using OutputOllamaSharpContent across samples
  • Update VectorData abstractions documentation with detailed feature list and updated API links

Tests:

  • Add comprehensive unit and integration tests for OllamaChatClient, including DI and kernel builder extensions, streaming and cancellation scenarios

Copilot AI review requested due to automatic review settings June 16, 2025 22:17
@sourcery-ai
Copy link

sourcery-ai bot commented Jun 16, 2025

Reviewer's Guide

This PR refactors the chat completion path to adopt a shared IChatClient interface, extends dependency injection and kernel builder to register chat clients, enhances the orchestration framework with streaming callbacks, adds Python connector audio support, updates vector data documentation, and delivers comprehensive unit and integration tests for the Ollama chat client.

Sequence diagram for orchestration streaming callback flow

sequenceDiagram
    actor User
    participant Orchestration as Orchestration
    participant AgentActor as AgentActor
    participant Agent as Agent
    participant Callback as StreamingResponseCallback
    User->>Orchestration: InvokeAsync(..., StreamingResponseCallback)
    Orchestration->>AgentActor: InvokeAsync(...)
    AgentActor->>Agent: InvokeStreamingAsync(..., OnIntermediateMessage)
    Agent-->>AgentActor: StreamingChatMessageContent
    AgentActor->>Callback: StreamingResponseCallback(streamedResponse, isFinal)
    Callback-->>User: (streamed message chunk)
    Note over AgentActor,Callback: Callback is invoked for each streamed message
    AgentActor-->>Orchestration: Final ChatMessageContent
    Orchestration-->>User: OrchestrationResult
Loading

Entity relationship diagram for VectorData.Abstractions documentation update

erDiagram
    VECTORSTORE ||--o{ VECTORSTORECOLLECTION : contains
    VECTORSTORECOLLECTION ||--o{ VECTORRECORD : has
    VECTORSTORE {
        string Id
        string Name
    }
    VECTORSTORECOLLECTION {
        string Id
        string Name
        Schema Schema
    }
    VECTORRECORD {
        string Id
        float[] Embedding
        string Metadata
    }
Loading

Class diagram for new and updated Ollama Chat Client registration extensions

classDiagram
    class IServiceCollection
    class IKernelBuilder
    class IChatClient
    class OllamaApiClient
    IServiceCollection <|.. OllamaServiceCollectionExtensions
    IKernelBuilder <|.. OllamaKernelBuilderExtensions
    OllamaApiClient ..|> IChatClient
    OllamaServiceCollectionExtensions : +AddOllamaChatClient(modelId, endpoint, serviceId)
    OllamaServiceCollectionExtensions : +AddOllamaChatClient(modelId, httpClient, serviceId)
    OllamaServiceCollectionExtensions : +AddOllamaChatClient(ollamaClient, serviceId)
    OllamaKernelBuilderExtensions : +AddOllamaChatClient(modelId, endpoint, serviceId)
    OllamaKernelBuilderExtensions : +AddOllamaChatClient(modelId, httpClient, serviceId)
    OllamaKernelBuilderExtensions : +AddOllamaChatClient(ollamaClient, serviceId)
    OllamaApiClient : +GetResponseAsync()
    OllamaApiClient : +GetStreamingResponseAsync()
    IChatClient <|.. OllamaApiClient
Loading

Class diagram for OrchestrationContext and streaming callback support

classDiagram
    class OrchestrationContext {
        +string Orchestration
        +TopicId Topic
        +OrchestrationResponseCallback? ResponseCallback
        +OrchestrationStreamingCallback? StreamingResponseCallback
        +ILoggerFactory LoggerFactory
        +CancellationToken Cancellation
    }
    class OrchestrationResponseCallback
    class OrchestrationStreamingCallback
    OrchestrationContext --> OrchestrationResponseCallback
    OrchestrationContext --> OrchestrationStreamingCallback
Loading

Class diagram for AgentActor streaming and callback changes

classDiagram
    class AgentActor {
        -AgentInvokeOptions _options
        +ValueTask<ChatMessageContent> InvokeAsync(IList<ChatMessageContent>, CancellationToken)
        +Task InvokeAsync(IList<ChatMessageContent>, AgentInvokeOptions, CancellationToken)
        +Task InvokeStreamingAsync(IList<ChatMessageContent>, AgentInvokeOptions, CancellationToken)
        +AgentInvokeOptions GetInvokeOptions(Func<ChatMessageContent, Task>)
        +AgentInvokeOptions CreateInvokeOptions(Func<ChatMessageContent, Task>)
    }
    class AgentInvokeOptions {
        +Func<ChatMessageContent, Task> OnIntermediateMessage
    }
    AgentActor --> AgentInvokeOptions
Loading

Class diagram for HandoffActor override of streaming options

classDiagram
    class HandoffActor {
        +AgentInvokeOptions CreateInvokeOptions(Func<ChatMessageContent, Task>)
    }
    HandoffActor --|> AgentActor
Loading

File-Level Changes

Change Details Files
Standardize chat samples and core code to use IChatClient and unified streaming logic
  • Samples now instantiate and use IChatClient instead of OllamaSharp.API
  • Introduced StreamChatClientMessageOutputAsync and OutputLastMessage helpers
  • Updated sample methods and names for streaming and raw representation handling
  • Replaced chatService.GetChatMessageContentAsync with chatClient.GetResponseAsync/GetStreamingResponseAsync
dotnet/samples/Concepts/ChatCompletion/Ollama_ChatCompletionStreaming.cs
dotnet/samples/Concepts/ChatCompletion/Ollama_ChatCompletion.cs
dotnet/samples/Concepts/ChatCompletion/Ollama_ChatCompletionWithVision.cs
dotnet/src/SemanticKernel.Abstractions/AI/ChatClient/ChatClientExtensions.cs
dotnet/src/InternalUtilities/samples/InternalUtilities/BaseTest.cs
Introduce AddOllamaChatClient extension methods for DI and kernel builder
  • Added three overloads in service collection to register IChatClient by endpoint, HttpClient, or existing client
  • Extended IKernelBuilder with corresponding AddOllamaChatClient methods
  • Integrated logging and kernel function invocation in builder
dotnet/src/Connectors/Connectors.Ollama/Extensions/OllamaServiceCollectionExtensions.DependencyInjection.cs
dotnet/src/Connectors/Connectors.Ollama/Extensions/OllamaKernelBuilderExtensions.cs
Extend orchestration and agents to support streaming callbacks
  • Added StreamingResponseCallback to OrchestrationContext and AgentOrchestration
  • Updated AgentActor to pass OnIntermediateMessage and branch between batch and streaming invoke
  • Refactored InvokeAsync/InvokeStreamingAsync for ChatMessageContent and StreamingChatMessageContent
  • Enhanced BaseOrchestrationTest with WriteResponse and WriteStreamedResponse helpers
  • Adjusted HandoffActor CreateInvokeOptions to accept messageHandler
dotnet/src/Agents/Orchestration/AgentActor.cs
dotnet/src/Agents/Orchestration/AgentOrchestration.cs
dotnet/src/Agents/Orchestration/OrchestrationContext.cs
dotnet/src/InternalUtilities/samples/AgentUtilities/BaseOrchestrationTest.cs
dotnet/src/Agents/Orchestration/Handoff/HandoffActor.cs
Enhance Python connectors with audio support
  • Extended MCP connector to convert AudioContent to/from kernel types
  • Updated OpenAPI plugin parser to handle AudioContent in call_tool payloads
python/semantic_kernel/connectors/mcp.py
python/semantic_kernel/connectors/openapi_plugin/openapi_parser.py
Update VectorData documentation and add NuGet guide
  • Enhanced VectorData.Abstractions PACKAGE.md with schema details and links
  • Added VECTORDATA-CONNECTORS-NUGET.md with connector overview and getting started steps
dotnet/src/VectorData/VectorData.Abstractions/PACKAGE.md
dotnet/nuget/VECTORDATA-CONNECTORS-NUGET.md
Add comprehensive unit and integration tests for Ollama chat client
  • New unit tests for OllamaChatClient functionality, streaming, options, cancellation and dispose
  • Unit tests for AddOllamaChatClient DI and kernel builder extensions
  • Integration tests for basic usage, streaming, options, DI and kernel builder scenarios
dotnet/src/Connectors/Connectors.Ollama.UnitTests/Services/OllamaChatClientTests.cs
dotnet/src/Connectors/Connectors.Ollama.UnitTests/Extensions/OllamaServiceCollectionExtensionsChatClientTests.cs
dotnet/src/Connectors/Connectors.Ollama.UnitTests/Extensions/OllamaKernelBuilderExtensionsChatClientTests.cs
dotnet/src/IntegrationTests/Connectors/Ollama/OllamaChatClientIntegrationTests.cs

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

This comment was marked as outdated.

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @Bryan-Roe - I've reviewed your changes - here's some feedback:

  • The C# samples use invalid list initializer syntax (e.g., List<ChatMessage> chatHistory = [ … ];); switch to new List<ChatMessage> { … } to ensure the code compiles.
  • In the Python MCP connector _call_tool loop, the isinstance check uses value instead of the loop variable item, which will bypass the intended filtering—update it to check item.
  • The three overloads in AddOllamaChatClient share nearly identical builder logic—consider extracting the common setup into a private helper to reduce duplication and simplify future maintenance.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The C# samples use invalid list initializer syntax (e.g., `List<ChatMessage> chatHistory = [ … ];`); switch to `new List<ChatMessage> { … }` to ensure the code compiles.
- In the Python MCP connector `_call_tool` loop, the `isinstance` check uses `value` instead of the loop variable `item`, which will bypass the intended filtering—update it to check `item`.
- The three overloads in `AddOllamaChatClient` share nearly identical builder logic—consider extracting the common setup into a private helper to reduce duplication and simplify future maintenance.

## Individual Comments

### Comment 1
<location> `dotnet/src/Agents/Orchestration/AgentActor.cs:100` </location>
<code_context>
-        // The vast majority of responses will be a single message.  Responses with multiple messages will have their content merged.
-        ChatMessageContent response = new(firstResponse?.Message.Role ?? AuthorRole.Assistant, string.Join("\n\n", responses.Select(response => response.Message)))
+        AgentInvokeOptions options = this.GetInvokeOptions(HandleMessage);
+        if (this.Context.StreamingResponseCallback == null)
+        {
+            // No need to utilize streaming if no callback is provided
</code_context>

<issue_to_address>
Non-streaming path discards the response

Assign the result of `InvokeAsync` to the `response` variable in the non-streaming branch to ensure the method returns the correct assistant message.
</issue_to_address>

### Comment 2
<location> `python/semantic_kernel/connectors/mcp.py:904` </location>
<code_context>
+                ] = []
                 if isinstance(value, list):
                     for item in value:
-                        if isinstance(value, (TextContent, ImageContent, BinaryContent, ChatMessageContent)):
+                        if isinstance(
+                            value, (TextContent, ImageContent, BinaryContent, AudioContent, ChatMessageContent)
</code_context>

<issue_to_address>
Incorrect variable used in isinstance check

The type check should be applied to `item` within the loop, not `value`. Use `isinstance(item, ...)` to check each element's type.
</issue_to_address>

### Comment 3
<location> `dotnet/src/VectorData/VectorData.Abstractions/PACKAGE.md:11` </location>
<code_context>
+- Abstractions include:
+  - Creating, listing and deleting collections with custom schema support.
+  - Creating, retrieving, updating and deleting records.
+  - Similarty search using vector embeddings.
+  - Search using filters.
+  - Hybrid search combining vector similarity and keyword search.
</code_context>

<issue_to_address>
Typo: 'Similarty' should be 'Similarity'.

Update the bullet point to use the correct spelling: 'Similarity'.
</issue_to_address>

<suggested_fix>
<<<<<<< SEARCH
  - Similarty search using vector embeddings.
=======
  - Similarity search using vector embeddings.
>>>>>>> REPLACE

</suggested_fix>

### Comment 4
<location> `dotnet/src/Connectors/Connectors.Ollama/Extensions/OllamaServiceCollectionExtensions.DependencyInjection.cs:28` </location>
<code_context>
+    /// <param name="endpoint">The endpoint to Ollama hosted service.</param>
+    /// <param name="serviceId">Optional service ID.</param>
+    /// <returns>The updated service collection.</returns>
+    public static IServiceCollection AddOllamaChatClient(
+        this IServiceCollection services,
+        string modelId,
</code_context>

<issue_to_address>
Consider refactoring the repeated client building and registration logic into shared private helper methods to reduce duplication across overloads.

Consider extracting the common “build & configure” logic into a single helper and a shared private registration method. This removes the duplication in each overload while keeping your three public APIs.

```csharp
// 1) common builder helper
private static IChatClient BuildChatClient(
    OllamaApiClient client,
    IServiceProvider sp,
    ILoggerFactory? loggerFactory)
{
    var builder = client.AsBuilder();
    if (loggerFactory is not null)
    {
        builder.UseLogging(loggerFactory);
    }

    return builder
        .UseKernelFunctionInvocation(loggerFactory)
        .Build(sp);
}

// 2) shared registration impl
private static IServiceCollection AddOllamaChatClientImpl(
    this IServiceCollection services,
    Func<IServiceProvider, OllamaApiClient> clientFactory,
    string? serviceId)
{
    Verify.NotNull(services);

    return services.AddKeyedSingleton<IChatClient>(
        serviceId,
        (sp, _) =>
        {
            var loggerFactory = sp.GetService<ILoggerFactory>();
            var client = clientFactory(sp);
            return BuildChatClient(client, sp, loggerFactory);
        });
}

// 3) public overloads now delegate

public static IServiceCollection AddOllamaChatClient(
    this IServiceCollection services,
    string modelId,
    Uri endpoint,
    string? serviceId = null)
    => services.AddOllamaChatClientImpl(
        sp => new OllamaApiClient(endpoint, modelId),
        serviceId);

public static IServiceCollection AddOllamaChatClient(
    this IServiceCollection services,
    string modelId,
    HttpClient? httpClient = null,
    string? serviceId = null)
    => services.AddOllamaChatClientImpl(
        sp =>
        {
            httpClient ??= HttpClientProvider.GetHttpClient(httpClient, sp);
            return new OllamaApiClient(httpClient, modelId);
        },
        serviceId);

public static IServiceCollection AddOllamaChatClient(
    this IServiceCollection services,
    OllamaApiClient? ollamaClient = null,
    string? serviceId = null)
    => services.AddOllamaChatClientImpl(
        sp =>
        {
            // existing resolution logic
            var client = ollamaClient
                ?? sp.GetKeyedService<OllamaApiClient>(serviceId)
                ?? sp.GetKeyedService<IOllamaApiClient>(serviceId) as OllamaApiClient
                ?? sp.GetService<OllamaApiClient>()
                ?? sp.GetRequiredService<IOllamaApiClient>() as OllamaApiClient
                ?? throw new InvalidOperationException($"No {nameof(IOllamaApiClient)} found");
            return client;
        },
        serviceId);
```

Repeat the same pattern in the Embeddings region. This preserves all three overloads but centralizes the common build/configure routine.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@Bryan-Roe Bryan-Roe requested a review from Copilot June 18, 2025 02:15
@Bryan-Roe Bryan-Roe self-assigned this Jun 18, 2025

This comment was marked as outdated.

This comment was marked as outdated.

Copy link
Collaborator Author

@Bryan-Roe Bryan-Roe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

k

@Bryan-Roe Bryan-Roe removed their assignment Aug 7, 2025
@Bryan-Roe Bryan-Roe added this to the Code Builds Clean milestone Aug 7, 2025
@Bryan-Roe Bryan-Roe added the help wanted Extra attention is needed label Aug 7, 2025
@Bryan-Roe Bryan-Roe marked this pull request as draft August 7, 2025 11:46
@Bryan-Roe Bryan-Roe requested a review from Copilot August 7, 2025 15:17
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This pull request implements a major refactoring to unify and extend Ollama chat client support across .NET and Python SDKs, introducing new IChatClient API support, dependency injection extensions, and enhanced agent orchestration capabilities.

  • Refactored .NET chat completion samples to use IChatClient with unified streaming helpers
  • Added comprehensive Ollama chat client integration including DI container and kernel builder extensions
  • Enhanced agent orchestration with streaming callbacks and improved test coverage across multiple agent types

Reviewed Changes

Copilot reviewed 294 out of 783 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
dotnet/src/Plugins/Plugins.UnitTests/Plugins.UnitTests.csproj Updated package reference from Microsoft.Extensions.TimeProvider.Testing to System.Linq.AsyncEnumerable
dotnet/src/Plugins/Plugins.UnitTests/Memory/VolatileMemoryStoreTests.cs Replaced .ToEnumerable() calls with async equivalents (.ToArrayAsync(), .ToListAsync())
dotnet/src/Plugins/Plugins.StructuredData.EntityFramework/StructuredDataServiceExtensions.cs Renamed SelectAsync function to Select for consistency
dotnet/src/Plugins/Plugins.StructuredData.EntityFramework/StructuredDataService.cs Added conditional compilation for OData library imports (NET8+ uses OData2Linq, older versions use Community.OData.Linq)
dotnet/src/InternalUtilities/src/Linq/AsyncEnumerable.cs Extended with new async enumerable methods including Cast, Reverse, FirstAsync, LastAsync, SingleAsync, ToArrayAsync, Where, and OrderBy
dotnet/src/IntegrationTests/Connectors/Ollama/OllamaChatClientIntegrationTests.cs Added comprehensive integration tests for Ollama chat client including DI registration and kernel builder extensions
dotnet/src/Functions/Functions.OpenApi/Serialization/OpenApiTypeConverter.cs Enhanced type conversion to support JsonElement inputs alongside existing types
dotnet/src/Connectors/Connectors.OpenAI/Settings/OpenAIPromptExecutionSettings.cs Added PrepareChatHistoryForRequest method to automatically inject system and developer prompts

Comment on lines 552 to 563
// Inserts system and developer prompts at the beginning of the chat history if they are not already present.
if (!string.IsNullOrWhiteSpace(this.ChatDeveloperPrompt) && !chatHistory.Any(m => m.Role == AuthorRole.Developer))
{
chatHistory.Insert(0, new ChatMessageContent(AuthorRole.Developer, this.ChatDeveloperPrompt));
}

if (!string.IsNullOrWhiteSpace(this.ChatSystemPrompt) && !chatHistory.Any(m => m.Role == AuthorRole.System))
{
chatHistory.Insert(0, new ChatMessageContent(AuthorRole.System, this.ChatSystemPrompt));
}

return chatHistory;
Copy link

Copilot AI Aug 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The method mutates the input ChatHistory parameter by inserting messages at index 0, which could cause unexpected side effects for callers. Consider returning a new ChatHistory instance or clearly documenting that the input parameter will be modified.

Suggested change
// Inserts system and developer prompts at the beginning of the chat history if they are not already present.
if (!string.IsNullOrWhiteSpace(this.ChatDeveloperPrompt) && !chatHistory.Any(m => m.Role == AuthorRole.Developer))
{
chatHistory.Insert(0, new ChatMessageContent(AuthorRole.Developer, this.ChatDeveloperPrompt));
}
if (!string.IsNullOrWhiteSpace(this.ChatSystemPrompt) && !chatHistory.Any(m => m.Role == AuthorRole.System))
{
chatHistory.Insert(0, new ChatMessageContent(AuthorRole.System, this.ChatSystemPrompt));
}
return chatHistory;
// Create a new ChatHistory instance to avoid mutating the input parameter.
var newChatHistory = new ChatHistory();
// Insert system and developer prompts at the beginning if not already present.
if (!string.IsNullOrWhiteSpace(this.ChatSystemPrompt) && !chatHistory.Any(m => m.Role == AuthorRole.System))
{
newChatHistory.Add(new ChatMessageContent(AuthorRole.System, this.ChatSystemPrompt));
}
if (!string.IsNullOrWhiteSpace(this.ChatDeveloperPrompt) && !chatHistory.Any(m => m.Role == AuthorRole.Developer))
{
newChatHistory.Add(new ChatMessageContent(AuthorRole.Developer, this.ChatDeveloperPrompt));
}
// Add the rest of the original chat history messages.
foreach (var message in chatHistory)
{
newChatHistory.Add(message);
}
return newChatHistory;

Copilot uses AI. Check for mistakes.
Comment on lines 263 to 265
var keys = results.Select(keySelector).ToArray();
Array.Sort(keys, results);
foreach (var result in results)
Copy link

Copilot AI Aug 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The OrderBy implementation sorts arrays in-place but may not work correctly for all key types. The Array.Sort(keys, results) assumes that the key array can be sorted alongside the results array, but this will fail if TKey doesn't implement IComparable. Consider using a more robust sorting approach with key-value pairs.

Suggested change
var keys = results.Select(keySelector).ToArray();
Array.Sort(keys, results);
foreach (var result in results)
foreach (var result in results.OrderBy(keySelector))

Copilot uses AI. Check for mistakes.
{
string stringArgument => JsonValue.Create(long.Parse(stringArgument, CultureInfo.InvariantCulture)),
byte or sbyte or short or ushort or int or uint or long or ulong => JsonValue.Create(argument),
JsonElement jsonElement when jsonElement.TryGetInt64(out var intValue) => JsonValue.Create(intValue),
Copy link

Copilot AI Aug 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The JsonElement handling for integer type conversion may lose precision for large numbers. TryGetInt64 will fail for numbers that exceed long.MaxValue, but the original value might be a valid integer. Consider handling different numeric ranges or documenting the precision limitations.

Suggested change
JsonElement jsonElement when jsonElement.TryGetInt64(out var intValue) => JsonValue.Create(intValue),
JsonElement jsonElement when jsonElement.TryGetInt64(out var intValue) => JsonValue.Create(intValue),
JsonElement jsonElement when jsonElement.ValueKind == JsonValueKind.Number && jsonElement.TryGetRawText(out var rawText) => JsonValue.Create(jsonElement.GetRawText()),

Copilot uses AI. Check for mistakes.
@Bryan-Roe Bryan-Roe marked this pull request as ready for review August 9, 2025 04:24
@Bryan-Roe Bryan-Roe merged commit 51f4fe5 into Bryan-Roe-ai:main Sep 28, 2025
1 check failed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

help wanted Extra attention is needed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant