Repository navigation
[C#] Expose cached Generator through IChatClient.GetService - #2475
kunal-vaishnavi merged 1 commit into
Conversation
|
Azure Pipelines: There may be pipelines that require an authorized user to comment /azp run to run. |
db92295 to
387dcd9
Compare
There was a problem hiding this comment.
Pull request overview
This PR updates the C# OnnxRuntimeGenAIChatClient to expose the currently cached Generator instance via IChatClient.GetService<Generator>(serviceKey: null), enabling advanced callers to perform operations like RewindTo between requests while keeping ownership and lifecycle with the chat client.
Changes:
- Expose the cached
GeneratorfromIChatClient.GetServicewhen requested with a null service key. - Use
Volatile.Readfor consistent, thread-safe cache access alongside existingInterlockedupdates. - Add a C# test validating the
Generatorservice is unavailable before a request and available after a cached request completes.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/csharp/OnnxRuntimeGenAIChatClient.cs | Exposes the cached generator via GetService and documents borrowing/lifetime constraints. |
| test/csharp/TestOnnxRuntimeGenAIAPI.cs | Adds a unit test covering GetService<Generator>(null) behavior with caching enabled. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
|
@microsoft-github-policy-service agree |
387dcd9 to
d3cffb4
Compare
|
Hi Baiju Meswani (@baijumeswani), friendly ping on this small C# PR addressing #1553. It exposes the cached Generator through IChatClient.GetService, with lifetime/concurrency documentation and tiny-model test coverage. The GitHub Actions runs are still awaiting maintainer approval, and Azure Pipelines also needs an authorized trigger. Could you please take a look or route it to the appropriate reviewer? Thanks! |
kunal-vaishnavi
left a comment
There was a problem hiding this comment.
Thanks for your contribution!
|
Thanks for the review, kunal-vaishnavi! The new C# test passed in CI. The only failing check is Linux CUDA, where test_engine_run_releases_gil[cpu] failed at worker_progressed.is_set() (76 passed, 1 failed). This appears unrelated to the C#-only changes. Could you please rerun the failed job? |
|
/azp run macOS arm64 Build |
|
Azure Pipelines: Successfully started running 1 pipeline(s). |
d3cffb4 to
0deaf4a
Compare
|
/azp run macOS arm64 Build |
|
Azure Pipelines: Successfully started running 1 pipeline(s). |
Description
Expose the currently cached
GeneratorthroughIChatClient.GetService<Generator>(). This enables callers to retrieve it between requests for operations such asRewindTo.The returned generator remains owned by the chat client and is documented as a borrowed reference. Callers must not dispose it, retain it across requests, or use it concurrently with an active request.
Changes
Generatorwhen requested without a service key.Volatile.Readto access the cache consistently with its existing interlocked updates.Testing
dotnet build src/csharp/Microsoft.ML.OnnxRuntimeGenAI.csproj --configuration Releasenet8.0andnetstandard2.0passed with 0 errors.dotnet test test/csharp/Microsoft.ML.OnnxRuntimeGenAI.Tests.csproj --configuration Release --no-buildTestChatClientGetServiceGeneratorFixes #1553