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

[Components] kindo - new action #15755

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

[Components] kindo - new action #15755

wants to merge 1 commit into from

Conversation

jcortes
Copy link
Collaborator

@jcortes jcortes commented Feb 26, 2025

WHY

Resolves #15729

Summary by CodeRabbit

  • New Features

    • Introduced a dynamic chat action that generates model responses for conversational interactions.
    • Added configuration utilities for processing input data.
    • Enhanced request handling with automated URL construction and header management.
  • Chores

    • Updated the package version to 0.1.0 and included new dependencies for improved stability.

@jcortes jcortes self-assigned this Feb 26, 2025
Copy link

vercel bot commented Feb 26, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

3 Skipped Deployments
Name Status Preview Comments Updated (UTC)
docs-v2 ⬜️ Ignored (Inspect) Visit Preview Feb 28, 2025 2:43pm
pipedream-docs ⬜️ Ignored (Inspect) Feb 28, 2025 2:43pm
pipedream-docs-redirect-do-not-edit ⬜️ Ignored (Inspect) Feb 28, 2025 2:43pm

Copy link
Contributor

coderabbitai bot commented Feb 26, 2025

Walkthrough

The pull request introduces a new chat module that integrates with Kindo’s API for generating chat responses. It adds utility functions for recursive JSON and array parsing and enhances the Kindo app configuration with methods for URL construction, headers management, and HTTP requests, while deprecating the old authentication method. The package metadata is updated to reflect a new version and dependency requirements.

Changes

Files Change Summary
components/kindo/actions/…/chat.mjs Added a new chat action module that constructs payloads with configuration parameters and sends a POST request to the Kindo API for chat completions.
components/kindo/common/…/utils.mjs Introduced two utility functions, parseJson and parseArray, with adjustments to the export mapping to ensure consistent recursive processing of input values.
components/kindo/kindo.app.mjs Added methods (getUrl, getHeaders, makeRequest, and post) for structured HTTP request handling and removed the deprecated authKeys method.
components/kindo/package.json Updated the package version from "0.0.1" to "0.1.0" and added a dependency on @pipedream/platform with the version constraint "^3.0.3".

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant ChatModule as chat.mjs
    participant API as Kindo API

    Client->>ChatModule: Invoke run() with parameters
    ChatModule->>ChatModule: Prepare payload and configuration
    ChatModule->>API: Send POST request with payload
    API-->>ChatModule: Return chat completion response
    ChatModule-->>Client: Return API response with summary
Loading

Possibly related PRs

  • [Components] 360nrs #12862: The changes in the main PR, which introduce a new chat module with methods for handling API requests, are related to the retrieved PR as both include the addition of methods for making HTTP requests, specifically getHeaders and post in the main PR and similar methods in the retrieved PR.

Suggested labels

action, ai-assisted

Suggested reviewers

  • GTFalcao

Poem

I'm a little rabbit, hopping through the code,
New chat features and utilities on a bouncy road.
With APIs and headers, each step is neat,
Every function and method makes the product complete.
Hoppin' along in our digital abode!
🐰🚀

Warning

There were issues while running some tools. Please review the errors and either fix the tool’s configuration or disable the tool if it’s a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

components/kindo/actions/chat/chat.mjs

Oops! Something went wrong! :(

ESLint: 8.57.1

Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'jsonc-eslint-parser' imported from /eslint.config.mjs
at packageResolve (node:internal/modules/esm/resolve:839:9)
at moduleResolve (node:internal/modules/esm/resolve:908:18)
at defaultResolve (node:internal/modules/esm/resolve:1038:11)
at ModuleLoader.defaultResolve (node:internal/modules/esm/loader:557:12)
at ModuleLoader.resolve (node:internal/modules/esm/loader:525:25)
at ModuleLoader.getModuleJob (node:internal/modules/esm/loader:246:38)
at ModuleJob._link (node:internal/modules/esm/module_job:126:49)

components/kindo/common/utils.mjs

Oops! Something went wrong! :(

ESLint: 8.57.1

Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'jsonc-eslint-parser' imported from /eslint.config.mjs
at packageResolve (node:internal/modules/esm/resolve:839:9)
at moduleResolve (node:internal/modules/esm/resolve:908:18)
at defaultResolve (node:internal/modules/esm/resolve:1038:11)
at ModuleLoader.defaultResolve (node:internal/modules/esm/loader:557:12)
at ModuleLoader.resolve (node:internal/modules/esm/loader:525:25)
at ModuleLoader.getModuleJob (node:internal/modules/esm/loader:246:38)
at ModuleJob._link (node:internal/modules/esm/module_job:126:49)

components/kindo/kindo.app.mjs

Oops! Something went wrong! :(

ESLint: 8.57.1

Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'jsonc-eslint-parser' imported from /eslint.config.mjs
at packageResolve (node:internal/modules/esm/resolve:839:9)
at moduleResolve (node:internal/modules/esm/resolve:908:18)
at defaultResolve (node:internal/modules/esm/resolve:1038:11)
at ModuleLoader.defaultResolve (node:internal/modules/esm/loader:557:12)
at ModuleLoader.resolve (node:internal/modules/esm/loader:525:25)
at ModuleLoader.getModuleJob (node:internal/modules/esm/loader:246:38)
at ModuleJob._link (node:internal/modules/esm/module_job:126:49)

✨ Finishing Touches
  • 📝 Generate Docstrings

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

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

🧹 Nitpick comments (1)
components/kindo/common/utils.mjs (1)

49-52: Optional chaining may be unnecessary

The optional chaining operator (?.) in the exported parseArray wrapper is technically unnecessary since the function already guarantees either an array return or throws an error.

-  parseArray: (value) => parseArray(value)?.map(parseJson),
+  parseArray: (value) => parseArray(value).map(parseJson),
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between db6687e and 11556cb.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (4)
  • components/kindo/actions/chat/chat.mjs (1 hunks)
  • components/kindo/common/utils.mjs (1 hunks)
  • components/kindo/kindo.app.mjs (1 hunks)
  • components/kindo/package.json (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: pnpm publish
  • GitHub Check: Verify TypeScript components
  • GitHub Check: Publish TypeScript components
🔇 Additional comments (11)
components/kindo/package.json (2)

3-3: Version bump is appropriate for feature additions

The version has been incremented from 0.0.1 to 0.1.0, which follows semantic versioning principles for adding new features without breaking changes.


15-16: Dependencies aligned with implementation requirements

Adding @pipedream/platform as a dependency is appropriate as it's used throughout the implementation for ConfigurationError and axios functionality.

components/kindo/common/utils.mjs (2)

3-24: Well-structured recursive JSON parsing implementation

The parseJson function is well-implemented with proper handling of different data types and recursive parsing of nested objects.


26-47: Robust array parsing with appropriate error handling

The array parsing function provides good validation and clear error messages for configuration issues.

One observation - returning an empty array for falsy values (line 29) is a design choice that makes the function more resilient but could potentially mask errors if null or undefined are passed unintentionally.

components/kindo/actions/chat/chat.mjs (3)

7-8: Clear and informative component description

The description provides good context with a link to relevant documentation.


65-71: Clean implementation of chat method

The chat method elegantly leverages the app's post method with appropriate path and argument forwarding.


73-103: Well-structured run method with appropriate data transformation

The run method correctly:

  1. Destructures properties
  2. Transforms data for the API (using snake_case where needed)
  3. Utilizes the utility functions for parsing
  4. Properly handles the response and exports a summary
components/kindo/kindo.app.mjs (4)

1-1: Appropriate dependency import

Importing axios from the platform package is consistent with the package.json dependencies.


7-16: Well-structured URL and headers helper methods

The getUrl and getHeaders methods provide clean abstractions for constructing URLs and headers, with proper authentication.


17-25: Robust request implementation with good defaults

The makeRequest method is well-implemented with:

  • Default context parameter
  • Proper spreading of additional arguments
  • Utilization of helper methods for URL and headers construction

26-31: Convenient post method wrapper

The post method provides a clean abstraction for POST requests, simplifying code in consuming components.

michelle0927
michelle0927 previously approved these changes Feb 26, 2025
Copy link
Collaborator

@michelle0927 michelle0927 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

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

🧹 Nitpick comments (1)
components/kindo/actions/chat/chat.mjs (1)

87-100: Verify data validation for required parameters.

The code doesn't validate that required parameters like model and messages are present before making the API call. Consider adding validation to improve error handling.

    const response = await chat({
      $,
      data: {
+       // Ensure model is provided
        model,
+       // Parse messages array and validate it's not empty
        messages: utils.parseArray(messages),
        max_tokens: maxTokens,
        temperature,
        top_p: topP,
        n,
        stop,
        presence_penalty: presencePenalty,
        frequency_penalty: frequencyPenalty,
      },
    });
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 11556cb and aa8e908.

📒 Files selected for processing (1)
  • components/kindo/actions/chat/chat.mjs (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: Verify TypeScript components
  • GitHub Check: pnpm publish
  • GitHub Check: Publish TypeScript components
🔇 Additional comments (7)
components/kindo/actions/chat/chat.mjs (7)

1-3: LGTM: Import statements.

The imports are correctly structured to pull in the app configuration and utility functions needed for this component.


4-9: LGTM: Component metadata configuration.

The component metadata is well-structured with a clear key, name, description and appropriate versioning.


10-21: Remove OpenAI documentation references.

The messages property description still contains references to OpenAI documentation which is inconsistent with a Kindo component. These should be updated to reference Kindo-specific documentation.

-      description: "A list of messages comprising the conversation so far. Depending on the [model](https://app.kindo.ai/settings/api) you use, different message types (modalities) are supported, like [text](https://platform.openai.com/docs/guides/text-generation), [images](https://platform.openai.com/docs/guides/vision), and [audio](https://platform.openai.com/docs/guides/audio). [See the documentation](https://platform.openai.com/docs/api-reference/chat/create#chat-create-messages) for more information. Eg. `[{\"role\": \"user\", \"content\": \"Hello, world!\"}]`",
+      description: "A list of messages comprising the conversation so far. Depending on the [model](https://app.kindo.ai/settings/api) you use, different message types (modalities) are supported. [See the documentation](https://app.kindo.ai/settings/api) for more information. Eg. `[{\"role\": \"user\", \"content\": \"Hello, world!\"}]`",

28-63: LGTM: Configuration for advanced parameters.

The advanced parameters (temperature, topP, n, stop, presencePenalty, frequencyPenalty) are well-defined with clear descriptions and appropriate types.


65-72: LGTM: Chat method implementation.

The chat method is concisely implemented to delegate to the app's post method with the appropriate endpoint.


73-86: LGTM: Run method setup.

The run method correctly destructures all the necessary properties from the context.


101-103: LGTM: Response handling.

The export of a summary message and return of the response is handled correctly.

@jcortes jcortes force-pushed the kindo-new-components branch from aa8e908 to 24430f9 Compare February 27, 2025 16:25
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

🧹 Nitpick comments (2)
components/kindo/actions/chat/chat.mjs (2)

28-33: Replace OpenAI reference in temperature description

The temperature description references OpenAI-specific content which should be updated for Kindo.

-      description: "**Optional**. What [sampling temperature](https://towardsdatascience.com/how-to-sample-from-language-models-682bceb97277) to use. Higher values means the model will take more risks. Try `0.9` for more creative applications, and `0` (argmax sampling) for ones with a well-defined answer.",
+      description: "**Optional**. What sampling temperature to use. Higher values means the model will take more risks. Try `0.9` for more creative applications, and `0` for ones with a well-defined answer.",

117-119: Consider enhancing response summary

The current summary is generic. Consider enhancing it to include information about the completion, such as the number of tokens generated or the first few words of the response.

-    $.export("$summary", "Successfully created model response");
+    $.export("$summary", `Successfully created model response (${response.choices?.[0]?.message?.content?.substring(0, 50)}...)`);
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between aa8e908 and 24430f9.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (4)
  • components/kindo/actions/chat/chat.mjs (1 hunks)
  • components/kindo/common/utils.mjs (1 hunks)
  • components/kindo/kindo.app.mjs (1 hunks)
  • components/kindo/package.json (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • components/kindo/common/utils.mjs
  • components/kindo/kindo.app.mjs
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: Publish TypeScript components
  • GitHub Check: pnpm publish
  • GitHub Check: Verify TypeScript components
🔇 Additional comments (5)
components/kindo/package.json (2)

3-3: Version bump looks appropriate.

The version update from 0.0.1 to 0.1.0 follows semantic versioning principles, correctly indicating the addition of new functionality (the chat action) without breaking changes.


14-16: Dependencies addition is appropriate.

Adding @pipedream/platform as a dependency is appropriate for the new functionality introduced in this PR. The version constraint ^3.0.3 allows for compatible updates.

components/kindo/actions/chat/chat.mjs (3)

19-21: Fix the unbalanced quote in messages description and update OpenAI references

The description has a syntax error with an unbalanced quote at the end. Additionally, it references OpenAI documentation which seems out of place for a Kindo component.

-      description: "A list of messages comprising the conversation so far. Depending on the [model](https://app.kindo.ai/settings/api) you use, different message types (modalities) are supported, like [text](https://platform.openai.com/docs/guides/text-generation), [images](https://platform.openai.com/docs/guides/vision), and [audio](https://platform.openai.com/docs/guides/audio). [See the documentation](https://platform.openai.com/docs/api-reference/chat/create#chat-create-messages) for more information. Eg. `[{\"role\": \"user\", \"content\": \"Hello, world!\"}]",
+      description: "A list of messages comprising the conversation so far. Depending on the [model](https://app.kindo.ai/settings/api) you use, different message types (modalities) are supported, like text, images, and audio. [See the documentation](https://app.kindo.ai/settings/api) for more information. Eg. `[{\"role\": \"user\", \"content\": \"Hello, world!\"}]`",

22-27: Update tokenizer link to Kindo-specific documentation

The maxTokens description links to OpenAI's tokenizer, which should be replaced with a Kindo equivalent.

-      description: "The maximum number of [tokens](https://beta.openai.com/tokenizer) to generate in the completion.",
+      description: "The maximum number of tokens to generate in the completion.",

94-116: Looks good: Proper API request construction

The chat method correctly constructs the API request with all required and optional parameters. The use of utils.parseArray() for messages is appropriate for handling user input, and the conversion of string values to numbers where needed (using the + operator) is a good practice.

@jcortes jcortes force-pushed the kindo-new-components branch from 24430f9 to 1f325fb Compare February 28, 2025 14:43
@jcortes
Copy link
Collaborator Author

jcortes commented Feb 28, 2025

/approve

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

🧹 Nitpick comments (3)
components/kindo/kindo.app.mjs (3)

7-9: Consider handling path formatting to ensure consistency.

The getUrl method doesn't handle cases where the provided path might not start with a forward slash, which could lead to malformed URLs. Consider normalizing the path parameter to ensure consistent URL construction.

getUrl(path) {
-  return `https://llm.kindo.ai/v1${path}`;
+  const normalizedPath = path.startsWith('/') ? path : `/${path}`;
+  return `https://llm.kindo.ai/v1${normalizedPath}`;
}

14-14: Consider adding validation for API key.

The code assumes this.$auth.api_key will always be available. Consider adding validation to handle cases where the API key might be missing.

"content-type": "application/json",
-"api-key": this.$auth.api_key,
+"api-key": this.$auth.api_key || (() => { throw new Error("API key is required") })(),

17-25: Consider adding basic error handling for API requests.

The makeRequest method doesn't include any error handling. Consider adding try/catch blocks or error transformations to provide more context-specific error messages when API calls fail.

makeRequest({
  $ = this, path, headers, ...args
} = {}) {
-  return axios($, {
-    ...args,
-    url: this.getUrl(path),
-    headers: this.getHeaders(headers),
-  });
+  try {
+    return axios($, {
+      ...args,
+      url: this.getUrl(path),
+      headers: this.getHeaders(headers),
+    });
+  } catch (error) {
+    const errorMessage = error.response?.data?.message || error.message;
+    throw new Error(`Kindo API request failed: ${errorMessage}`);
+  }
}
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 24430f9 and 1f325fb.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (4)
  • components/kindo/actions/chat/chat.mjs (1 hunks)
  • components/kindo/common/utils.mjs (1 hunks)
  • components/kindo/kindo.app.mjs (1 hunks)
  • components/kindo/package.json (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (3)
  • components/kindo/package.json
  • components/kindo/common/utils.mjs
  • components/kindo/actions/chat/chat.mjs
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: pnpm publish
  • GitHub Check: Publish TypeScript components
  • GitHub Check: Verify TypeScript components
🔇 Additional comments (3)
components/kindo/kindo.app.mjs (3)

10-16: LGTM! Good header management implementation.

The header construction follows best practices by combining custom headers with required API authentication. The method is well-structured and properly includes the API key from authentication.


26-31: Good implementation of the POST method wrapper.

The post method provides a clean abstraction for making POST requests, which simplifies the code in action components that need to make POST calls to the Kindo API.


1-33: Overall code structure is well-organized and follows good patterns.

The implementation follows a clean, modular approach with clear separation of concerns:

  1. URL construction
  2. Header management
  3. Generic request handling
  4. Specialized HTTP method abstractions

This structure will make it easy to maintain and extend the Kindo integration.

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.

[Components] kindo
3 participants