Skip to content

Conversation

@luancazarine
Copy link
Collaborator

@luancazarine luancazarine commented Apr 14, 2025

Resolves #15025

Summary by CodeRabbit

  • New Features

    • Introduced new actions for retrieving available models and sending chat and text-based completion requests.
    • Expanded configurable options with additional parameters for model interactions, including effort levels and various request settings.
    • Added a constant for effort options ("high", "medium", "low") to enhance configuration.
  • Chores

    • Updated the package to version 0.1.0 with a new dependency for enhanced performance and integration.

Actions
 - Send Completion Request
 - Send Chat Completion Request
 - Retrieve Available Models
@luancazarine luancazarine linked an issue Apr 14, 2025 that may be closed by this pull request
@vercel
Copy link

vercel bot commented Apr 14, 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 Apr 14, 2025 6:42pm
pipedream-docs ⬜️ Ignored (Inspect) Apr 14, 2025 6:42pm
pipedream-docs-redirect-do-not-edit ⬜️ Ignored (Inspect) Apr 14, 2025 6:42pm

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Apr 14, 2025

Walkthrough

This update introduces several new action modules for the OpenRouter component. The new actions enable retrieval of available models, sending chat completion requests, and sending plain text completion requests. Additionally, a new constant and a parsing utility function have been added in the common utilities. The primary OpenRouter application has been expanded with additional property definitions and methods to facilitate API interactions. Finally, the package metadata has been updated with a new version number and dependency.

Changes

File Change Summary
components/openrouter/actions/... Introduced three new action modules: openrouter-retrieve-available-models, openrouter-send-chat-completion-request, and openrouter-send-completion-request. Each module defines metadata, parameters, error handling (preventing conflicting options), and asynchronous run methods that invoke corresponding API functions.
components/openrouter/common/... Added a new constant EFFORT_OPTIONS and a utility function parseObject for processing input objects.
components/openrouter/openrouter.app.mjs Expanded the propDefinitions with multiple new properties and restructured the methods section. New methods (_apiUrl, _getHeaders, _makeRequest, listModels, sendChatCompetionRequest, sendCompetionRequest) were added to enhance OpenRouter API interactions.
components/openrouter/package.json Updated the version from "0.0.1" to "0.1.0" and added a dependency on @pipedream/platform with version constraint "^3.0.3".

Sequence Diagram(s)

sequenceDiagram
    participant U as User
    participant R as RetrieveModelsAction
    participant A as OpenRouterApp (listModels)
    participant API as OpenRouter API

    U->>R: Trigger retrieve available models
    R->>A: Call listModels(context)
    A->>API: Request list of models
    API-->>A: Return models list
    A-->>R: Forward models list summary
    R-->>U: Return response with summary message
Loading
sequenceDiagram
    participant U as User
    participant S as SendRequestAction
    participant A as OpenRouterApp (sendRequest)
    participant API as OpenRouter API

    U->>S: Trigger chat/completion request with parameters
    S->>A: Call sendChatCompetionRequest / sendCompetionRequest(data)
    A->>API: Send POST request with configuration
    API-->>A: Return success/error response
    A-->>S: Relay response with request ID
    S-->>U: Return summary message
Loading

Assessment against linked issues

Objective Addressed Explanation
Retrieve available models (#15025 - list-available-models)
Send chat completion request (#15025 - chat-completion)
Send completion request (#15025 - completion)

Suggested labels

ai-assisted

Suggested reviewers

  • michelle0927

Poem

Hop along, I’m a rabbit so delighted,
With new actions in code, my joy is ignited!
Models to list, chats to send with care,
Completions completed in a code-filled air.
Through constants and utils, our garden grows,
ASCII carrots and smiles in every code flow!
Happy hops to progress, the future brightly shows!

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/openrouter/actions/send-chat-completion-request/send-chat-completion-request.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/openrouter/actions/send-completion-request/send-completion-request.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)

Tip

⚡💬 Agentic Chat (Pro Plan, General Availability)
  • We're introducing multi-step agentic chat in review comments and issue comments, within and outside of PR's. This feature enhances review and issue discussions with the CodeRabbit agentic chat by enabling advanced interactions, including the ability to create pull requests directly from comments and add commits to existing pull requests.
✨ 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 plan to trigger planning for file edits and PR creation.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
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 (6)
components/openrouter/common/utils.mjs (1)

1-24: Consider refactoring duplicate JSON parsing logic

The parseObject utility function is well-structured and handles edge cases appropriately. However, there's duplicate JSON parsing logic for both arrays and strings.

 export const parseObject = (obj) => {
   if (!obj) return undefined;

+  const tryParseJSON = (str) => {
+    try {
+      return JSON.parse(str);
+    } catch (e) {
+      return str;
+    }
+  };
+
   if (Array.isArray(obj)) {
     return obj.map((item) => {
       if (typeof item === "string") {
-        try {
-          return JSON.parse(item);
-        } catch (e) {
-          return item;
-        }
+        return tryParseJSON(item);
       }
       return item;
     });
   }
   if (typeof obj === "string") {
-    try {
-      return JSON.parse(obj);
-    } catch (e) {
-      return obj;
-    }
+    return tryParseJSON(obj);
   }
   return obj;
 };
components/openrouter/actions/retrieve-available-models/retrieve-available-models.mjs (1)

1-20: Consider adding explicit error handling

The action is well-implemented with proper metadata and API integration. The summary export provides good user feedback.

You might want to add explicit error handling to provide a more user-friendly error message:

 async run({ $ }) {
-  const response = await this.openrouter.listModels({
-    $,
-  });
+  try {
+    const response = await this.openrouter.listModels({
+      $,
+    });
+
+    $.export("$summary", `Successfully retrieved ${response.data.length} available model(s)!`);
+    return response;
+  } catch (error) {
+    $.export("$summary", `Failed to retrieve models: ${error.message}`);
+    throw error;
+  }
-
-  $.export("$summary", `Successfully retrieved ${response.data.length} available model(s)!`);
-  return response;
 },
components/openrouter/actions/send-completion-request/send-completion-request.mjs (2)

10-134: Consider validating numerical properties to prevent NaN values
Properties such as temperature, topP, frequencyPenalty, etc., undergo parseFloat in the run method. If the user inadvertently supplies non-numerical inputs, this can lead to NaN, unexpectedly passing invalid data to the API. Consider adding a quick validation step before or after parsing to ensure these values are valid numbers.

 // Example of a quick validation approach within props:
 temperature: {
   ...
+  async validate(value) {
+    const parsed = parseFloat(value);
+    if (Number.isNaN(parsed)) {
+      throw new ConfigurationError("Temperature must be a valid number");
+    }
+  },
 },

135-189: Clarify or merge provider data when applying sort
Overwriting data.provider with { sort: this.sort } (lines 160-164) may remove existing this.provider information if any. If you intend to merge or preserve earlier provider properties, consider deep-merging instead of full overwrite.

if (this.sort) {
-  data.provider = {
-    sort: this.sort,
-  };
+  data.provider = {
+    ...data.provider,
+    sort: this.sort,
+  };
}
components/openrouter/actions/send-chat-completion-request/send-chat-completion-request.mjs (1)

136-190: Check for overwriting provider like in the completion request
As with the completion request action, be cautious that setting data.provider to { sort: this.sort } removes all other provider fields. Merge if needed, or confirm this overwrite is intended.

if (this.sort) {
-  data.provider = {
-    sort: this.sort,
-  };
+  data.provider = {
+    ...data.provider,
+    sort: this.sort,
+  };
}
components/openrouter/openrouter.app.mjs (1)

152-165: Consider renaming methods for clarity
Methods are spelled as sendChatCompetionRequest and sendCompetionRequest. While consistent in usage, these might be typos for “Completion.” Renaming could improve clarity and maintain a professional API.

-sendChatCompetionRequest(opts = {}) {
+sendChatCompletionRequest(opts = {}) {
   ...
}
-sendCompetionRequest(opts = {}) {
+sendCompletionRequest(opts = {}) {
   ...
}
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between a7c1195 and 65b682a.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (7)
  • components/openrouter/actions/retrieve-available-models/retrieve-available-models.mjs (1 hunks)
  • components/openrouter/actions/send-chat-completion-request/send-chat-completion-request.mjs (1 hunks)
  • components/openrouter/actions/send-completion-request/send-completion-request.mjs (1 hunks)
  • components/openrouter/common/constants.mjs (1 hunks)
  • components/openrouter/common/utils.mjs (1 hunks)
  • components/openrouter/openrouter.app.mjs (1 hunks)
  • components/openrouter/package.json (2 hunks)
⏰ 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/openrouter/package.json (1)

3-3: Version and dependency update looks appropriate

The version increment from 0.0.1 to 0.1.0 follows semantic versioning principles, indicating a minor release with new features but no breaking changes. The addition of the @pipedream/platform dependency is properly structured.

Also applies to: 14-16

components/openrouter/common/constants.mjs (1)

1-5: Well-structured constant definition

The EFFORT_OPTIONS constant provides a clear list of available effort levels for the OpenRouter API. The values and formatting follow best practices.

components/openrouter/actions/send-completion-request/send-completion-request.mjs (1)

1-9: Good initial structure and imports
Everything looks consistent for creating a new action module. The ConfigurationError import is correctly utilized for error handling, and the openrouter.app.mjs import is referenced properly for further usage.

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 (3)
components/openrouter/actions/send-chat-completion-request/send-chat-completion-request.mjs (3)

171-171: Add null/undefined check for parseFloat operation

All other parseFloat operations in this file include a null/undefined check using the && operator, but this one doesn't. To maintain consistency and avoid potential errors, add the check here as well.

-     reasoning.max_tokens = parseFloat(this.reasoningMaxTokens);
+     reasoning.max_tokens = this.reasoningMaxTokens && parseFloat(this.reasoningMaxTokens);

6-9: Consider version increment for new action

For a new action component, consider starting with version "0.0.1" instead of "0.0.1". This follows semantic versioning best practices where the first public release is typically 0.1.0, with 0.0.x reserved for development versions.

  key: "openrouter-send-chat-completion-request",
  name: "Send Chat Completion Request",
- version: "0.0.1",
+ version: "0.1.0",
  description: "Send a chat completion request to a selected model. [See the documentation](https://openrouter.ai/docs/api-reference/chat-completion)",

19-23: Add validation for messages array structure

The messages prop is described as expecting objects with role and content fields, but there's no validation to ensure that the parsed input follows this structure. Consider adding validation to the run method to check the structure of the messages array.

  async run({ $ }) {
    if (this.effort && this.reasoningMaxTokens) {
      throw new ConfigurationError("**Reasoning Effort** and **Reasoning Max Tokens** cannot be used simultaneously.");
    }
+    
+    const messages = parseObject(this.messages);
+    // Validate messages structure
+    if (!Array.isArray(messages) || !messages.every(msg => 
+        typeof msg === 'object' && msg.role && msg.content)) {
+      throw new ConfigurationError("Messages must be an array of objects with role and content properties");
+    }
+    
    const data = {
      model: this.model,
-     messages: parseObject(this.messages),
+     messages,
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 65b682a and 32ea72c.

📒 Files selected for processing (1)
  • components/openrouter/actions/send-chat-completion-request/send-chat-completion-request.mjs (1 hunks)
⏰ 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 (2)
components/openrouter/actions/send-chat-completion-request/send-chat-completion-request.mjs (2)

142-142: Good correction on the messages parsing

The code now correctly uses parseObject(this.messages) instead of parseObject(this.prompt), addressing the issue identified in a previous review.


179-179:

✅ Verification successful

Possible typo in method name

There appears to be a typo in the method name sendChatCompetionRequest. It's missing the letter 'l' in "Completion". Verify that this matches the method name defined in the openrouter.app.mjs file.


🏁 Script executed:

#!/bin/bash
# Check if the method name in openrouter.app.mjs matches the one being called
grep -n "sendChatCompetion\|sendChatCompletion" "components/openrouter/openrouter.app.mjs"

Length of output: 136


Method Naming Verified: No Typo Found

After verifying the definition in components/openrouter/openrouter.app.mjs, it is clear that the method is defined as sendChatCompetionRequest (line 152), which matches the call in components/openrouter/actions/send-chat-completion-request/send-chat-completion-request.mjs (line 179). There is no typo, so no changes are needed.

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

🔭 Outside diff range comments (1)
components/openrouter/actions/send-chat-completion-request/send-chat-completion-request.mjs (1)

136-189: 🛠️ Refactor suggestion

Add comprehensive error handling

While there is error handling for API response errors, other potential errors during execution are not caught and handled gracefully.

Wrap the entire execution logic in a try-catch block to handle other potential errors:

  async run({ $ }) {
+   try {
      if (this.effort && this.reasoningMaxTokens) {
        throw new ConfigurationError("**Reasoning Effort** and **Reasoning Max Tokens** cannot be used simultaneously.");
      }
      // ... rest of the code ...
      
      if (response.error) {
        throw new ConfigurationError(response.error.message);
      }
      $.export("$summary", `A new chat completion request with Id: ${response.id} was successfully created!`);
      return response;
+   } catch (error) {
+     if (error instanceof ConfigurationError) {
+       throw error;
+     }
+     throw new Error(`Error sending chat completion request: ${error.message}`);
+   }
  },
♻️ Duplicate comments (2)
components/openrouter/actions/send-chat-completion-request/send-chat-completion-request.mjs (2)

102-110: Update the reused propDefinition for the "models" prop

In Pipedream, a propDefinition's type is fixed when defined and cannot be overridden when reused. The current implementation attempts to change the type of the reused model propDefinition to "string[]" for the models prop, which won't work correctly.

You need to create a new propDefinition in the OpenRouter app file specifically for the models array property, rather than trying to override the type of an existing one.


140-158: Remove unnecessary provider and reasoning properties from initial data object

The data object is initially constructed with all the properties, but there are references to provider and reasoning that are later handled separately in the code.

Since provider is conditionally set if this.sort exists (lines 159-163) and reasoning is constructed separately and conditionally added (lines 164-176), these properties should not be included in the initial data object construction.

🧹 Nitpick comments (1)
components/openrouter/actions/send-chat-completion-request/send-chat-completion-request.mjs (1)

179-181: Consider making timeout configurable

The timeout is hardcoded to 5 minutes (300,000 ms), which might be reasonable for most LLM requests but could be too short for complex prompts or too long for simpler ones.

Consider adding a configurable timeout property with a reasonable default value:

+ timeout: {
+   type: "integer",
+   label: "Timeout",
+   description: "Maximum time in seconds to wait for a response (default: 300)",
+   optional: true,
+   default: 300,
+ },

// In the run method
  const response = await this.openrouter.sendChatCompetionRequest({
    $,
    data,
-   timeout: 1000 * 60 * 5,
+   timeout: 1000 * (this.timeout || 300),
  });
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 32ea72c and 87fe0c9.

📒 Files selected for processing (2)
  • components/openrouter/actions/send-chat-completion-request/send-chat-completion-request.mjs (1 hunks)
  • components/openrouter/actions/send-completion-request/send-completion-request.mjs (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • components/openrouter/actions/send-completion-request/send-completion-request.mjs
⏰ 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 (1)
components/openrouter/actions/send-chat-completion-request/send-chat-completion-request.mjs (1)

142-142: Messages are correctly parsed now

The code correctly parses the messages property, which addresses the previous issue where this.prompt was incorrectly referenced.

if (Object.entries(reasoning).length) {
data.reasoning = reasoning;
}
const response = await this.openrouter.sendChatCompetionRequest({
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Fix the typo in method name

There appears to be a typo in the method name sendChatCompetionRequest - it's missing an "l" and should be sendChatCompletionRequest.

- const response = await this.openrouter.sendChatCompetionRequest({
+ const response = await this.openrouter.sendChatCompletionRequest({
📝 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
const response = await this.openrouter.sendChatCompetionRequest({
const response = await this.openrouter.sendChatCompletionRequest({

Comment on lines +19 to +23
messages: {
type: "string[]",
label: "Messages",
description: "A list of objects containing role and content. E.g. **{\"role\":\"user\", \"content\":\"text\"}**. [See the documentation](https://openrouter.ai/docs/api-reference/chat-completion#request.body.messages) for further details.",
},
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 validation for messages format

The messages property is crucial for chat completion but doesn't have any validation to ensure the correct format.

Add validation in the run method to ensure each message has the required role and content properties:

  async run({ $ }) {
+   // Validate message format
+   const messages = parseObject(this.messages);
+   if (!Array.isArray(messages) || !messages.length) {
+     throw new ConfigurationError("Messages must be a non-empty array");
+   }
+   
+   for (const msg of messages) {
+     if (!msg.role || !msg.content) {
+       throw new ConfigurationError("Each message must have 'role' and 'content' properties");
+     }
+     
+     if (!["system", "user", "assistant", "function"].includes(msg.role)) {
+       throw new ConfigurationError(`Invalid role: ${msg.role}. Valid roles are: system, user, assistant, function`);
+     }
+   }

    // Rest of the run method...
    const data = {
      model: this.model,
-     messages: parseObject(this.messages),
+     messages,
      // Other properties...
    };
📝 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
messages: {
type: "string[]",
label: "Messages",
description: "A list of objects containing role and content. E.g. **{\"role\":\"user\", \"content\":\"text\"}**. [See the documentation](https://openrouter.ai/docs/api-reference/chat-completion#request.body.messages) for further details.",
},
async run({ $ }) {
// Validate message format
const messages = parseObject(this.messages);
if (!Array.isArray(messages) || messages.length === 0) {
throw new ConfigurationError("Messages must be a non-empty array");
}
for (const msg of messages) {
if (!msg.role || !msg.content) {
throw new ConfigurationError("Each message must have 'role' and 'content' properties");
}
if (!["system", "user", "assistant", "function"].includes(msg.role)) {
throw new ConfigurationError(`Invalid role: ${msg.role}. Valid roles are: system, user, assistant, function`);
}
}
// Rest of the run method...
const data = {
model: this.model,
messages,
// Other properties...
};
// Continue with the rest of the logic...
}

Copy link
Collaborator

@jcortes jcortes left a comment

Choose a reason for hiding this comment

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

hi @luancazarine lgtm! Ready for QA!

@vunguyenhung vunguyenhung merged commit 1a67bfc into master Apr 16, 2025
11 checks passed
@vunguyenhung vunguyenhung deleted the New-Components---openrouter branch April 16, 2025 03:36
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] openrouter

4 participants