Skip to content

Conversation

@gunpal5
Copy link
Collaborator

@gunpal5 gunpal5 commented Mar 23, 2025

Summary by CodeRabbit

  • New Features

    • Enhanced schema conversion to handle cases with no properties.
    • Introduced new methods for retrieving student records and book details.
    • Added lightweight function tools that can be invoked without input parameters.
  • Tests

    • Expanded automated tests to validate the new function tools and endpoint behaviors.
  • Refactor

    • Improved code formatting and readability for better maintainability.

@coderabbitai
Copy link

coderabbitai bot commented Mar 23, 2025

Walkthrough

The pull request updates several components across the project. In the schema helper, the ConvertToSchema method now returns a nullable schema and includes a new early-exit check when there are no properties. New test methods were added in AOT and MEAI test suites, and corresponding static function tool methods were introduced to the tools class. Additionally, a new method for retrieving books was added to the book service, and two new methods for fetching student records were implemented. Minor formatting adjustments and whitespace changes were applied throughout.

Changes

File(s) Change Summary
src/libs/.../SchemaSubsetHelper.cs Updated ConvertToSchema to return OpenApiSchema? with an early null-check when no properties exist; adjusted formatting and parameter layout in ExtractDescription.
src/tests/.../AotTests/MethodFunctionTools_Tests.cs
src/tests/.../AotTests/Services/MethodFunctionTools.cs
Added two new test methods to verify function tool methods and two new static methods (SampleFunctionTool_Static_No_Parameters and SampleFunctionTool_No_Parameters) that return a greeting string.
src/tests/.../IntegrationTests/MethodFunctionTools.cs Inserted two blank lines at the end of the SampleFunctionTool_Static_String method for formatting consistency.
src/tests/.../MeaiTests/(Meai_Tests.cs, BookService.cs, StudentRecordService.cs) Introduced three new test methods for function invocation without parameters; added GetBooksAsync to the book service interface and implementation; implemented two new student record list retrieval methods with minor formatting updates.

Sequence Diagram(s)

sequenceDiagram
    participant Caller
    participant SchemaBuilder
    Caller->>SchemaBuilder: ConvertToSchema(type, description)
    alt No properties in type
        SchemaBuilder-->>Caller: null
    else Properties exist
        SchemaBuilder->>SchemaBuilder: Build schema
        SchemaBuilder-->>Caller: OpenApiSchema
    end
Loading
sequenceDiagram
    participant Test
    participant OpenAIClient
    participant ChatClient
    participant Service
    Test->>OpenAIClient: Initialize with API key
    OpenAIClient->>ChatClient: Setup chat session with tools
    Test->>ChatClient: Send request message (e.g., student records/books)
    ChatClient->>Service: Invoke function tool
    Service-->>ChatClient: Return response data
    ChatClient-->>Test: Deliver response message
Loading

Poem

I'm a hopping rabbit, bright and quick,
Skipping through code with every clever trick.
Schemas bloom and tests now leap in place,
Function tools sing in our coding race.
With each new line, I bound with glee—
Celebrating changes, happy as can be!


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between da99fc0 and 4519559.

📒 Files selected for processing (2)
  • src/tests/CSharpToJsonSchema.MeaiTests/Meai_Tests.cs (2 hunks)
  • src/tests/CSharpToJsonSchema.MeaiTests/Services/StudentRecordService.cs (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/tests/CSharpToJsonSchema.MeaiTests/Meai_Tests.cs
  • src/tests/CSharpToJsonSchema.MeaiTests/Services/StudentRecordService.cs

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.


Gunpal Jain seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.

Copy link

@coderabbitai coderabbitai bot left a 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

🧹 Nitpick comments (5)
src/tests/CSharpToJsonSchema.AotTests/Services/MethodFunctionTools.cs (1)

61-65: Method naming is inconsistent with class convention.

This method is defined as static but does not follow the naming convention used by other static methods in this class, which include "Static" in their name.

-    public static string SampleFunctionTool_No_Parameters()
+    public static string SampleFunctionTool_Static_No_Parameters_2()

Or if this is meant to be an instance method:

-    public static string SampleFunctionTool_No_Parameters()
+    public string SampleFunctionTool_No_Parameters()
src/tests/CSharpToJsonSchema.AotTests/MethodFunctionTools_Tests.cs (1)

83-88: Missing assertion in test method.

While the test correctly invokes the method with an empty JSON object, it doesn't verify the return value. Consider adding an assertion to ensure the function returns the expected result.

    public async Task Should_SampleFunctionTool_No_Parameters()
    {
        var tools = new Tools([MethodFunctionTools.SampleFunctionTool_No_Parameters]);
-        await tools.CallAsync(nameof(MethodFunctionTools.SampleFunctionTool_No_Parameters), "{}");
+        var value = await tools.CallAsync(nameof(MethodFunctionTools.SampleFunctionTool_No_Parameters), "{}");
+        Assert.Equal("\"Hello world from string return\"", value);
    }
src/tests/CSharpToJsonSchema.MeaiTests/Services/BookService.cs (1)

41-44: Improve readability by using consistent formatting

The implementation works correctly but could benefit from consistent formatting with the rest of the codebase, particularly matching the formatting style used in the GetAuthorBooksAsync method.

-    public Task<List<GetAuthorBook>> GetBooksAsync(CancellationToken cancellationToken = default)
-    {
-        return Task.FromResult(new List<GetAuthorBook>(){new GetAuthorBook(){Title = "Five point someone", Description = "This book is about 3 college friends"},new GetAuthorBook(){Title = "Two States", Description = "This book is about intercast marriage in India"}});
-    }
+    public Task<List<GetAuthorBook>> GetBooksAsync(CancellationToken cancellationToken = default)
+    {
+        return Task.FromResult(new List<GetAuthorBook>([
+            new GetAuthorBook
+                { Title = "Five point someone", Description = "This book is about 3 college friends" },
+            new GetAuthorBook
+                { Title = "Two States", Description = "This book is about intercast marriage in India" }
+        ]));
+    }
src/tests/CSharpToJsonSchema.MeaiTests/Meai_Tests.cs (2)

67-92: Consider consolidating duplicate tests

This test is nearly identical to ShouldInvokeTheFunctions_NoParameters with the only difference being the method called (GetStudentsList2 vs GetStudentsListAsync). Since both methods have identical functionality, consider consolidating these tests or using a parameterized test approach.

+    [TestMethod]
+    [DataRow(nameof(StudentRecordService.GetStudentsListAsync))]
+    [DataRow(nameof(StudentRecordService.GetStudentsList2))]
+    public async Task ShouldInvokeTheFunctions_NoParameters(string methodName)
+    {
+        var key = Environment.GetEnvironmentVariable("OPEN_AI_APIKEY",EnvironmentVariableTarget.User);
+        if (string.IsNullOrWhiteSpace(key))
+            return;
+        
+        var client = new OpenAIClient(new ApiKeyCredential(key));
+
+        Microsoft.Extensions.AI.OpenAIChatClient openAiClient = new OpenAIChatClient(client.GetChatClient("gpt-4o-mini"));
+
+        var chatClient = new Microsoft.Extensions.AI.FunctionInvokingChatClient(openAiClient);
+        var chatOptions = new ChatOptions();
+
+        var service = new StudentRecordService();
+        var method = typeof(StudentRecordService).GetMethod(methodName);
+        var tools = new Tools([method?.CreateDelegate(typeof(Func<CancellationToken, Task<List<StudentRecord>>>), service)]);
+        chatOptions.Tools = tools.AsMeaiTools();
+        
+        var message = new ChatMessage(ChatRole.User, "Get all students records");
+        var response = await chatClient.GetResponseAsync(message,options:chatOptions).ConfigureAwait(false);
+
+        response.Text.Contains("John", StringComparison.InvariantCultureIgnoreCase).Should()
+            .Be(true);
+        
+        Console.WriteLine(response.Text);
+    }

122-149: Use consistent client initialization patterns

While the test is functional, I note that line 130 uses a different approach to create the chat client compared to the other tests in this file. Consider using a consistent pattern throughout the class for better maintainability.

-        var chatClient = new OpenAIClient(new ApiKeyCredential(key)).AsChatClient("gpt-4o-mini").AsBuilder().UseFunctionInvocation().Build();
+        var client = new OpenAIClient(new ApiKeyCredential(key));
+        Microsoft.Extensions.AI.OpenAIChatClient openAiClient = new OpenAIChatClient(client.GetChatClient("gpt-4o-mini"));
+        var chatClient = new Microsoft.Extensions.AI.FunctionInvokingChatClient(openAiClient);
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 10780c4 and da99fc0.

📒 Files selected for processing (7)
  • src/libs/CSharpToJsonSchema/SchemaSubsetHelper.cs (5 hunks)
  • src/tests/CSharpToJsonSchema.AotTests/MethodFunctionTools_Tests.cs (1 hunks)
  • src/tests/CSharpToJsonSchema.AotTests/Services/MethodFunctionTools.cs (1 hunks)
  • src/tests/CSharpToJsonSchema.IntegrationTests/MethodFunctionTools.cs (1 hunks)
  • src/tests/CSharpToJsonSchema.MeaiTests/Meai_Tests.cs (2 hunks)
  • src/tests/CSharpToJsonSchema.MeaiTests/Services/BookService.cs (2 hunks)
  • src/tests/CSharpToJsonSchema.MeaiTests/Services/StudentRecordService.cs (3 hunks)
🧰 Additional context used
🧬 Code Definitions (3)
src/tests/CSharpToJsonSchema.AotTests/MethodFunctionTools_Tests.cs (1)
src/tests/CSharpToJsonSchema.AotTests/Services/MethodFunctionTools.cs (1)
  • MethodFunctionTools (6-66)
src/tests/CSharpToJsonSchema.MeaiTests/Meai_Tests.cs (2)
src/tests/CSharpToJsonSchema.MeaiTests/Services/BookService.cs (4)
  • Task (26-34)
  • Task (36-39)
  • Task (41-44)
  • BookStoreService (24-45)
src/tests/CSharpToJsonSchema.MeaiTests/Services/StudentRecordService.cs (1)
  • StudentRecordService (5-104)
src/tests/CSharpToJsonSchema.MeaiTests/Services/StudentRecordService.cs (1)
src/tests/CSharpToJsonSchema.MeaiTests/Meai_Tests.cs (2)
  • Task (14-38)
  • Task (95-121)
🔇 Additional comments (11)
src/tests/CSharpToJsonSchema.IntegrationTests/MethodFunctionTools.cs (1)

56-57: Minor formatting adjustment.

The addition of these blank lines appears to be a formatting improvement for better code readability, separating the method implementations.

src/tests/CSharpToJsonSchema.AotTests/Services/MethodFunctionTools.cs (1)

56-60: LGTM! Added support for parameterless static functions.

The implementation correctly adds a static function with no parameters, following the existing pattern for function tools.

src/tests/CSharpToJsonSchema.AotTests/MethodFunctionTools_Tests.cs (1)

76-81: LGTM! Test for parameterless static function.

The test correctly verifies that a static function with no parameters can be invoked with an empty JSON object.

src/libs/CSharpToJsonSchema/SchemaSubsetHelper.cs (3)

12-16: Good fix for handling types with no properties.

Making the return type nullable and adding an early exit when a type has no properties is a good improvement. This prevents attempting to create schemas for empty types.


47-54: Improved readability of return statement.

The reformatting of the return statement improves code readability by clearly structuring the object initialization.


57-58: Improved parameter formatting.

The reformatting of method parameters improves readability by placing parameters on separate lines.

src/tests/CSharpToJsonSchema.MeaiTests/Services/BookService.cs (1)

20-21: LGTM: Interface method signature properly defines a parameter-less operation

The addition of the GetBooksAsync method to the interface with only a cancellation token parameter (with default value) is a good approach for implementing a parameter-less operation while maintaining cancellation support.

src/tests/CSharpToJsonSchema.MeaiTests/Meai_Tests.cs (1)

40-65: LGTM: Appropriate test for parameter-less function

This test correctly validates that the parameter-less method GetStudentsListAsync works properly. The test structure follows the established pattern and verifies that the expected student data is returned.

src/tests/CSharpToJsonSchema.MeaiTests/Services/StudentRecordService.cs (3)

9-10: LGTM: Improved parameter formatting

The reformatting of the method signature improves readability by placing parameters on separate lines, especially useful when parameter lists grow longer.


29-65: LGTM: Added parameter-less method to retrieve all student records

The implementation of GetStudentsListAsync provides a good way to retrieve all student records without requiring specific parameters, which simplifies certain use cases.


137-149: LGTM: Improved readability with consistent spacing

The added whitespace between property definitions in the QueryStudentRecordRequest class improves readability and maintains consistency.

@gunpal5 gunpal5 merged commit d62ff17 into tryAGI:main Mar 23, 2025
3 of 4 checks passed
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.

2 participants