Skip to content

Conversation

grimmerk
Copy link
Collaborator

@grimmerk grimmerk commented Mar 25, 2025

What does this PR do?

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)

xxx

Loom Video (if appropriate)

xxx

Any Security implications

xxx

Summary by CodeRabbit

  • New Features

    • Introduced comprehensive support for Google Vertex AI, enabling enhanced tool definitions and response schema handling.
    • Added new functions and classes for converting JSON schemas to Gemini Vertex formats.
  • Documentation

    • Updated guides and API references to illustrate the new Vertex AI functionalities.
  • Chores

    • Upgraded the package version to 1.0.2.

Copy link

coderabbitai bot commented Mar 25, 2025

Caution

Review failed

The pull request is closed.

Walkthrough

The pull request introduces support for the Google Cloud Vertex AI API. New functions and type definitions have been added to convert JSON schemas and classes into Vertex AI tool and response schema formats. Documentation in the CHANGELOG and README has been updated to reflect these changes, and the package version has been incremented. Existing export lists have been enhanced by integrating the new functions alongside legacy functionality.

Changes

File(s) Change Summary
CHANGELOG.md, README.md Updated documentation to include a new section for version 1.0.2, describing the addition of Vertex AI support and the introduction of new functions for both legacy and Vertex schema conversions.
package.json Bumped the package version from "1.0.1" to "1.0.2".
src/lib/index.ts, src/lib/llm-formats.ts Added new Vertex AI conversion functions: jsonSchemaToGeminiVertexTool, jsonSchemaToGeminiVertexResponseSchema, classToGeminiVertexTool, and classToGeminiVertexResponseSchema. Additionally, legacy functions such as jsonSchemaToGeminiOldTool and jsonSchemaToGeminiOldResponseSchema are now exported alongside the new ones.
src/lib/types.ts, src/lib/vertex-api.type.ts Introduced new type definitions (GeminiVertexToolFunction and GeminiVertexResponseSchema) and a new enum (SchemaType with member OBJECT) to support Vertex AI schema definitions, enhancing type safety and clarity in the API.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant Dev as Developer
  participant SF as @firefliesai/schema-forge
  participant LLM as llm-formats Module

  Dev->>SF: call classToGeminiVertexTool(UserInput, options)
  SF->>LLM: Delegate conversion from class to tool format
  LLM-->>SF: Return GeminiVertexToolFunction instance
  SF-->>Dev: Return tool instance
Loading
sequenceDiagram
  autonumber
  participant Dev as Developer
  participant SF as @firefliesai/schema-forge
  participant JSON as JSON Converter

  Dev->>SF: call jsonSchemaToGeminiVertexTool(schema, metadata)
  SF->>JSON: Convert JSON schema to tool format
  JSON-->>SF: Return conversion result
  SF-->>Dev: Return GeminiVertexToolFunction instance
Loading

Possibly related PRs

  • feat: add gemini vertex api support #21: The changes in the main PR and the retrieved PR are directly related as they both introduce new functions and classes for handling the Gemini Vertex API, specifically modifying the same functions and classes such as jsonSchemaToGeminiVertexTool, jsonSchemaToGeminiVertexResponseSchema, classToGeminiVertexTool, and classToGeminiVertexResponseSchema.

Suggested reviewers

  • FoysalOsmany
  • Serdar-FF
  • jhho89
  • greguintow

📜 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 f4dfc33 and 882bb56.

📒 Files selected for processing (1)
  • src/lib/types.ts (3 hunks)
✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 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 generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai plan to trigger planning for file edits and PR creation.
  • @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 comments (1)
src/lib/index.ts (1)

75-112: 💡 Verification agent

🧩 Analysis chain

Consider updating Schema namespace with new exports

The Schema namespace at the bottom of the file hasn't been updated to include the newly added functions. This could lead to inconsistency in the API for users who use the namespace-style imports.

export const Schema = {
  // Decorators
  ToolMeta,
  ToolProp,

  // Core JSON Schema generation
  classToJsonSchema,
  prepareForOpenAIStructuredOutput,

  // Schema modification
  updateSchemaProperty,
  addSchemaProperty,

  // LLM-specific class converter functions
  classToOpenAITool,
  classToOpenAIResponseFormatJsonSchema,
  classToOpenAIResponseApiTool,
  classToOpenAIResponseApiTextSchema,
  classToGeminiTool,
  classToGeminiResponseSchema,
+ classToGeminiVertexTool,
+ classToGeminiVertexResponseSchema,
+ classToGeminiOldTool,
+ classToGeminiOldResponseSchema,
  classToAnthropicTool,

  // Direct JSON Schema converter functions
  jsonSchemaToOpenAITool,
  jsonSchemaToOpenAIResponseFormat,
  jsonSchemaToOpenAIResponseApiTool,
  jsonSchemaToOpenAIResponseApiTextSchema,
  jsonSchemaToGeminiTool,
  jsonSchemaToGeminiResponseSchema,
+ jsonSchemaToGeminiVertexTool,
+ jsonSchemaToGeminiVertexResponseSchema,
+ jsonSchemaToGeminiOldTool,
+ jsonSchemaToGeminiOldResponseSchema,
  jsonSchemaToAnthropicTool,

  // Extract JSON Schema from LLM formats
  openAIToolToJsonSchema,
  openAIResponseApiToolToJsonSchema,

  // Legacy name
  classToLLMTool: classToOpenAITool,
} as const;

To ensure this is implemented correctly, we would also need to import these functions in the imports section around line 56-72.


🏁 Script executed:

#!/bin/bash
# Check if classToGeminiVertexTool and other new functions are defined in the llm-formats.ts file

echo "Searching for implementation of new Vertex API functions..."
rg -A 1 "export (const|function) (classToGeminiVertex|jsonSchemaToGeminiVertex|classToGeminiOld|jsonSchemaToGeminiOld)" src/lib/llm-formats.ts

Length of output: 1018


Action Required: Extend Schema Namespace with New Vertex API Exports

The new functions (e.g. classToGeminiVertexTool, classToGeminiVertexResponseSchema, classToGeminiOldTool, classToGeminiOldResponseSchema, and their JSON Schema converter counterparts) have been verified to exist in src/lib/llm-formats.ts. However, the Schema namespace in src/lib/index.ts hasn’t been updated to expose these exports.

Please update the Schema object as follows and ensure that the corresponding import statements (around lines 56–72 in src/lib/index.ts) are also updated to import these new functions:

  • Add the following to the LLM-specific class converter functions section:
    • classToGeminiVertexTool
    • classToGeminiVertexResponseSchema
    • classToGeminiOldTool
    • classToGeminiOldResponseSchema
  • Add the following to the direct JSON Schema converter functions section:
    • jsonSchemaToGeminiVertexTool
    • jsonSchemaToGeminiVertexResponseSchema
    • jsonSchemaToGeminiOldTool
    • jsonSchemaToGeminiOldResponseSchema

Diff Suggestion:

 export const Schema = {
   // Decorators
   ToolMeta,
   ToolProp,

   // Core JSON Schema generation
   classToJsonSchema,
   prepareForOpenAIStructuredOutput,

   // Schema modification
   updateSchemaProperty,
   addSchemaProperty,

   // LLM-specific class converter functions
   classToOpenAITool,
   classToOpenAIResponseFormatJsonSchema,
   classToOpenAIResponseApiTool,
   classToOpenAIResponseApiTextSchema,
   classToGeminiTool,
   classToGeminiResponseSchema,
+  classToGeminiVertexTool,
+  classToGeminiVertexResponseSchema,
+  classToGeminiOldTool,
+  classToGeminiOldResponseSchema,
   classToAnthropicTool,

   // Direct JSON Schema converter functions
   jsonSchemaToOpenAITool,
   jsonSchemaToOpenAIResponseFormat,
   jsonSchemaToOpenAIResponseApiTool,
   jsonSchemaToOpenAIResponseApiTextSchema,
   jsonSchemaToGeminiTool,
   jsonSchemaToGeminiResponseSchema,
+  jsonSchemaToGeminiVertexTool,
+  jsonSchemaToGeminiVertexResponseSchema,
+  jsonSchemaToGeminiOldTool,
+  jsonSchemaToGeminiOldResponseSchema,
   jsonSchemaToAnthropicTool,

   // Extract JSON Schema from LLM formats
   openAIToolToJsonSchema,
   openAIResponseApiToolToJsonSchema,

   // Legacy name
   classToLLMTool: classToOpenAITool,
 } as const;

After updating the export object, please double-check that the new functions are being imported correctly from src/lib/llm-formats.ts. This will ensure consistency in the API for namespace-style imports.

🧹 Nitpick comments (3)
src/lib/vertex-api.type.ts (1)

1-4: Consider adding more documentation for the SchemaType enum

This enum appears to be used for Vertex AI schema type definitions. Consider adding:

  1. JSDoc comments to explain the purpose of this enum
  2. Documentation about whether more values might be added in the future
  3. Why only OBJECT is defined currently
// @google-cloud/vertexai
+/**
+ * Schema types supported by the Google Cloud Vertex AI API.
+ * Currently only OBJECT schema type is supported.
+ */
export enum SchemaType {
  OBJECT = 'OBJECT',
}
CHANGELOG.md (1)

8-15: Fix capitalization of "Google" in changelog

The company name "Google" should be capitalized.

## [1.0.2] - 2025-03-25

-1. Publish `jsonSchemaToGeminiOldTool`, `jsonSchemaToGeminiOldResponseSchema` that whould be published in 1.0.0.
-2. Support the tool format and responseSchema format of google vertex API, `@google-cloud/vertexai`. Supply the following functions
+1. Publish `jsonSchemaToGeminiOldTool`, `jsonSchemaToGeminiOldResponseSchema` that should be published in 1.0.0.
+2. Support the tool format and responseSchema format of Google Vertex API, `@google-cloud/vertexai`. Supply the following functions
   1. `jsonSchemaToGeminiVertexTool`
   2. `jsonSchemaToGeminiVertexResponseSchema`
   3. `classToGeminiVertexResponseSchema`
   4. `classToGeminiVertexTool`

Also note there's a typo: "whould" should be "should".

🧰 Tools
🪛 LanguageTool

[grammar] ~11-~11: “Google” is a proper noun and needs to be capitalized.
Context: ...ool format and responseSchema format of google vertex API, @google-cloud/vertexai. S...

(A_GOOGLE)

src/lib/types.ts (1)

132-145: Fix typo in comment.

There's a typo in the comment documentation.

    // json schema like structure,
-    // Google Gemini (@google/genai) prefers capital 'OBJECT' insteadac of 'object'
+    // Google Gemini (@google/genai) prefers capital 'OBJECT' instead of 'object'
    // but 'object' is also accepted by Gemini API if we use any to force triggering api
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 26a756c and f4dfc33.

📒 Files selected for processing (7)
  • CHANGELOG.md (1 hunks)
  • README.md (4 hunks)
  • package.json (2 hunks)
  • src/lib/index.ts (1 hunks)
  • src/lib/llm-formats.ts (5 hunks)
  • src/lib/types.ts (3 hunks)
  • src/lib/vertex-api.type.ts (1 hunks)
🧰 Additional context used
🧬 Code Definitions (1)
src/lib/llm-formats.ts (1)
src/lib/types.ts (5)
  • JSONSchemaDefinition (54-60)
  • GeminiVertexToolFunction (133-145)
  • GeminiVertexResponseSchema (165-170)
  • GeminiToolOptions (222-225)
  • GeminiResponseSchemaOptions (231-234)
🪛 LanguageTool
CHANGELOG.md

[grammar] ~11-~11: “Google” is a proper noun and needs to be capitalized.
Context: ...ool format and responseSchema format of google vertex API, @google-cloud/vertexai. S...

(A_GOOGLE)

🔇 Additional comments (21)
package.json (1)

3-3: Version bump is appropriate for feature addition

The version increment from 1.0.1 to 1.0.2 follows semantic versioning principles for adding new features without breaking changes.

src/lib/index.ts (3)

23-24: New Vertex API class converters added appropriately

The Vertex API-specific class converters are correctly exported from the module.


31-32: Legacy Gemini converters exported correctly

The "Old" Gemini converters that should have been in v1.0.0 are now properly exported.


35-36: New Vertex API JSON Schema converters added correctly

The direct JSON Schema converters for Vertex API are properly exported.

src/lib/types.ts (3)

4-4: Looking good! Appropriate import and type aliasing.

The import and renaming of SchemaType to SchemaVertexType creates a clear distinction for Vertex API types.


132-145: Good interface definition that maintains consistency with existing patterns.

The GeminiVertexToolFunction interface follows the same structure as the other Gemini tool interfaces, which maintains consistency across the codebase. Using SchemaVertexType.OBJECT helps distinguish this implementation for Vertex AI.


164-170: Well-structured response schema interface.

The GeminiVertexResponseSchema interface appropriately mirrors the pattern of other response schema interfaces while using the Vertex-specific type.

src/lib/llm-formats.ts (5)

14-15: Good import of new types.

Properly importing the new Vertex-specific types to be used in the new functions.


285-294: Consistent implementation pattern for response schema conversion.

The implementation follows the same pattern as the tool function conversion, leveraging existing code with type casting.


559-565: Similar implementation pattern for class-based conversion.

The approach of leveraging existing functions with type casting is maintained consistently across all Vertex AI conversion functions.


675-681: Consistent implementation completing the set of conversion functions.

The implementation completes the set of conversion functions needed for Vertex AI support, following the same pattern as the other functions.


236-242:

✅ Verification successful

Implementation leverages existing code with type casting.

The implementation reuses the existing jsonSchemaToGeminiTool function, avoiding code duplication while maintaining API-specific types through casting. This approach is efficient if the underlying formats are indeed identical.

Since the implementation assumes structural equivalence between Gemini and Vertex formats, verify this assumption remains valid if either API changes:


🏁 Script executed:

#!/bin/bash
# Check if there are any structural differences in type definitions
grep -r "export interface Gemini.*ToolFunction" src/
grep -r "export interface Gemini.*ResponseSchema" src/

Length of output: 465


Verified Structural Equivalence between Gemini and Vertex APIs

The implementation in src/lib/llm-formats.ts efficiently leverages the existing jsonSchemaToGeminiTool function by casting its output to a GeminiVertexToolFunction. A review of type definitions in src/lib/types.ts confirms that the expected interfaces (including GeminiVertexToolFunction, GeminiOldToolFunction, and their corresponding response interfaces) are present and consistent. This suggests that the assumption of structural equivalence between Gemini and Vertex formats currently holds. However, please remain alert to any future changes in these API definitions that might affect this equivalence.

README.md (9)

290-290: Clear import statement including new Vertex tool function.

The import statement now includes classToGeminiVertexTool alongside the other Gemini conversion functions.


293-293: Good variable name clarification.

Renaming from tool to geminiTool improves clarity, especially as multiple tool variables are now defined in the example.


298-299: Proper formatting for tool configuration.

The example correctly shows how to use the tool function in the configuration object.


303-304: Clear identification of API client.

The comment properly identifies which Google API client is being used for this example (@google/generative-ai).


310-316: Good example for Vertex AI implementation.

The example demonstrates how to use the new Vertex AI support with the appropriate API client.


689-690: Transparent documentation with appropriate cautionary note.

The documentation clearly indicates that while the Vertex API functionality is implemented, it hasn't been verified with real API calls yet. This transparency is important for users.


703-704: Consistent documentation for JSON Schema converters.

The documentation for the JSON Schema converters is consistent with the class-based converters, including the same cautionary note about verification.


838-840: Important implementation notes for users.

The notes provide important context about the implementation status and potential future API changes, which is valuable information for users deciding which API to use.


845-845: Example code matches API documentation.

The example code correctly uses the classToGeminiVertexTool function as described in the API reference.

@grimmerk grimmerk merged commit 9030945 into develop Mar 25, 2025
2 of 3 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.

1 participant