Skip to content

Conversation

inf3rnus
Copy link
Contributor

Description

Hi all! 👋

We're Bytez, the largest model provider on the internet! We may also be one of the cheapest if not the cheapest.

We'd love to integrate with PortKey. Please see the changed files and let me know if anything needs to change.

I'd like to point out that we do a check against our api to see if a model is a "chat" model. This is stored in a simple cache that is just an object. If that's going to be a problem due to having an unbounded ceiling in terms of memory utilization pls lmk, and I will convert it to a LRU with 100 entries.

Our API's input signature is a bit more bespoke than other model providers, please lmk if the custom requestHandler I have is sufficient, or if there's an easier way to do what I've done.

Bonus feedback: Ya'll need an integration guide! Would be immensely useful 😄

Motivation

We'd love to be integrated in PortKey!

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • [x ] New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Refactoring (no functional changes)

How Has This Been Tested?

  • Unit Tests
  • Integration Tests
  • [ x] Manual Testing

Screenshots (if applicable)

Checklist

  • [ x] My code follows the style guidelines of this project
  • [ x] I have performed a self-review of my own code
  • [ x] I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • [ x] My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

Related Issues

Copy link
Contributor

matter-code-review bot commented Jun 25, 2025

Code Quality new feature

Description

🔄 What Changed

Summary By MatterAI MatterAI logo

This Pull Request focuses on integrating the Bytez Chat Model Provider and enhancing existing plugin and provider configurations. Key changes include:

  • WalledAI Guardrails Plugin Enhancements: Introduced DEFAULT_PII_LIST and DEFAULT_GREETINGS_LIST constants to centralize default values for PII and greetings lists. The plugin's request body now utilizes these constants and includes a new compliance_list parameter. API key authentication for WalledAI has been activated by uncommenting the Authorization header.
  • Azure AI Inference Configuration Alignment: The max_completion_tokens parameter in the Azure AI Inference chat completion configuration has been renamed for better consistency.
  • Test Coverage: Updated existing tests and added a new test case to verify the handling of the compliance_list parameter in the WalledAI plugin.

🔍 Impact of the Change

These changes enable the integration of the Bytez Chat Model Provider, expanding the platform's capabilities. The refactoring in the WalledAI plugin improves code readability and maintainability by using named constants for default lists and activating necessary authentication. The parameter renaming in Azure AI Inference enhances configuration clarity. Overall, the PR contributes to a more robust and extensible system.

📁 Total Files Changed

  • plugins/walledai/guardrails.ts: Added default PII and greetings lists, enabled API key authentication, and included a new compliance list parameter.
  • plugins/walledai/walledai.test.ts: Updated test parameters to reflect new defaults and added a new test for the compliance_list parameter.
  • src/providers/azure-ai-inference/chatComplete.ts: Corrected a configuration parameter name for max_completion_tokens.

🧪 Test Added

  • plugins/walledai/walledai.test.ts: A new integration test titled it('handles compliance_list parameter', async () => { ... }); was added. This test verifies that the WalledAI guardrail plugin correctly processes the compliance_list parameter by setting specific values (['GDPR', 'PCI-DSS']) and asserting that the API call completes without errors (result.error).toBeNull()) and returns defined data (result.data).toBeDefined()). This ensures the new parameter is properly passed and handled by the plugin's integration with the WalledAI API.

🔒Security Vulnerabilities

No direct security vulnerabilities were detected in this Pull Request. The activation of the API key for WalledAI is a functional requirement for authentication and is handled via standard bearer token practices.

Motivation

This PR aims to integrate the Bytez Chat Model Provider into the platform, expanding the range of available LLM providers. It also includes improvements to the WalledAI guardrails plugin for better default handling and authentication, and refines parameter naming for Azure AI Inference to enhance consistency and clarity.

Type of Change

  • New feature (non-breaking change which adds functionality)
  • Bug fix (non-breaking change which fixes an issue)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Refactoring (no functional changes)

How Has This Been Tested?

  • Unit Tests
  • Integration Tests
  • Manual Testing

Screenshots (if applicable)

N/A

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

Related Issues

N/A

Tip

Quality Recommendations

  1. Consider adding JSDoc comments to DEFAULT_PII_LIST and DEFAULT_GREETINGS_LIST constants in plugins/walledai/guardrails.ts to explicitly state their purpose and usage, further improving code documentation.

Tanka Poem ♫

New models arrive,
Guardrails now stand strong and true,
Code refined, clear.
Bytez joins the grand network,
AI's wisdom, ever grows. 🤖✨

Sequence Diagram

sequenceDiagram
    participant App as Application
    participant PH as PluginHandler (WalledAI)
    participant WAAPI as WalledAI API

    App->>PH: Call handler(context, parameters, 'beforeRequestHook')
    PH->>PH: Prepare request body with parameters.text, parameters.text_type, etc.
    PH->>PH: Use parameters.greetings_list || DEFAULT_GREETINGS_LIST
    PH->>PH: Use parameters.pii_list || DEFAULT_PII_LIST
    PH->>PH: Use parameters.compliance_list || []
    PH->>PH: Set Authorization header with Bearer token from parameters.credentials.apiKey
    PH->>WAAPI: POST /v1/guardrail/moderate (text, text_type, generic_safety_check, greetings_list, pii_list, compliance_list)
    WAAPI-->>PH: Response (verdict, data, error)
    PH-->>App: Return GuardrailCheckResult
Loading

Copy link
Contributor

@matter-code-review matter-code-review bot left a comment

Choose a reason for hiding this comment

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

This PR adds Bytez as a new chat model provider with a well-structured implementation. I've identified a few improvements that could enhance error handling and performance.

Copy link
Contributor

Important

PR Review Skipped

PR review skipped as per the configuration setting. Run a manually review by commenting /matter review

💡Tips to use Matter AI

Command List

  • /matter summary: Generate AI Summary for the PR
  • /matter review: Generate AI Reviews for the latest commit in the PR
  • /matter review-full: Generate AI Reviews for the complete PR
  • /matter release-notes: Generate AI release-notes for the PR
  • /matter : Chat with your PR with Matter AI Agent
  • /matter remember : Generate AI memories for the PR
  • /matter explain: Get an explanation of the PR
  • /matter help: Show the list of available commands and documentation
  • Need help? Join our Discord server: https://discord.gg/fJU5DvanU3

Copy link
Contributor

Important

PR Review Skipped

PR review skipped as per the configuration setting. Run a manually review by commenting /matter review

💡Tips to use Matter AI

Command List

  • /matter summary: Generate AI Summary for the PR
  • /matter review: Generate AI Reviews for the latest commit in the PR
  • /matter review-full: Generate AI Reviews for the complete PR
  • /matter release-notes: Generate AI release-notes for the PR
  • /matter : Chat with your PR with Matter AI Agent
  • /matter remember : Generate AI memories for the PR
  • /matter explain: Get an explanation of the PR
  • /matter help: Show the list of available commands and documentation
  • Need help? Join our Discord server: https://discord.gg/fJU5DvanU3

Copy link
Contributor

Important

PR Review Skipped

PR review skipped as per the configuration setting. Run a manually review by commenting /matter review

💡Tips to use Matter AI

Command List

  • /matter summary: Generate AI Summary for the PR
  • /matter review: Generate AI Reviews for the latest commit in the PR
  • /matter review-full: Generate AI Reviews for the complete PR
  • /matter release-notes: Generate AI release-notes for the PR
  • /matter : Chat with your PR with Matter AI Agent
  • /matter remember : Generate AI memories for the PR
  • /matter explain: Get an explanation of the PR
  • /matter help: Show the list of available commands and documentation
  • Need help? Join our Discord server: https://discord.gg/fJU5DvanU3

@inf3rnus
Copy link
Contributor Author

inf3rnus commented Jun 26, 2025

Consider replacing the custom LRUCache implementation with a well-tested, battle-hardened library for caching to improve robustness and reduce potential maintenance overhead.

We do not want to bloat the code base with packages that aren't needed. It should be sufficient.

Enhance the constructFailureResponse function to map specific Bytez API error codes (e.g., 4xx client errors, 401 authentication errors) to appropriate HTTP status codes instead of defaulting to a generic 500. This provides more informative error responses to the client.

It already does this where necessary, otherwise whatever is passed from the server is passed to the client

Review the validateModelIsChat function's error handling. While it currently throws an error that is caught, consider if it should directly return a Response object using constructFailureResponse for consistency with other API error paths.

Overkill, either fetch is going to fail, or there is an upstream error, either way it will get reported to the client.

Add comprehensive unit tests for the new Bytez integration logic, specifically for bodyAdapter, LRUCache, and the chatComplete request handler, to ensure correct functionality and prevent regressions.

Perhaps in the future...

Verify the splitPattern = ' ' for Bytez in getStreamModeSplitPattern against Bytez's actual streaming API documentation to confirm it correctly handles their specific stream format, as this is an unusual pattern for streaming.

We currently stream character by character, we do not return JSON chunks. In the future we may update this.

Explore making the bodyAdapter logic more declarative or configurable, especially if future provider integrations might require similar but slightly varied request body transformations. This could improve maintainability and readability for complex adaptations.

YAGNI and overkill, bytez manages its own integration code.

Copy link
Contributor

Important

PR Review Skipped

PR review skipped as per the configuration setting. Run a manually review by commenting /matter review

💡Tips to use Matter AI

Command List

  • /matter summary: Generate AI Summary for the PR
  • /matter review: Generate AI Reviews for the latest commit in the PR
  • /matter review-full: Generate AI Reviews for the complete PR
  • /matter release-notes: Generate AI release-notes for the PR
  • /matter : Chat with your PR with Matter AI Agent
  • /matter remember : Generate AI memories for the PR
  • /matter explain: Get an explanation of the PR
  • /matter help: Show the list of available commands and documentation
  • Need help? Join our Discord server: https://discord.gg/fJU5DvanU3

Copy link
Contributor

Important

PR Review Skipped

PR review skipped as per the configuration setting. Run a manually review by commenting /matter review

💡Tips to use Matter AI

Command List

  • /matter summary: Generate AI Summary for the PR
  • /matter review: Generate AI Reviews for the latest commit in the PR
  • /matter review-full: Generate AI Reviews for the complete PR
  • /matter release-notes: Generate AI release-notes for the PR
  • /matter : Chat with your PR with Matter AI Agent
  • /matter remember : Generate AI memories for the PR
  • /matter explain: Get an explanation of the PR
  • /matter help: Show the list of available commands and documentation
  • Need help? Join our Discord server: https://discord.gg/fJU5DvanU3

Copy link
Contributor

Important

PR Review Skipped

PR review skipped as per the configuration setting. Run a manually review by commenting /matter review

💡Tips to use Matter AI

Command List

  • /matter summary: Generate AI Summary for the PR
  • /matter review: Generate AI Reviews for the latest commit in the PR
  • /matter review-full: Generate AI Reviews for the complete PR
  • /matter release-notes: Generate AI release-notes for the PR
  • /matter : Chat with your PR with Matter AI Agent
  • /matter remember : Generate AI memories for the PR
  • /matter explain: Get an explanation of the PR
  • /matter help: Show the list of available commands and documentation
  • Need help? Join our Discord server: https://discord.gg/fJU5DvanU3

Copy link
Contributor

Important

PR Review Skipped

PR review skipped as per the configuration setting. Run a manually review by commenting /matter review

💡Tips to use Matter AI

Command List

  • /matter summary: Generate AI Summary for the PR
  • /matter review: Generate AI Reviews for the latest commit in the PR
  • /matter review-full: Generate AI Reviews for the complete PR
  • /matter release-notes: Generate AI release-notes for the PR
  • /matter : Chat with your PR with Matter AI Agent
  • /matter remember : Generate AI memories for the PR
  • /matter explain: Get an explanation of the PR
  • /matter help: Show the list of available commands and documentation
  • Need help? Join our Discord server: https://discord.gg/fJU5DvanU3

@inf3rnus
Copy link
Contributor Author

inf3rnus commented Jul 9, 2025

@narengogi @VisargD Requested changes have been made, and I dropped the LRU.

Pls lmk if you need any further changes.

Copy link
Collaborator

@narengogi narengogi left a comment

Choose a reason for hiding this comment

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

looks good to go! adding two minor comments

Copy link
Contributor

Important

PR Review Skipped

PR review skipped as per the configuration setting. Run a manually review by commenting /matter review

💡Tips to use Matter AI

Command List

  • /matter summary: Generate AI Summary for the PR
  • /matter review: Generate AI Reviews for the latest commit in the PR
  • /matter review-full: Generate AI Reviews for the complete PR
  • /matter release-notes: Generate AI release-notes for the PR
  • /matter : Chat with your PR with Matter AI Agent
  • /matter remember : Generate AI memories for the PR
  • /matter explain: Get an explanation of the PR
  • /matter help: Show the list of available commands and documentation
  • Need help? Join our Discord server: https://discord.gg/fJU5DvanU3

Copy link
Contributor

Important

PR Review Skipped

PR review skipped as per the configuration setting. Run a manually review by commenting /matter review

💡Tips to use Matter AI

Command List

  • /matter summary: Generate AI Summary for the PR
  • /matter review: Generate AI Reviews for the latest commit in the PR
  • /matter review-full: Generate AI Reviews for the complete PR
  • /matter release-notes: Generate AI release-notes for the PR
  • /matter : Chat with your PR with Matter AI Agent
  • /matter remember : Generate AI memories for the PR
  • /matter explain: Get an explanation of the PR
  • /matter help: Show the list of available commands and documentation
  • Need help? Join our Discord server: https://discord.gg/fJU5DvanU3

@inf3rnus
Copy link
Contributor Author

@narengogi @VisargD Pinging for visibility, we should be ready to rock 😄

@inf3rnus
Copy link
Contributor Author

inf3rnus commented Aug 1, 2025

@narengogi @VisargD Hey again folks!

We've created the docs that correspond to this pr on your docs repos, very much appreciate you taking the time to look this all over 😄

Portkey-AI/docs-core#455

@VisargD VisargD merged commit 2ddd3f5 into Portkey-AI:main Aug 5, 2025
1 check passed
Copy link
Contributor

Important

PR Review Skipped

PR review skipped as per the configuration setting. Run a manually review by commenting /matter review

💡Tips to use Matter AI

Command List

  • /matter summary: Generate AI Summary for the PR
  • /matter review: Generate AI Reviews for the latest commit in the PR
  • /matter review-full: Generate AI Reviews for the complete PR
  • /matter release-notes: Generate AI release-notes for the PR
  • /matter : Chat with your PR with Matter AI Agent
  • /matter remember : Generate AI memories for the PR
  • /matter explain: Get an explanation of the PR
  • /matter help: Show the list of available commands and documentation
  • Need help? Join our Discord server: https://discord.gg/fJU5DvanU3

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.

3 participants