Skip to content

OpenAI - Chat Tools #15900

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

Merged
merged 17 commits into from
Mar 12, 2025
Merged

OpenAI - Chat Tools #15900

merged 17 commits into from
Mar 12, 2025

Conversation

andrewjschuang
Copy link
Collaborator

@andrewjschuang andrewjschuang commented Mar 12, 2025

Part of #15862.

Summary by CodeRabbit

  • New Features

    • Introduced a chat option that leverages file search, enabling seamless interactions with content stored in file repositories.
    • Launched a chat feature with function integration, allowing dynamic invocation of additional operations during conversations.
    • Rolled out a web search–powered chat experience that incorporates real-time search context into user interactions.
    • Enhanced chat interfaces with informative alerts linking to related chat actions.
    • Expanded communication capabilities through improved response handling and model support.
  • Version Updates

    • Updated multiple modules to reflect new version increments, ensuring users have access to the latest features and improvements.
    • Updated the package version to 0.9.0.

Copy link

vercel bot commented Mar 12, 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 Mar 12, 2025 3:21pm
pipedream-docs ⬜️ Ignored (Inspect) Mar 12, 2025 3:21pm
pipedream-docs-redirect-do-not-edit ⬜️ Ignored (Inspect) Mar 12, 2025 3:21pm

Copy link
Contributor

coderabbitai bot commented Mar 12, 2025

Walkthrough

This pull request introduces three new chat modules—Chat using File Search, Chat using Functions, and Chat using Web Search—that implement asynchronous run methods and dynamic additionalProps functions. Additionally, it enhances two existing chat components by adding an alert property with contextual links. Finally, two new methods are added to the OpenAI application module to support reasoning model identification and to handle API responses through a POST request.

Changes

File(s) Change Summary
components/openai/actions/chat-using-file-search/chat-using-file-search.mjs, components/openai/actions/chat-using-functions/chat-using-functions.mjs, components/openai/actions/chat-using-web-search/chat-using-web-search.mjs Introduced new modules that export default objects with asynchronous run methods and an additionalProps function to configure and execute chat actions with file search, function invocation, and web search capabilities.
components/openai/actions/chat-with-assistant/chat-with-assistant.mjs, components/openai/actions/chat/chat.mjs Added an alert property to the exported default objects to provide contextual information and links to related chat actions.
components/openai/openai.app.mjs Added two utility methods: isReasoningModel, which identifies reasoning models based on naming conventions, and responses, which sends a POST request to handle API responses.
components/openai/actions/analyze-image-content/analyze-image-content.mjs, components/openai/actions/cancel-run/cancel-run.mjs, components/openai/actions/classify-items-into-categories/classify-items-into-categories.mjs, components/openai/actions/convert-text-to-speech/convert-text-to-speech.mjs, components/openai/actions/create-assistant/create-assistant.mjs, components/openai/actions/create-batch/create-batch.mjs, components/openai/actions/create-embeddings/create-embeddings.mjs, components/openai/actions/create-fine-tuning-job/create-fine-tuning-job.mjs, components/openai/actions/create-image/create-image.mjs, components/openai/actions/create-moderation/create-moderation.mjs, components/openai/actions/create-thread/create-thread.mjs, components/openai/actions/create-vector-store-file/create-vector-store-file.mjs, components/openai/actions/create-vector-store/create-vector-store.mjs, components/openai/actions/delete-file/delete-file.mjs, components/openai/actions/delete-vector-store-file/delete-vector-store-file.mjs, components/openai/actions/delete-vector-store/delete-vector-store.mjs, components/openai/actions/list-files/list-files.mjs, components/openai/actions/list-messages/list-messages.mjs, components/openai/actions/list-run-steps/list-run-steps.mjs, components/openai/actions/list-runs/list-runs.mjs, components/openai/actions/list-vector-store-files/list-vector-store-files.mjs, components/openai/actions/list-vector-stores/list-vector-stores.mjs, components/openai/actions/modify-assistant/modify-assistant.mjs, components/openai/actions/retrieve-file-content/retrieve-file-content.mjs, components/openai/actions/retrieve-file/retrieve-file.mjs, components/openai/actions/retrieve-run-step/retrieve-run-step.mjs, components/openai/actions/retrieve-run/retrieve-run.mjs, components/openai/actions/retrieve-vector-store-file/retrieve-vector-store-file.mjs, components/openai/actions/retrieve-vector-store/retrieve-vector-store.mjs, components/openai/actions/send-prompt/send-prompt.mjs, components/openai/actions/submit-tool-outputs-to-run/submit-tool-outputs-to-run.mjs, components/openai/actions/summarize/summarize.mjs, components/openai/actions/translate-text/translate-text.mjs, components/openai/actions/upload-file/upload-file.mjs, components/openai/sources/new-batch-completed/new-batch-completed.mjs, components/openai/sources/new-file-created/new-file-created.mjs, components/openai/sources/new-fine-tuning-job-created/new-fine-tuning-job-created.mjs, components/openai/sources/new-run-state-changed/new-run-state-changed.mjs Updated version numbers across various modules without altering functionality.

Possibly related PRs

  • OpenAI: Added support for structured outputs in Chat action #13725: The changes in the main PR introduce a new module with methods that include additionalProps and a structured run function, while the retrieved PR enhances the existing Chat action by adding support for structured outputs and a new json_schema option, which also utilizes additionalProps, indicating a direct relationship in functionality.
  • OpenAI - Vector Store and Vector Store Files actions #14435: The changes in the main PR introduce a new module for interacting with a knowledge base through chat, while the retrieved PR focuses on implementing actions related to OpenAI's Vector Stores and Vector Store Files, which includes creating and managing vector stores; thus, they are related at the code level through their shared focus on vector store functionalities.

Suggested labels

enhancement, action, actions

Poem

I'm just a rabbit with code so bright,
Hopping through modules from morning 'til night.
With chat actions new and functions to share,
I spread the news with a digital flair.
Carrots and code—a hopping delight!

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.

Scope: all 2 workspace projects
 ERR_PNPM_OPTIONAL_DEPS_REQUIRE_PROD_DEPS  Optional dependencies cannot be installed without production dependencies


📜 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 35d1467 and a05ef4d.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (3)
  • components/openai/actions/chat-using-file-search/chat-using-file-search.mjs (1 hunks)
  • components/openai/actions/chat-using-functions/chat-using-functions.mjs (1 hunks)
  • components/openai/actions/chat-using-web-search/chat-using-web-search.mjs (1 hunks)
🧰 Additional context used
🪛 GitHub Check: Lint Code Base
components/openai/actions/chat-using-functions/chat-using-functions.mjs

[warning] 14-14:
Component prop alert must have a label. See https://pipedream.com/docs/components/guidelines/#props


[warning] 14-14:
Component prop alert must have a description. See https://pipedream.com/docs/components/guidelines/#props

components/openai/actions/chat-using-file-search/chat-using-file-search.mjs

[warning] 14-14:
Component prop alert must have a label. See https://pipedream.com/docs/components/guidelines/#props


[warning] 14-14:
Component prop alert must have a description. See https://pipedream.com/docs/components/guidelines/#props

⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Verify TypeScript components
  • GitHub Check: Publish TypeScript components
🔇 Additional comments (1)
components/openai/actions/chat-using-web-search/chat-using-web-search.mjs (1)

1-201: No major concerns.

All the property definitions, including userLocation and searchContextSize, are well-structured and consistent with the overall approach. The JSON parsing for the jsonSchema has a proper try/catch block, which is a good defensive practice. This file looks well-implemented with no critical issues.

✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 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: 4

🧹 Nitpick comments (4)
components/openai/openai.app.mjs (1)

341-343: Consider returning a boolean or handling null input.

The function currently returns the length of the matches, which can be undefined if model is null/undefined or doesn't match. You might want to explicitly handle these edge cases and/or return a boolean for clarity.

    isReasoningModel(model) {
-      return model.match(/^o[1-9]/gi)?.length;
+      const match = model?.match(/^o[1-9]/gi);
+      return !!match?.length;
    },
components/openai/actions/chat-using-functions/chat-using-functions.mjs (1)

178-240: Validate input parsing and error handling.

The run method logic looks consistent. Note that any malformed JSON in the functions prop would trigger a runtime error in JSON.parse(). Providing a user-friendly error message or a try-catch block might improve robustness.

    let functions = this.functions;
    if (typeof functions === "string") {
-      functions = JSON.parse(functions);
+      try {
+        functions = JSON.parse(functions);
+      } catch (err) {
+        throw new Error("Invalid JSON for the 'functions' prop: " + err.message);
+      }
    }
components/openai/actions/chat-using-file-search/chat-using-file-search.mjs (1)

134-136: Address the 'TODO' comment for user-friendly configuration.

The code hints that you'd like to make metadata filtering more user-friendly. This can enhance discoverability and lower the learning curve for users.

I can suggest a refined UI approach or open a new issue to explore advanced user-friendly metadata filtering patterns. Would you like to proceed with a proposal?

components/openai/actions/chat-using-web-search/chat-using-web-search.mjs (1)

175-178: Add error handling for external OpenAI calls.

Any unhandled exception from await this.openai.responses() could halt the workflow abruptly. Implementing a try-catch block will improve reliability.

Here's a possible diff to handle exceptions gracefully:

 async run({ $ }) {
   if (this.skipThisStep) {
     $.export("$summary", "Step execution skipped");
     return;
   }

-  const response = await this.openai.responses({
-    $,
-    data,
-  });
+  let response;
+  try {
+    response = await this.openai.responses({
+      $,
+      data,
+    });
+  } catch (err) {
+    throw new Error(`Failed to fetch web search results: ${err}`);
+  }

   if (response) {
     $.export("$summary", `Successfully sent chat with id ${response.id}`);
   }

   return response;
 }
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between caaf754 and 979e997.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (6)
  • components/openai/actions/chat-using-file-search/chat-using-file-search.mjs (1 hunks)
  • components/openai/actions/chat-using-functions/chat-using-functions.mjs (1 hunks)
  • components/openai/actions/chat-using-web-search/chat-using-web-search.mjs (1 hunks)
  • components/openai/actions/chat-with-assistant/chat-with-assistant.mjs (1 hunks)
  • components/openai/actions/chat/chat.mjs (1 hunks)
  • components/openai/openai.app.mjs (2 hunks)
🧰 Additional context used
🪛 GitHub Check: Lint Code Base
components/openai/actions/chat-with-assistant/chat-with-assistant.mjs

[warning] 13-13:
Component prop alert must have a label. See https://pipedream.com/docs/components/guidelines/#props


[warning] 13-13:
Component prop alert must have a description. See https://pipedream.com/docs/components/guidelines/#props

components/openai/actions/chat-using-functions/chat-using-functions.mjs

[warning] 14-14:
Component prop alert must have a label. See https://pipedream.com/docs/components/guidelines/#props


[warning] 14-14:
Component prop alert must have a description. See https://pipedream.com/docs/components/guidelines/#props

components/openai/actions/chat/chat.mjs

[warning] 15-15:
Component prop alert must have a label. See https://pipedream.com/docs/components/guidelines/#props


[warning] 15-15:
Component prop alert must have a description. See https://pipedream.com/docs/components/guidelines/#props

components/openai/actions/chat-using-file-search/chat-using-file-search.mjs

[warning] 14-14:
Component prop alert must have a label. See https://pipedream.com/docs/components/guidelines/#props


[warning] 14-14:
Component prop alert must have a description. See https://pipedream.com/docs/components/guidelines/#props

⏰ 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 (2)
components/openai/openai.app.mjs (1)

770-775: Method addition looks good.

This new method aligns well with the existing request pattern in the code. No immediate issues found.

components/openai/actions/chat-using-functions/chat-using-functions.mjs (1)

132-174: Properties defined for reasoning and JSON schema look fine.

No immediate concerns. It’s good to see you’re providing dynamic props based on model type. Consider adding tests to ensure that these props function as expected at runtime.

Comment on lines +13 to +17
alert: {
type: "alert",
alertType: "info",
content: "Looking to chat with your tools? Check out our individual actions: [Chat using Web Search](https://pipedream.com/apps/openai/actions/chat-using-web-search), [Chat using File Search](https://pipedream.com/apps/openai/actions/chat-using-file-search), and [Chat using Functions](https://pipedream.com/apps/openai/actions/chat-using-functions).",
},
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Add label and description to the alert prop.

The prop alert is missing a label and a description, which violates the Pipedream component prop guidelines. Consider the following fix:

    alert: {
+     label: "Chat Info",
+     description: "Displays helpful links to additional chat capabilities",
      type: "alert",
      alertType: "info",
      content: "Looking to chat with your tools? Check out our individual actions: ...",
    },
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
alert: {
type: "alert",
alertType: "info",
content: "Looking to chat with your tools? Check out our individual actions: [Chat using Web Search](https://pipedream.com/apps/openai/actions/chat-using-web-search), [Chat using File Search](https://pipedream.com/apps/openai/actions/chat-using-file-search), and [Chat using Functions](https://pipedream.com/apps/openai/actions/chat-using-functions).",
},
alert: {
label: "Chat Info",
description: "Displays helpful links to additional chat capabilities",
type: "alert",
alertType: "info",
content: "Looking to chat with your tools? Check out our individual actions: [Chat using Web Search](https://pipedream.com/apps/openai/actions/chat-using-web-search), [Chat using File Search](https://pipedream.com/apps/openai/actions/chat-using-file-search), and [Chat using Functions](https://pipedream.com/apps/openai/actions/chat-using-functions).",
},
🧰 Tools
🪛 GitHub Check: Lint Code Base

[warning] 13-13:
Component prop alert must have a label. See https://pipedream.com/docs/components/guidelines/#props


[warning] 13-13:
Component prop alert must have a description. See https://pipedream.com/docs/components/guidelines/#props

Comment on lines +15 to +19
alert: {
type: "alert",
alertType: "info",
content: "Looking to chat with your tools? Check out our individual actions: [Chat using Web Search](https://pipedream.com/apps/openai/actions/chat-using-web-search), [Chat using File Search](https://pipedream.com/apps/openai/actions/chat-using-file-search), and [Chat using Functions](https://pipedream.com/apps/openai/actions/chat-using-functions).",
},
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Add label and description to the alert prop.

Similar to other components, the alert prop must have a label and description according to Pipedream guidelines. For example:

    alert: {
+     label: "Chat Helper",
+     description: "Displays info on how to chat with advanced features",
      type: "alert",
      alertType: "info",
      content: "Looking to chat with your tools? Check out our individual actions: ...",
    },
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
alert: {
type: "alert",
alertType: "info",
content: "Looking to chat with your tools? Check out our individual actions: [Chat using Web Search](https://pipedream.com/apps/openai/actions/chat-using-web-search), [Chat using File Search](https://pipedream.com/apps/openai/actions/chat-using-file-search), and [Chat using Functions](https://pipedream.com/apps/openai/actions/chat-using-functions).",
},
alert: {
label: "Chat Helper",
description: "Displays info on how to chat with advanced features",
type: "alert",
alertType: "info",
content: "Looking to chat with your tools? Check out our individual actions: [Chat using Web Search](https://pipedream.com/apps/openai/actions/chat-using-web-search), [Chat using File Search](https://pipedream.com/apps/openai/actions/chat-using-file-search), and [Chat using Functions](https://pipedream.com/apps/openai/actions/chat-using-functions).",
},
🧰 Tools
🪛 GitHub Check: Lint Code Base

[warning] 15-15:
Component prop alert must have a label. See https://pipedream.com/docs/components/guidelines/#props


[warning] 15-15:
Component prop alert must have a description. See https://pipedream.com/docs/components/guidelines/#props

Comment on lines +14 to +18
alert: {
type: "alert",
alertType: "info",
content: "Provide function names and parameters, and the model will either answer the question directly or decide to invoke one of the functions, returning a function call that adheres to your specified schema. Add a custom code step that includes all available functions which can be invoked based on the model's response - [you can even build an entire workflow as a function](https://pipedream.com/docs/workflows/building-workflows/code/nodejs/#invoke-another-workflow)! Once the appropriate function or workflow is executed, continue the overall execution or pass the result back to the model for further analysis. For more details, [see this guide](https://platform.openai.com/docs/guides/function-calling?api-mode=responses#overview).",
},
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Add label and description to the alert prop.

The alert prop needs a label and description to follow the Pipedream guidelines. Example:

    alert: {
+     label: "Functions Alert",
+     description: "Informs users on how to integrate function calls within the chat",
      type: "alert",
      alertType: "info",
      content: "Provide function names and parameters...",
    },
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
alert: {
type: "alert",
alertType: "info",
content: "Provide function names and parameters, and the model will either answer the question directly or decide to invoke one of the functions, returning a function call that adheres to your specified schema. Add a custom code step that includes all available functions which can be invoked based on the model's response - [you can even build an entire workflow as a function](https://pipedream.com/docs/workflows/building-workflows/code/nodejs/#invoke-another-workflow)! Once the appropriate function or workflow is executed, continue the overall execution or pass the result back to the model for further analysis. For more details, [see this guide](https://platform.openai.com/docs/guides/function-calling?api-mode=responses#overview).",
},
alert: {
label: "Functions Alert",
description: "Informs users on how to integrate function calls within the chat",
type: "alert",
alertType: "info",
content: "Provide function names and parameters, and the model will either answer the question directly or decide to invoke one of the functions, returning a function call that adheres to your specified schema. Add a custom code step that includes all available functions which can be invoked based on the model's response - [you can even build an entire workflow as a function](https://pipedream.com/docs/workflows/building-workflows/code/nodejs/#invoke-another-workflow)! Once the appropriate function or workflow is executed, continue the overall execution or pass the result back to the model for further analysis. For more details, [see this guide](https://platform.openai.com/docs/guides/function-calling?api-mode=responses#overview).",
},
🧰 Tools
🪛 GitHub Check: Lint Code Base

[warning] 14-14:
Component prop alert must have a label. See https://pipedream.com/docs/components/guidelines/#props


[warning] 14-14:
Component prop alert must have a description. See https://pipedream.com/docs/components/guidelines/#props

Comment on lines +14 to +18
alert: {
type: "alert",
alertType: "info",
content: "To use this action, you need to have set up a knowledge base in a vector store and uploaded files to it. [More infomation here](https://platform.openai.com/docs/guides/tools-file-search?lang=javascript#overview).",
},
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Add a label and description to the alert prop.

The static analysis flagged that alert props must have both a label and description. This omission may cause lint or pipeline failures based on your project's guidelines.

Here is a proposed fix:

 alert: {
   type: "alert",
+  label: "Alert",
+  description: "Provides additional context on how to set up a knowledge base in a vector store",
   alertType: "info",
   content: "To use this action, you need to have set up a knowledge base in a vector store and uploaded files to it. [More infomation here](https://platform.openai.com/docs/guides/tools-file-search?lang=javascript#overview).",
 },
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
alert: {
type: "alert",
alertType: "info",
content: "To use this action, you need to have set up a knowledge base in a vector store and uploaded files to it. [More infomation here](https://platform.openai.com/docs/guides/tools-file-search?lang=javascript#overview).",
},
alert: {
type: "alert",
label: "Alert",
description: "Provides additional context on how to set up a knowledge base in a vector store",
alertType: "info",
content: "To use this action, you need to have set up a knowledge base in a vector store and uploaded files to it. [More infomation here](https://platform.openai.com/docs/guides/tools-file-search?lang=javascript#overview).",
},
🧰 Tools
🪛 GitHub Check: Lint Code Base

[warning] 14-14:
Component prop alert must have a label. See https://pipedream.com/docs/components/guidelines/#props


[warning] 14-14:
Component prop alert must have a description. See https://pipedream.com/docs/components/guidelines/#props

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

🧹 Nitpick comments (2)
components/openai/actions/chat-using-web-search/chat-using-web-search.mjs (1)

148-196: Improve error handling and logging of the API response.

You handle the main request but provide no fallback for potential API errors or network failures. Although skipping is supported, consider adding minimal error handling or a retry mechanism for resilience.

components/openai/actions/chat-using-file-search/chat-using-file-search.mjs (1)

136-142: Validate user-defined filters.

filters can contain arbitrary objects, but you don't validate or sanitize the user input. This could lead to unexpected runtime errors during filtering.

Would you like me to propose a validation snippet to ensure each filter property is of the correct type?

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 11dc862 and ff384b2.

📒 Files selected for processing (3)
  • components/openai/actions/chat-using-file-search/chat-using-file-search.mjs (1 hunks)
  • components/openai/actions/chat-using-functions/chat-using-functions.mjs (1 hunks)
  • components/openai/actions/chat-using-web-search/chat-using-web-search.mjs (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: Verify TypeScript components
  • GitHub Check: pnpm publish
  • GitHub Check: Lint Code Base
  • GitHub Check: Publish TypeScript components
🔇 Additional comments (6)
components/openai/actions/chat-using-web-search/chat-using-web-search.mjs (1)

18-23: Ensure model option consistency.

Currently, the modelId property defaults to "gpt-4o" and provides the options ["gpt-4o", "gpt-4o-mini"]. Verify these models exist in your environment or error handling is provided for invalid model choices.

Would you like me to generate a script to verify the existence of these model IDs in your codebase or your environment’s model list?

components/openai/actions/chat-using-functions/chat-using-functions.mjs (2)

14-18: Add a label and description to the alert prop.

Your alert prop is missing the required label and description fields per your pipeline’s guidelines.

 alert: {
   type: "alert",
+  label: "Functions Alert",
+  description: "Provides context for function usage and references to external documentation",
   alertType: "info",
   content: "...",
 },

222-249: Overall structure looks good.

The rest of the code effectively handles the multi-turn conversation logic, tool choice, and reasoning parameters. No further concerns.

components/openai/actions/chat-using-file-search/chat-using-file-search.mjs (3)

14-18: Add a label and description to the alert prop.

The alert prop is missing the required fields to satisfy official guidelines.

 alert: {
   type: "alert",
+  label: "File Search Alert",
+  description: "Informs users how to set up and use the file-based knowledge base",
   alertType: "info",
   content: "...",
 },

180-188: Confirm that search results will be relevant to the user request.

With includeSearchResults = true, the model might receive additional context. Verify that the appended search results won't unnecessarily bloat the token usage or lead to inaccurate context.

Please confirm if your typical input sizes remain well within your model’s max token limit.


218-223: No further concerns.

The overall design aligns well with your chat-based file search flow.

Comment on lines +96 to +144
additionalProps() {
const {
responseFormat,
userLocation,
} = this;
const props = {};

if (userLocation?.includes("City")) {
props.city = {
type: "string",
label: "City",
description: "Free text input for the city of the user, e.g. `San Francisco`",
};
}

if (userLocation?.includes("Region")) {
props.region = {
type: "string",
label: "Region",
description: "Free text input for the region of the user, e.g. `California`",
};
}

if (userLocation?.includes("Country")) {
props.country = {
type: "string",
label: "Country",
description: "The two-letter [ISO country code](https://en.wikipedia.org/wiki/ISO_3166-1) of the user, e.g. `US`",
};
}

if (userLocation?.includes("Timezone")) {
props.timezone = {
type: "string",
label: "Timezone",
description: "The [IANA timezone](https://timeapi.io/documentation/iana-timezones) of the user, e.g. `America/Los_Angeles`",
};
}

if (responseFormat === constants.CHAT_RESPONSE_FORMAT.JSON_SCHEMA.value) {
props.jsonSchema = {
type: "string",
label: "JSON Schema",
description: "Define the schema that the model's output must adhere to. [Generate one here](https://platform.openai.com/docs/guides/structured-outputs/supported-schemas).",
};
}

return props;
},
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Validate JSON schema property to prevent runtime failures.

When responseFormat is JSON Schema, you parse the jsonSchema string without try/catch. If the user provides invalid JSON, this will raise an unhandled exception.

+ try {
+   JSON.parse(this.jsonSchema);
+ } catch (err) {
+   throw new Error("Invalid JSON format in the JSON Schema property");
+ }

Committable suggestion skipped: line range outside the PR's diff.

Comment on lines 194 to 203
let functions = this.functions;
if (typeof functions === "string") {
functions = JSON.parse(functions);
}

if (Array.isArray(functions)) {
data.tools.push(...functions);
} else {
data.tools.push(functions);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Validate the functions JSON string.

If this.functions isn’t valid JSON, JSON.parse(functions) will throw. Consider adding error handling to notify users about malformed strings.

 try {
   functions = JSON.parse(functions);
 } catch (err) {
   throw new Error("Invalid JSON format in the Functions property");
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
let functions = this.functions;
if (typeof functions === "string") {
functions = JSON.parse(functions);
}
if (Array.isArray(functions)) {
data.tools.push(...functions);
} else {
data.tools.push(functions);
}
let functions = this.functions;
if (typeof functions === "string") {
try {
functions = JSON.parse(functions);
} catch (err) {
throw new Error("Invalid JSON format in the Functions property");
}
}
if (Array.isArray(functions)) {
data.tools.push(...functions);
} else {
data.tools.push(functions);
}

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/openai/actions/chat-using-functions/chat-using-functions.mjs (2)

148-149: Fix typo in comment

There's a typo in the comment: "aparrently" should be "apparently".

-      // aparrently not supported yet as of 12/march/2025
+      // apparently not supported yet as of 12/march/2025

240-242: Handle case when response is falsy

Consider adding an else block to handle cases where the response might be falsy, providing appropriate error information.

if (response) {
  $.export("$summary", `Successfully sent chat with id ${response.id}`);
+} else {
+  $.export("$summary", "Completed, but received empty response from OpenAI");
}
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between ff384b2 and 3523ba0.

📒 Files selected for processing (1)
  • components/openai/actions/chat-using-functions/chat-using-functions.mjs (1 hunks)
🧰 Additional context used
🪛 GitHub Check: Lint Code Base
components/openai/actions/chat-using-functions/chat-using-functions.mjs

[warning] 14-14:
Component prop alert must have a label. See https://pipedream.com/docs/components/guidelines/#props


[warning] 14-14:
Component prop alert must have a description. See https://pipedream.com/docs/components/guidelines/#props

⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Verify TypeScript components
  • GitHub Check: Publish TypeScript components
🔇 Additional comments (3)
components/openai/actions/chat-using-functions/chat-using-functions.mjs (3)

14-18: Add label and description to the alert prop

The alert prop is missing required label and description attributes according to Pipedream guidelines. This is flagged by the linter warnings.

alert: {
+  label: "Functions Alert",
+  description: "Information about using function calling with OpenAI models",
  type: "alert",
  alertType: "info",
  content: "Provide function names and parameters, and the model will either answer the question directly or decide to invoke one of the functions, returning a function call that adheres to your specified schema. Add a custom code step that includes all available functions which can be invoked based on the model's response - [you can even build an entire workflow as a function](https://pipedream.com/docs/workflows/building-workflows/code/nodejs/#invoke-another-workflow)! Once the appropriate function or workflow is executed, continue the overall execution or pass the result back to the model for further analysis. For more details, [see this guide](https://platform.openai.com/docs/guides/function-calling?api-mode=responses#overview).",
},
🧰 Tools
🪛 GitHub Check: Lint Code Base

[warning] 14-14:
Component prop alert must have a label. See https://pipedream.com/docs/components/guidelines/#props


[warning] 14-14:
Component prop alert must have a description. See https://pipedream.com/docs/components/guidelines/#props


190-193: Add error handling for JSON parsing

When parsing the functions string, you should add error handling to catch and provide a clear message for invalid JSON input.

let functions = this.functions;
if (typeof functions === "string") {
+  try {
    functions = JSON.parse(functions);
+  } catch (err) {
+    throw new Error("Invalid JSON format in the Functions property");
+  }
}

1-246: Overall implementation looks good

The component is well-structured and follows Pipedream's component architecture. It properly handles various configurations for OpenAI's function calling feature, including reasoning models, tool choice options, and JSON schema responses.

The dynamic props implementation based on model and response format is a good approach for providing a clean user experience.

🧰 Tools
🪛 GitHub Check: Lint Code Base

[warning] 14-14:
Component prop alert must have a label. See https://pipedream.com/docs/components/guidelines/#props


[warning] 14-14:
Component prop alert must have a description. See https://pipedream.com/docs/components/guidelines/#props

Comment on lines 226 to 233
if (this.responseFormat === constants.CHAT_RESPONSE_FORMAT.JSON_SCHEMA.value) {
data.text = {
format: {
type: this.responseFormat,
...JSON.parse(this.jsonSchema),
},
};
}
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Add error handling for JSON schema parsing

Similar to the functions parsing, you should add error handling when parsing the JSON schema to provide a clear error message to users.

if (this.responseFormat === constants.CHAT_RESPONSE_FORMAT.JSON_SCHEMA.value) {
+  let schema;
+  try {
+    schema = JSON.parse(this.jsonSchema);
+  } catch (err) {
+    throw new Error("Invalid JSON format in the JSON Schema property");
+  }
  data.text = {
    format: {
      type: this.responseFormat,
-      ...JSON.parse(this.jsonSchema),
+      ...schema,
    },
  };
}
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if (this.responseFormat === constants.CHAT_RESPONSE_FORMAT.JSON_SCHEMA.value) {
data.text = {
format: {
type: this.responseFormat,
...JSON.parse(this.jsonSchema),
},
};
}
if (this.responseFormat === constants.CHAT_RESPONSE_FORMAT.JSON_SCHEMA.value) {
let schema;
try {
schema = JSON.parse(this.jsonSchema);
} catch (err) {
throw new Error("Invalid JSON format in the JSON Schema property");
}
data.text = {
format: {
type: this.responseFormat,
...schema,
},
};
}

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 (1)
components/openai/actions/chat-using-functions/chat-using-functions.mjs (1)

148-159: Ensure consistency in using generateSummary.

The code references this.generateSummary (lines 223-226), but the prop for it is commented out (lines 148-159). Consider adding a prop for generateSummary or removing this reference to avoid confusion or potential errors.

Also applies to: 223-226

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 3523ba0 and 35d1467.

📒 Files selected for processing (3)
  • components/openai/actions/chat-using-file-search/chat-using-file-search.mjs (1 hunks)
  • components/openai/actions/chat-using-functions/chat-using-functions.mjs (1 hunks)
  • components/openai/actions/chat-using-web-search/chat-using-web-search.mjs (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • components/openai/actions/chat-using-file-search/chat-using-file-search.mjs
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: Verify TypeScript components
  • GitHub Check: Publish TypeScript components
  • GitHub Check: Lint Code Base
🔇 Additional comments (7)
components/openai/actions/chat-using-functions/chat-using-functions.mjs (3)

14-18: Add a label and description to the alert prop.

This component prop should have both a label and description in accordance with Pipedream guidelines.

 alert: {
+  label: "Functions Alert",
+  description: "Informs users on how to integrate function calls within the chat",
   type: "alert",
   alertType: "info",
   content: "Provide function names and parameters..."
 },

190-197: Good work validating the functions JSON.

The try/catch block for parsing functions helps prevent runtime errors due to invalid JSON, adhering to best practices for user input.


231-241: Robust JSON schema parsing.

Thank you for adding error handling to parse the jsonSchema property. This will help users quickly identify invalid output schema definitions.

components/openai/actions/chat-using-web-search/chat-using-web-search.mjs (4)

103-144: Nice approach to dynamic location props.

Creating additional properties based on the array of userLocation ensures flexible configuration. Just ensure users understand which location fields are actually used downstream.


175-186: Good usage of try/catch for JSON schema.

This ensures the step fails gracefully when encountering invalid JSON, preventing undefined behavior.


188-197: No further concerns on the response flow.

The call to openai.responses and the summary export appear straightforward and correct.


160-173:

❓ Verification inconclusive

Verify web_search_preview arguments.

Please confirm the web search tool supports "type": "approximate" under user_location. If it’s unsupported, this field may be ignored or cause run-time confusion.


🏁 Script executed:

#!/bin/bash
# Searching for references to web_search_preview usage and "type: approximate"
rg "web_search_preview"
rg '"type": "approximate"'

Length of output: 164


Action Required: Confirm the configuration of user_location

  • The code passes "type": "approximate" within the user_location object for web_search_preview.
  • Our search results were inconclusive in confirming that this option is commonly used or supported elsewhere.
  • Please manually verify—by checking the web search tool documentation or its runtime behavior—that the tool accepts "type": "approximate". If it turns out to be unsupported, adjust or remove this field to prevent potential run-time confusion.

@andrewjschuang andrewjschuang merged commit aa50dfe into master Mar 12, 2025
11 checks passed
@andrewjschuang andrewjschuang deleted the openai-chat-updates branch March 12, 2025 15:32
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