Skip to content
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

BREAKING CHANGE: major refactor done, bump genkit version to 0.9 #81

Merged
merged 18 commits into from
Nov 14, 2024

Conversation

xavidop
Copy link
Owner

@xavidop xavidop commented Nov 7, 2024

This pull request is related to:

  • A bug
  • A new feature
  • Documentation
  • Other (please specify)

I have checked the following:

  • I have read and understood the contribution guidelines and the code of conduct;
  • I have added new tests (for bug fixes/features);
  • I have added/updated the documentation (for bug fixes / features).

Description:
Preparing the plugin for Genkit version > 0.9. Change the plugin API to be ready for the new GenkitAPI

Summary by CodeRabbit

  • New Features

    • Updated dependency structure to streamline package management, replacing multiple peer dependencies with a single one.
    • Enhanced functionality for GitHub integration through improved method signatures and internal logic for model and embedder definitions.
    • Added a new "Versions" section in the documentation to clarify compatibility between the Genkit plugin and different Genkit versions.
    • Updated workflow configuration to include new licenses for dependency review.
  • Bug Fixes

    • Refined error handling for message processing and GitHub token validation to ensure more robust functionality.
  • Refactor

    • Significant restructuring of function implementations to utilize the new Genkit library, improving clarity and efficiency in handling models and messages.
    • Adjusted internal logic to shift from return-based structures to a more procedural approach in the GitHub function.

Copy link
Contributor

coderabbitai bot commented Nov 7, 2024

Caution

Review failed

The pull request is closed.

Walkthrough

The pull request introduces significant modifications to the genkitx-github project, specifically in the package.json, src/github_embedders.ts, src/github_llms.ts, and src/index.ts files. Key changes include the removal of specific peer dependencies in favor of a new dependency, genkit, and updates to function signatures across multiple files to incorporate this new dependency. The internal logic of functions has been refactored to streamline the handling of models and embedders, enhancing the integration with the genkit library.

Changes

File Change Summary
package.json Removed peer dependencies @genkit-ai/ai and @genkit-ai/core; added genkit as a peer dependency. Updated @azure-rest/ai-inference version from ^1.0.0-beta.2 to ^1.0.0-beta.4.
src/github_embedders.ts Updated githubEmbedder function signature to include ai: Genkit; modified internal logic for embedder definition.
src/github_llms.ts Updated githubModel function signature to include ai: Genkit; refactored message handling logic.
src/index.ts Changed github function from constant to standard function; integrated ai parameter and modified control flow.
README.md Added new section "Versions" detailing compatibility between the Genkit plugin and different versions of Genkit. Updated function calls to reflect changes in initialization and usage.
.github/workflows/depsreview.yaml Updated allow-licenses parameter to include BSD-3-Clause-Clear for dependency review. Updated action version from v4 to v4.3.3.

Possibly related PRs

🐰 "In the garden of code, we hop and play,
Dependencies shift, in a marvelous way.
With Genkit now guiding our paths anew,
We build and we craft, with a vibrant view.
Functions refined, like a fresh morning dew,
Hopping along, creating something true!" 🐇


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 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 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
Contributor

@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

🧹 Outside diff range and nitpick comments (2)
src/github_embedders.ts (1)

Line range hint 112-122: LGTM! Core implementation updated for Genkit v0.9+.

The change to ai.defineEmbedder and input mapping updates are correct.

Consider adding these improvements:

  1. Add error handling for invalid embeddings response
  2. Add validation for embedding dimensions
  3. Enhance type safety with a more specific return type
 return ai.defineEmbedder(
   {
     info: model.info!,
     configSchema: TextEmbeddingConfigSchema,
     name: model.name,
   },
-  async (input, options) => {
+  async (input: { text: string }[], options?: TextEmbeddingGeckoConfig) => {
     const body = {
       body: {
         model: name,
         input: input.map((d) => d.text),
         dimensions: options?.dimensions,
         encoding_format: options?.encodingFormat,
       },
     } as GetEmbeddingsParameters;
     const embeddings = (await client
       .path("/embeddings")
       .post(body)) as GetEmbeddings200Response;
+    // Validate response
+    if (!embeddings?.body?.data?.length) {
+      throw new Error('Invalid embeddings response');
+    }
+    // Validate dimensions if specified
+    if (options?.dimensions) {
+      const actualDimensions = embeddings.body.data[0]?.embedding?.length;
+      if (actualDimensions !== options.dimensions) {
+        throw new Error(`Expected ${options.dimensions} dimensions but got ${actualDimensions}`);
+      }
+    }
     return {
       embeddings: embeddings.body.data.map((d) => ({
         embedding: Array.isArray(d.embedding) ? d.embedding : [],
       })),
     };
   },
 );
src/index.ts (1)

106-108: Replace Object.keys().forEach() with for...of loop for better readability.

Using a for...of loop can improve readability and maintain consistency with modern JavaScript practices.

Refactor the code as follows:

-Object.keys(SUPPORTED_GITHUB_MODELS).forEach((name) => {
-  githubModel(name, client, ai);
-});
+for (const name of Object.keys(SUPPORTED_GITHUB_MODELS)) {
+  githubModel(name, client, ai);
+}
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 585b533 and 4855347.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (4)
  • package.json (1 hunks)
  • src/github_embedders.ts (4 hunks)
  • src/github_llms.ts (4 hunks)
  • src/index.ts (3 hunks)
🔇 Additional comments (10)
package.json (2)

28-28: LGTM: Azure SSE dependency version specification.

The explicit version specification for @azure/core-sse is appropriate.


31-31: Verify stability implications of using genkit dev version.

While the migration from @genkit-ai/{core,ai}@0.5.0 to genkit@0.9.0-dev.4 aligns with the PR objectives, using a development version (-dev.4) in production could pose stability risks:

  • Development versions may contain breaking changes
  • APIs might not be finalized
  • Future updates could be unpredictable

Please confirm:

  1. Is this dev version required for specific features?
  2. Are there plans to upgrade to a stable release?
  3. Has this version been thoroughly tested?

Let's check the dependency usage:

Consider:

  1. Adding a comment in package.json explaining why this specific dev version is required
  2. Creating an upgrade plan to move to the stable version when available
  3. Documenting any known limitations or issues with this version
✅ Verification successful

Using genkit dev version is appropriate in this context

The dev version usage is justified for the following reasons:

  1. This is a plugin package (genkitx-github) that properly declares genkit as a peer dependency, meaning the actual version used will be determined by the end application
  2. The git history shows a recent intentional upgrade to this version (refactor: major refactor done, bump genkit version to 0.9)
  3. The package itself is a community plugin for Firebase Genkit, and the version aligns with the current development state
  4. The dependency is properly scoped as a peer dependency, which is the correct pattern for plugin packages to avoid version conflicts

The stability concerns are mitigated by:

  • Clear version pinning (0.9.0-dev.4)
  • Proper peer dependency declaration allowing end users to override if needed
  • The plugin nature of the package, where version compatibility is an expected consideration
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the genkit dependency usage and potential breaking changes

# Test 1: Check for genkit imports and usage patterns
echo "Checking genkit import patterns..."
rg -l 'from\s+[\'"]genkit[\'"]|require\([\'"]genkit[\'"]\)' 

# Test 2: Look for any TODO/FIXME comments related to genkit version
echo "Checking for version-related comments..."
rg -i "todo|fixme|hack|xxx" -A 3 -B 3 | rg -i "genkit|0\.9|version"

Length of output: 172


Script:

#!/bin/bash
# Let's try a more comprehensive analysis

# Check for genkit imports with proper quoting and extended patterns
echo "=== Checking genkit import patterns ==="
rg -l "from genkit|require.*genkit|import.*genkit"

# Check package.json for any comments or related dependencies
echo -e "\n=== Analyzing package.json ==="
cat package.json

# Look for migration or upgrade related comments
echo -e "\n=== Checking for migration/upgrade comments ==="
rg -i "migration|upgrade|genkit" -A 3 -B 3

# Check git history for genkit related changes
echo -e "\n=== Recent genkit-related commits ==="
git log --grep="genkit" --pretty=format:"%h %s" -n 5

Length of output: 19070

src/github_embedders.ts (2)

18-18: LGTM! Import changes align with Genkit v0.9+ upgrade.

The addition of Genkit import while maintaining embedderRef properly supports the refactoring objectives.


93-97: LGTM! Function signature properly updated for Genkit v0.9+.

The addition of the ai: Genkit parameter follows good practices with proper type safety and maintains backward compatibility.

src/index.ts (2)

1-2: Imports updated appropriately.

The import statements for Genkit and genkitPlugin have been correctly updated to reflect the new module paths.


110-112: ⚠️ Potential issue

Fix syntax error due to unnecessary comma after function call.

There is an extra comma after the githubEmbedder function call, which may cause a syntax error.

Apply this diff to correct the issue:

-Object.keys(SUPPORTED_EMBEDDING_MODELS).forEach((name) =>
-  githubEmbedder(name, ai, options),
-);
+Object.keys(SUPPORTED_EMBEDDING_MODELS).forEach((name) => {
+  githubEmbedder(name, ai, options);
+});

Additionally, consider using a for...of loop for consistency:

+for (const name of Object.keys(SUPPORTED_EMBEDDING_MODELS)) {
+  githubEmbedder(name, ai, options);
+}

Likely invalid or redundant comment.

src/github_llms.ts (4)

19-27: Imports updated to include Genkit

The import statements have been correctly updated to import Genkit from the "genkit" package. This change ensures compatibility with the new Genkit library and aligns with the updates made in other parts of the code.


794-796: Function signature updated to accommodate Genkit instance

The githubModel function signature has been updated to include the ai: Genkit parameter. This change allows the function to utilize the Genkit instance for defining models, which is necessary for integration with the new Genkit API.


Line range hint 800-824: Model definition using ai.defineModel

The use of ai.defineModel to define the model ensures proper registration and integration within the Genkit framework. The modifications correctly pass the necessary model information and configuration to the defineModel method.


600-600: Verify access to msg.text property

The code now accesses msg.text as a property instead of calling it as a method with msg.text(). Please verify that msg.text is a property of the Message class and that this change does not affect the expected functionality.

To confirm that msg.text is a property, run the following script:

This script searches for the Message class definition in the TypeScript files and checks if there is a getter method for text, indicating that msg.text can be used as a property.

Also applies to: 608-608, 637-637

✅ Verification successful

Let's search for the Message class definition and its properties to understand how the text property is defined. I'm expanding the context lines to see more of the class definition and also including interface/type definitions that might be relevant.


Let's try to understand how msg.text is being used in the codebase and where the Message type/class is being imported from, which might help us trace its definition.


From the previous results, we can see that msg.text is consistently used as a property in multiple places. Let's try to find the actual Message type definition to confirm how the text property is declared.


Property access to msg.text appears to be the correct usage pattern

Based on the search results, we can see that msg.text is consistently used as a property access throughout the codebase in multiple locations (lines 600, 608, and 637 in src/github_llms.ts). This consistent usage pattern across different code paths suggests this is the intended way to access the text content. While we couldn't locate the exact Message type definition, the uniform property access pattern in the codebase indicates this change from method call to property access is correct.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify that `Message` class has a `text` property.

# Search for the `Message` class definition and check for a `text` getter.
fd --exclude node_modules --extension ts | xargs rg -A 5 'class Message' | rg 'get text\(\)'

Length of output: 94


Script:

#!/bin/bash
# Let's try a broader search to find the Message class definition and its properties
fd --exclude node_modules --extension ts | xargs rg -A 20 'class Message'

# Also search for any type definitions or interfaces related to Message
fd --exclude node_modules --extension ts | xargs rg -A 10 'interface Message|type Message'

Length of output: 168


Script:

#!/bin/bash
# Let's search for the actual usage of msg.text in the codebase to understand its context
rg -B 5 -A 5 'msg\.text'

# Also search for Message-related imports to find where it might be defined
rg 'import.*Message'

Length of output: 1297


Script:

#!/bin/bash
# Let's look at the Message type/interface definition by searching for its declaration
ast-grep --pattern 'interface Message {
  $$$
}'

# Also search for type Message = to catch type aliases
rg 'type Message ='

# Let's also look at the context where msg is defined
rg -B 10 'msg: Message'

Length of output: 98

src/index.ts Show resolved Hide resolved
Copy link
Contributor

@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 (2)
README.md (2)

36-38: Enhance version compatibility documentation.

While the version compatibility information is clear, consider these improvements for better user experience:

  1. Use a table format for better readability
  2. Add migration steps for users upgrading from v1.9.0 to v2.0.0
  3. Document any breaking changes between versions

Consider this format:

-### Versions
-
-if you are using Genkit version `<v0.9.0` or lower, please use the plugin version `v1.9.0`. If you are using Genkit `>=v0.9.0`, please use the plugin version `v2.0.0`.
+### Version Compatibility
+
+| Genkit Version | Plugin Version | Notes |
+|----------------|----------------|-------|
+| < v0.9.0       | v1.9.0         | Legacy version |
+| >= v0.9.0      | v2.0.0         | Current version |
+
+#### Migration Guide
+
+When upgrading from v1.9.0 to v2.0.0:
+1. Update your Genkit dependency to v0.9.0 or higher
+2. [Add migration steps here]
+
+#### Breaking Changes
+
+- [List breaking changes here]

Documentation needs updates to reflect current implementation

The documentation requires several updates to match the actual implementation:

  1. The import statement in examples is incorrect:
import {github, openAIGpt4o} from "genkitx-github";  // incorrect

Should be:

import {github, openAIGpt4o} from "@xavidop/genkitx-github";  // correct
  1. The troubleshooting section needs updates:

    • The note about GPT o1-preview and o1-mini is outdated as the implementation shows they support multiturn conversations
    • The Cohere models issue link is outdated as the implementation shows response format handling for non-Cohere models
  2. The supported models section needs expansion to list all the available models found in the implementation:

    • OpenAI models (GPT-4o, GPT-4o-mini, etc.)
    • Meta Llama models (3.x series)
    • Cohere models (Command-r series)
    • Mistral models
    • AI21 models
    • Microsoft Phi models
🔗 Analysis chain

Line range hint 42-185: Verify documentation accuracy post-refactor.

Since this PR involves a major refactor for Genkit v0.9+ compatibility, please verify if the following sections need updates:

  1. Code examples (they might need version-specific variants)
  2. Configuration section (might need version-specific instructions)
  3. Troubleshooting section (might need new known issues)

Let's verify if the imports and API usage in the documentation match the actual implementation:

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify if the documented imports and API patterns match the implementation

# Check if the documented imports exist in the codebase
echo "Checking documented imports..."
rg "export.*\b(github|openAIGpt4o)\b" src/

# Check if the documented API patterns exist
echo "Checking documented API patterns..."
rg "configureGenkit|defineFlow|defineTool" src/

Length of output: 402


Script:

#!/bin/bash
# Let's verify the actual API patterns and types in the codebase

# Check the actual plugin configuration pattern
echo "Checking plugin configuration pattern..."
ast-grep --pattern 'export function github($$$) { $$$' -f ts

# Check model usage patterns
echo "Checking model usage patterns..."
rg -A 5 "modelRef|generate" src/

# Check if there are any type definitions that might affect the documentation
echo "Checking type definitions..."
fd -e ts -e d.ts --exec cat {} \; 

Length of output: 38320

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 4855347 and 02c9dea.

📒 Files selected for processing (1)
  • README.md (1 hunks)

Copy link
Contributor

@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 (1)
src/github_llms.ts (1)

Line range hint 814-824: Add error handling for JSON parsing in streaming

The streaming implementation should handle potential JSON parsing errors to prevent crashes.

 for await (const event of sseStream) {
   if (event.data === "[DONE]") {
     break;
   }
-  for (const choice of JSON.parse(event.data).choices) {
-    const c = fromGithubChunkChoice(choice);
-    streamingCallback({
-      index: 0,
-      content: [{ ...c, custom: c.custom as Record<string, any> }],
-    });
+  try {
+    const data = JSON.parse(event.data);
+    for (const choice of data.choices) {
+      const c = fromGithubChunkChoice(choice);
+      streamingCallback({
+        index: 0,
+        content: [{ ...c, custom: c.custom as Record<string, any> }],
+      });
+    }
+  } catch (error) {
+    console.error('Error parsing streaming response:', error);
+    throw new Error('Failed to parse streaming response');
+  }
 }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 02c9dea and ac87066.

📒 Files selected for processing (1)
  • src/github_llms.ts (9 hunks)
🔇 Additional comments (4)
src/github_llms.ts (4)

19-34: LGTM: Import changes align with Genkit upgrade

The reorganization of imports from 'genkit' and 'genkit/model' properly aligns with the migration to Genkit version 0.9+.


665-665: LGTM: Type definitions properly aligned with Genkit API

The updated type definitions using ModelResponseData improve type safety and correctly align with the new Genkit API.

Also applies to: 692-692, 714-724


792-793: LGTM: Function signature updated for Genkit compatibility

The addition of the ai: Genkit parameter aligns with the new Genkit API requirements.


600-600: Verify consistent usage of Message.text property

The change from msg.text() to msg.text reflects an API change in the Message class. Let's verify that this change has been consistently applied across the codebase.

Also applies to: 608-608, 637-637

Copy link
Contributor

@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 (1)
.github/workflows/depsreview.yaml (1)

14-14: Add newline at end of file.

YAML files should end with a newline character to comply with POSIX standards.

-          allow-licenses: BSD-2-Clause, BSD-3-Clause, MIT, Apache-2.0, MPL-2.0, ISC, LGPL-3.0, 0BSD, BSD-3-Clause-Clear
+          allow-licenses: BSD-2-Clause, BSD-3-Clause, MIT, Apache-2.0, MPL-2.0, ISC, LGPL-3.0, 0BSD, BSD-3-Clause-Clear
+
🧰 Tools
🪛 yamllint

[error] 14-14: no new line character at the end of file

(new-line-at-end-of-file)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between ac87066 and 96be15a.

📒 Files selected for processing (1)
  • .github/workflows/depsreview.yaml (1 hunks)
🧰 Additional context used
🪛 yamllint
.github/workflows/depsreview.yaml

[error] 14-14: no new line character at the end of file

(new-line-at-end-of-file)

🔇 Additional comments (1)
.github/workflows/depsreview.yaml (1)

14-14: LGTM: License addition is appropriate.

The addition of BSD-3-Clause-Clear to the allowed licenses list is consistent with common open-source licensing practices and aligns with the dependency changes in this PR.

🧰 Tools
🪛 yamllint

[error] 14-14: no new line character at the end of file

(new-line-at-end-of-file)

Copy link
Contributor

@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 (4)
.github/workflows/depsreview.yaml (2)

14-14: Improve readability of license list.

The license list should have consistent spacing after commas for better readability.

-          allow-licenses: BSD-2-Clause, MIT, Apache-2.0, MPL-2.0, ISC, LGPL-3.0, 0BSD, BSD-3-Clause, BSD-3-Clause AND BSD-3-Clause-Clear
+          allow-licenses: BSD-2-Clause, MIT, Apache-2.0, MPL-2.0, ISC, LGPL-3.0, 0BSD, BSD-3-Clause, BSD-3-Clause, BSD-3-Clause-Clear
🧰 Tools
🪛 yamllint

[error] 14-14: no new line character at the end of file

(new-line-at-end-of-file)


14-14: Add newline at end of file.

Add a newline character at the end of the file to comply with YAML formatting standards.

           allow-licenses: BSD-2-Clause, MIT, Apache-2.0, MPL-2.0, ISC, LGPL-3.0, 0BSD, BSD-3-Clause, BSD-3-Clause AND BSD-3-Clause-Clear
+
🧰 Tools
🪛 yamllint

[error] 14-14: no new line character at the end of file

(new-line-at-end-of-file)

src/github_llms.ts (2)

Line range hint 714-724: Consider improving type safety in fromGithubChunkChoice.

The function uses any type for its parameter, which could lead to runtime errors. Consider defining a proper interface for the chunk choice parameter.

-function fromGithubChunkChoice(choice: any): ModelResponseData {
+interface GithubChunkChoice {
+  content?: string;
+  finishReason?: string;
+  delta?: {
+    content?: string;
+  };
+}
+function fromGithubChunkChoice(choice: GithubChunkChoice): ModelResponseData {

Line range hint 792-848: Add error handling for streaming response.

While the changes to use ai.defineModel are correct, the streaming response handling could be improved with proper error handling.

       if (streamingCallback) {
         body.body.stream = true;
         response = await client.path("/chat/completions").post(body);
         const stream = response.body;
         const sseStream = createSseStream(stream as any);
+        try {
           for await (const event of sseStream) {
             if (event.data === "[DONE]") {
               break;
             }
-            for (const choice of JSON.parse(event.data).choices) {
+            const parsedData = JSON.parse(event.data);
+            if (!parsedData.choices) {
+              throw new Error('Invalid response format: missing choices');
+            }
+            for (const choice of parsedData.choices) {
               const c = fromGithubChunkChoice(choice);
               streamingCallback({
                 content: [{ ...c, custom: c.custom as Record<string, any> }],
               });
             }
           }
+        } catch (error) {
+          throw new Error(`Error processing streaming response: ${error.message}`);
+        }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 96be15a and 4481cf7.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (3)
  • .github/workflows/depsreview.yaml (1 hunks)
  • package.json (1 hunks)
  • src/github_llms.ts (9 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • package.json
🧰 Additional context used
🪛 yamllint
.github/workflows/depsreview.yaml

[error] 14-14: no new line character at the end of file

(new-line-at-end-of-file)

🔇 Additional comments (3)
.github/workflows/depsreview.yaml (1)

12-12: LGTM! Good practice to pin to specific version.

Pinning to v4.3.3 instead of v4 ensures workflow stability and predictability.

src/github_llms.ts (2)

19-34: LGTM: Import changes align with Genkit upgrade.

The reorganization of imports to use the new genkit library is correct and consistent with the PR's objective of upgrading to Genkit version 0.9.


600-600: Verify the message text access pattern changes.

The changes from msg.text() to msg.text reflect an API change in the new Genkit version. Let's verify that this pattern is consistently applied across the codebase.

Also applies to: 608-608, 637-637

✅ Verification successful

The previous search might have been too specific. Let's broaden the search to find all message text access patterns and verify the consistency of the changes.


Message text access pattern is consistent across the codebase

The verification shows that all occurrences of msg.text in the codebase are using the property access pattern (not the method call pattern msg.text()). The changes are consistently applied in all three locations in src/github_llms.ts (lines 600, 608, and 637).

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for any remaining occurrences of the old pattern
rg 'msg\.text\(\)' 

Length of output: 20


Script:

#!/bin/bash
# Search for any occurrences of msg.text (both as property and method)
rg -A 2 'msg\.text'

# Also search for potential message text access patterns
ast-grep --pattern 'msg.text'

Length of output: 554

xavidop and others added 4 commits November 11, 2024 13:58
Bumps [typescript-eslint](https://github.com/typescript-eslint/typescript-eslint/tree/HEAD/packages/typescript-eslint) from 8.13.0 to 8.14.0.
- [Release notes](https://github.com/typescript-eslint/typescript-eslint/releases)
- [Changelog](https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/typescript-eslint/CHANGELOG.md)
- [Commits](https://github.com/typescript-eslint/typescript-eslint/commits/v8.14.0/packages/typescript-eslint)

---
updated-dependencies:
- dependency-name: typescript-eslint
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Xavier Portilla Edo <xavi_tb@hotmail.com>
@xavidop xavidop changed the title refactor: major refactor done, bump genkit version to 0.9. Change Plu… BREAKING CHANGE: major refactor done, bump genkit version to 0.9. Nov 14, 2024
Bumps [typescript-eslint](https://github.com/typescript-eslint/typescript-eslint/tree/HEAD/packages/typescript-eslint) from 8.13.0 to 8.14.0.
- [Release notes](https://github.com/typescript-eslint/typescript-eslint/releases)
- [Changelog](https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/typescript-eslint/CHANGELOG.md)
- [Commits](https://github.com/typescript-eslint/typescript-eslint/commits/v8.14.0/packages/typescript-eslint)

---
updated-dependencies:
- dependency-name: typescript-eslint
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Xavier Portilla Edo <xavi_tb@hotmail.com>
@xavidop xavidop changed the title BREAKING CHANGE: major refactor done, bump genkit version to 0.9. BREAKING CHANGE: major refactor done, bump genkit version to 0.9 Nov 14, 2024
Copy link

sonarcloud bot commented Nov 14, 2024

@xavidop xavidop merged commit 6863b72 into main Nov 14, 2024
6 of 7 checks passed
@xavidop xavidop deleted the xavier/genkit-09 branch November 14, 2024 16:45
Copy link

🎉 This PR is included in version 1.10.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@coderabbitai coderabbitai bot mentioned this pull request Nov 15, 2024
7 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant