Skip to content

0.1.6 #3

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

Closed
wants to merge 4 commits into from
Closed

0.1.6 #3

wants to merge 4 commits into from

Conversation

hoangvvo
Copy link
Collaborator

@hoangvvo hoangvvo commented Nov 9, 2024

What does this PR do?

Fix https://fireflies.sentry.io/issues/6052582757/?referrer=slack&notification_uuid=e1c886ce-dfea-4803-a716-8305fe4f218e&alert_rule_id=15510789&alert_type=issue

Type of change

This pull request is a

  • Feature
  • Bugfix
  • Enhancement

Which introduces

  • Breaking changes
  • Non-breaking changes

How should this be manually tested?

xxx

What are the requirements to deploy to production?

Any background context you want to provide beyond Shortcut?

xxx

Screenshots (if appropriate)

Without this fix:
image

With this fix:
image

all tests pass:
Uploading image.png…

Loom Video (if appropriate)

xxx

Any Security implications

xxx

Copy link

coderabbitai bot commented Nov 9, 2024

Important

Review skipped

Review was skipped due to path filters

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json

CodeRabbit blocks several paths by default. You can override this behavior by explicitly including those paths in the path filters. For example, including **/dist/** will override the default block on the dist directory, by removing the pattern from both the lists.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

The pull request includes updates to three files. The package.json file for the @hoangvvo/llm-sdk module has been updated to version 0.1.6. In stream.utils.ts, the guessDeltaIndex function's logic for matching tool calls has been modified to always return false, affecting how tool calls are indexed. Lastly, test-language-model.ts has seen updates to existing tests and the addition of a new test case to enhance testing coverage for tool interactions.

Changes

File Change Summary
javascript/package.json Updated version from 0.1.5 to 0.1.6. No other changes.
javascript/src/utils/stream.utils.ts Modified guessDeltaIndex logic to always return false for tool call matches.
javascript/test/test-language-model.ts Updated prompt in an existing test and added a new test for handling multiple tool calls.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant LanguageModel
    participant Tool

    User->>LanguageModel: Request user registration
    LanguageModel->>Tool: Generate tool call for registration
    Tool-->>LanguageModel: Return registration result
    LanguageModel-->>User: Respond with registration confirmation

    User->>LanguageModel: Request weather for Boston
    User->>LanguageModel: Request weather for New York
    LanguageModel->>Tool: Generate tool call for get_weather (Boston)
    LanguageModel->>Tool: Generate tool call for get_weather (New York)
    Tool-->>LanguageModel: Return weather for Boston
    Tool-->>LanguageModel: Return weather for New York
    LanguageModel-->>User: Respond with weather for Boston and New York
Loading

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

‼️ IMPORTANT
Auto-reply has been disabled for this repository in the CodeRabbit settings. The CodeRabbit bot will not respond to your replies unless it is explicitly tagged.

  • 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 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.

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: 0

🧹 Outside diff range and nitpick comments (3)
javascript/src/utils/stream.utils.ts (1)

Line range hint 1-180: Consider enhancing error messages for tool call handling.

Given the change in tool call matching logic, it would be helpful to improve error messages in the addChunks method when handling tool calls. This would make it easier to diagnose issues when tool calls are incorrectly accumulated.

Consider enhancing the error message in the tool-call branch of addChunks:

         } else if (
           existingDelta.part.type === "tool-call" &&
           incomingDelta.part.type === "tool-call"
         ) {
+          // Log detailed information about the tool calls being merged
+          console.debug(
+            `Merging tool calls: existing=${existingDelta.part.toolName} incoming=${incomingDelta.part.toolName}`
+          );
           if (incomingDelta.part.toolName) {
             existingDelta.part.toolName =
               (existingDelta.part.toolName || "") + incomingDelta.part.toolName;

Consider adding telemetry or debug logging around tool call handling to help monitor the impact of this change in production. This would help identify any potential issues with the new matching behavior.

javascript/test/test-language-model.ts (2)

387-387: Enhance test assertions for complex schema validation.

While the test prompt now covers all fields in the complex schema, the assertions only verify the tool call ID and name. Consider adding assertions to validate that the arguments are correctly parsed according to the schema requirements.

Add assertions to verify the parsed arguments:

    t.assert.equal(toolCallPart?.toolName, "register_user");
+   // Verify parsed arguments match input
+   const args = toolCallPart?.args;
+   t.assert.equal(args?.["id"], "a1b2c3");
+   t.assert.equal(args?.["name"], "John Doe");
+   t.assert.equal(args?.["email"], "[email protected]");
+   t.assert.equal(args?.["birthDate"], "1990-05-15");
+   t.assert.equal(args?.["age"], 34);
+   t.assert.equal(args?.["isActive"], true);
+   t.assert.equal(args?.["role"], "user");
+   t.assert.equal(args?.["accountBalance"], 500.75);
+   t.assert.equal(args?.["phoneNumber"], "+1234567890123");
+   t.assert.deepEqual(args?.["tags"], ["developer", "gamer"]);
+   t.assert.equal(args?.["lastLogin"], "2024-11-09T10:30:00Z");

522-564: LGTM! Consider adding additional test coverage.

The test case effectively validates parallel tool calls of the same name with different arguments. The assertions are thorough and type-safe.

Consider adding these test cases to improve coverage:

  1. Verify unique tool call IDs:
t.assert.notEqual(weatherCall1?.toolCallId, weatherCall2?.toolCallId);
  1. Add a test case for invalid locations to verify error handling:
test("stream parallel tool calls with invalid location", async (t) => {
  const response = languageModel.stream({
    messages: [{
      role: "user",
      content: [{
        type: "text",
        text: "Get me the weather in InvalidCity1 and InvalidCity2."
      }]
    }],
    tools,
  });
  // ... verify error handling
});
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 94720c0 and 7bd27c4.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (3)
  • javascript/package.json (1 hunks)
  • javascript/src/utils/stream.utils.ts (1 hunks)
  • javascript/test/test-language-model.ts (2 hunks)
✅ Files skipped from review due to trivial changes (1)
  • javascript/package.json
🔇 Additional comments (1)
javascript/src/utils/stream.utils.ts (1)

167-167: Verify the impact of disabling tool call matching.

The change to always return false for tool calls appears to be addressing a potential issue with matching multiple tool calls that have the same name. While this fix prevents incorrect matching, we should verify its impact on existing tool call handling.

Let's verify the tool call usage patterns in the codebase:

Consider adding a comment explaining why tool calls can't be reliably matched, for example:

-        // we won't be able to reliably match tool calls
-        // because there can be multiple tool calls with the same tool name
+        // Tool calls cannot be reliably matched by name since multiple calls
+        // can share the same tool name but represent different operations.
+        // Each tool call should be treated as a distinct entity.
         return false;
✅ Verification successful

The change to disable tool call matching is correct and necessary

The verification confirms this change is correct for several reasons:

  • Tests show multiple scenarios with parallel tool calls and tool calls of the same name, indicating the need to handle each tool call as a distinct entity
  • The test stream parallel tool calls of same name specifically validates the case where multiple tool calls share the same name
  • The implementation across different providers (OpenAI, Anthropic, etc.) shows that tool call deltas are handled independently

The change to return false ensures proper handling of multiple tool calls, especially in streaming scenarios where tool calls with the same name need to be treated as separate entities.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check tool call handling patterns to verify the safety of this change

# Search for tool call related tests and usage
echo "Searching for tool call related tests..."
rg -l "tool-call" --type ts

# Look for potential tool call matching patterns that might be affected
echo "Checking for potential tool call matching patterns..."
ast-grep --pattern 'toolName === $_' 

Length of output: 624


Script:

#!/bin/bash
# Let's examine the actual implementation and usage of guessDeltaIndex

# First, check the full context of the guessDeltaIndex function
echo "Checking guessDeltaIndex implementation..."
rg -B 10 -A 10 "guessDeltaIndex" javascript/src/utils/stream.utils.ts

# Check test files for tool call related test cases
echo "Checking test cases..."
rg "tool.*call" javascript/test/test-language-model.ts -C 5

# Check actual usage of stream utilities with tool calls
echo "Checking tool call usage in main implementation..."
rg "tool.*call.*delta" javascript/src/{openai,anthropic,google,mistral,cohere}/*.ts

Length of output: 5523

@hoangvvo hoangvvo requested review from greguintow and a team November 9, 2024 02:50
@hoangvvo
Copy link
Collaborator Author

hoangvvo commented Nov 9, 2024

@hoangvvo hoangvvo closed this Nov 9, 2024
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.

1 participant