-
Notifications
You must be signed in to change notification settings - Fork 30
Update to M.E.AI.Abstractions 9.9 #75
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
WalkthroughUpdates to MicrosoftExtensions.cs modify system instruction construction and overhaul tool handling to support AIFunctionDeclaration, HostedWebSearchTool, and HostedCodeInterpreterTool. The request.Tools assembly now separates function declarations from hosted tools. The csproj updates Microsoft.Extensions.AI.Abstractions to 9.9.0. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
participant Caller
participant MicrosoftExtensions as MicrosoftExtensions.ToGenerateContentRequest
participant Options as options
participant Request as GenerateContentRequest
Caller->>MicrosoftExtensions: ToGenerateContentRequest(options)
MicrosoftExtensions->>Options: Read system parts + Instructions
rect rgba(230,240,255,0.5)
note right of MicrosoftExtensions: Build SystemInstruction
MicrosoftExtensions->>Request: Set SystemInstruction<br/>(system parts + optional Instructions Part)
end
MicrosoftExtensions->>Options: Iterate Tools
alt Tool is AIFunctionDeclaration
MicrosoftExtensions->>MicrosoftExtensions: Accumulate FunctionDeclarations
else Tool is HostedWebSearchTool
MicrosoftExtensions->>MicrosoftExtensions: Add Tool.GoogleSearch
else Tool is HostedCodeInterpreterTool
MicrosoftExtensions->>MicrosoftExtensions: Add Tool.CodeExecution
end
rect rgba(240,230,255,0.5)
note right of MicrosoftExtensions: Assemble request.Tools
MicrosoftExtensions->>Request: Set Tools { FunctionDeclarations?, Tools? }
end
MicrosoftExtensions-->>Caller: GenerateContentRequest
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Poem
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches
🧪 Generate unit tests
Tip 👮 Agentic pre-merge checks are now available in preview!Pro plan users can now enable pre-merge checks in their settings to enforce checklists before merging PRs.
Please see the documentation for more information. Example: reviews:
pre_merge_checks:
custom_checks:
- name: "Undocumented Breaking Changes"
mode: "warning"
instructions: |
Pass/fail criteria: All breaking changes to public APIs, CLI flags, environment variables, configuration keys, database schemas, or HTTP/GraphQL endpoints must be documented in the "Breaking Change" section of the PR description and in CHANGELOG.md. Exclude purely internal or private changes (e.g., code not exported from package entry points or explicitly marked as internal).Please share your feedback with us on this Discord post. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
src/GenerativeAI.Microsoft/Extensions/MicrosoftExtensions.cs (1)
98-123: Harden JSON schema parsing to avoid KeyNotFound and handle non‑object schemas.GetProperty("properties") throws if absent; ValueKind can be Undefined; primitive/array schemas should still be converted.
- if (schema.ValueKind == JsonValueKind.Null) + if (schema.ValueKind is JsonValueKind.Null or JsonValueKind.Undefined) return null; - else - { - var properties = schema.GetProperty("properties"); - if (properties.GetPropertyCount() == 0) - return null; - else - { - var node = schema.AsNode(); - if (node != null) - { - // Clone the node to avoid modifying the original schema - var clonedNode = node.DeepClone(); - ApplySchemaTransformations(clonedNode); - return GoogleSchemaHelper.ConvertToCompatibleSchemaSubset(clonedNode); - } - return null; - } - } + if (schema.ValueKind != JsonValueKind.Object) + { + var node = schema.AsNode(); + return node != null ? GoogleSchemaHelper.ConvertToCompatibleSchemaSubset(node) : null; + } + if (!schema.TryGetProperty("properties", out var properties) || properties.GetPropertyCount() == 0) + return null; + var node = schema.AsNode(); + if (node == null) return null; + var clonedNode = node.DeepClone(); + ApplySchemaTransformations(clonedNode); + return GoogleSchemaHelper.ConvertToCompatibleSchemaSubset(clonedNode);
🧹 Nitpick comments (2)
src/GenerativeAI.Microsoft/Extensions/MicrosoftExtensions.cs (2)
594-597: Avoid repeated schema lookups/serialization in recursive transformer.Each recursion serializes function.JsonSchema and re‑looks up the function by name. Cache the function declaration and its JsonNode once per top‑level call or thread‑local context and thread it through recursive calls.
If you prefer minimal change: hoist the function lookup and JsonSerializer.SerializeToNode(...) above recursion and pass as an extra parameter.
Also applies to: 727-733, 777-783
1077-1109: Unify schema transformations to one path.ApplySchemaTransformations and s_schemaTransformerCache perform overlapping format rewrites. Prefer one mechanism (ideally the cache) to prevent drift.
Would you like a follow‑up diff to route ParseFunctionParameters through s_schemaTransformerCache?
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
src/GenerativeAI.Microsoft/Extensions/MicrosoftExtensions.cs(5 hunks)src/GenerativeAI.Microsoft/GenerativeAI.Microsoft.csproj(1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
src/GenerativeAI.Microsoft/Extensions/MicrosoftExtensions.cs (5)
src/GenerativeAI/Types/ContentGeneration/Inputs/Content.cs (4)
Content(11-58)Content(16-19)Content(25-29)Content(40-44)src/GenerativeAI.Tools/Helpers/FunctionSchemaHelper.cs (1)
FunctionDeclaration(21-61)src/GenerativeAI.Tools/GenericFunctionTool.cs (1)
Tool(41-52)src/GenerativeAI/Types/ContentGeneration/Tools/GoogleSearch/GoogleSearchTool.cs (1)
GoogleSearchTool(7-10)src/GenerativeAI/Types/ContentGeneration/Tools/CodeExecution/CodeExecutionTool.cs (1)
CodeExecutionTool(8-11)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: build (9.0.x)
🔇 Additional comments (2)
src/GenerativeAI.Microsoft/Extensions/MicrosoftExtensions.cs (1)
48-93: Tools assembly looks correct; confirm request.Tools shape matches API.Collecting FunctionDeclarations into a single Tool and adding hosted GoogleSearch/CodeExecution tools aligns with the Gemini Tool model.
Please validate at runtime that the resulting JSON matches the API (function_declarations grouped under a single tool, separate entries for google_search/code_execution). If helpful, log the serialized request in a dev build.
src/GenerativeAI.Microsoft/GenerativeAI.Microsoft.csproj (1)
35-35: Version bump to 9.9.0 — verify API alignment across repoNuGet/docs confirm Microsoft.Extensions.AI.Abstractions v9.9.0 exposes AIFunction/AIFunctionDeclaration and hosted-tool helpers; the repository scan didn't run (rg reported "No files were searched"). Re-run a repo-wide search and confirm there are no remaining references to pre-9.9 types (AIFunction, AIFunctionDeclaration, Hosted*Tool) and that CI uses an SDK including 9.9 APIs.
Suggested search:
rg -nP -C2 --hidden --no-ignore -S '\bAIFunction\b|\bAIFunctionDeclaration\b|Hosted(OpenAI|Bing|Search)Tool\b' --glob '!/bin/' --glob '!/obj/'
| if (systemParts.Length > 0 || !string.IsNullOrWhiteSpace(options?.Instructions)) | ||
| { | ||
| request.SystemInstruction = new Content(systemParts, Roles.System); | ||
| request.SystemInstruction = new Content(systemParts.Concat([new Part { Text = options!.Instructions }]), Roles.System); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix NRE when options is null; append instructions only when present.
If systemParts.Length > 0 and options is null, options!.Instructions dereferences null. Also avoid appending an empty instruction.
Apply:
- if (systemParts.Length > 0 || !string.IsNullOrWhiteSpace(options?.Instructions))
- {
- request.SystemInstruction = new Content(systemParts.Concat([new Part { Text = options!.Instructions }]), Roles.System);
- }
+ if (systemParts.Length > 0 || !string.IsNullOrWhiteSpace(options?.Instructions))
+ {
+ IEnumerable<Part> sys = systemParts;
+ if (!string.IsNullOrWhiteSpace(options?.Instructions))
+ {
+ sys = sys.Concat(new[] { new Part { Text = options!.Instructions! } });
+ }
+ request.SystemInstruction = new Content(sys.ToArray(), Roles.System);
+ }📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| if (systemParts.Length > 0 || !string.IsNullOrWhiteSpace(options?.Instructions)) | |
| { | |
| request.SystemInstruction = new Content(systemParts, Roles.System); | |
| request.SystemInstruction = new Content(systemParts.Concat([new Part { Text = options!.Instructions }]), Roles.System); | |
| } | |
| if (systemParts.Length > 0 || !string.IsNullOrWhiteSpace(options?.Instructions)) | |
| { | |
| IEnumerable<Part> sys = systemParts; | |
| if (!string.IsNullOrWhiteSpace(options?.Instructions)) | |
| { | |
| sys = sys.Concat(new[] { new Part { Text = options!.Instructions! } }); | |
| } | |
| request.SystemInstruction = new Content(sys.ToArray(), Roles.System); | |
| } |
🤖 Prompt for AI Agents
In src/GenerativeAI.Microsoft/Extensions/MicrosoftExtensions.cs around lines
36–39, the current code dereferences options with options! and always appends
options.Instructions which causes a NullReferenceException when options is null
and can append empty instructions; change the conditional logic to only access
options.Instructions when options is not null and not whitespace, build the
SystemInstruction parts sequence so that you only concatenate an instruction
Part when that check passes (otherwise use systemParts alone), and avoid forcing
a null-forgiving operator.
Summary by CodeRabbit
New Features
Improvements
Chores