Skip to content

Conversation

narengogi
Copy link
Collaborator

@narengogi narengogi commented Aug 13, 2025

tested with different reasoning levels
fixes #1281

Copy link
Contributor

matter-code-review bot commented Aug 13, 2025

Code Quality new feature

Summary By MatterAI MatterAI logo

🔄 What Changed

This pull request introduces support for the new '302ai' provider, enabling chat completion functionalities. It also significantly refactors the content extraction and setting utilities within the plugin system (plugins/utils.ts) to improve modularity and accommodate a new messages request type. The requestType interface in plugins/types.ts and the shouldSkipHook logic in src/middlewares/hooks/index.ts have been updated to include this new messages type.

🔍 Impact of the Change

The integration of the '302ai' provider expands the platform's capabilities by allowing users to interact with models from this new service. The refactoring of content handling utilities enhances the robustness and maintainability of the plugin system, making it more adaptable to diverse API response structures and request formats, including the new messages type. This ensures consistent and accurate data processing across different AI model providers.

📁 Total Files Changed

  • plugins/types.ts: Added 'messages' to PluginContext's requestType.
  • plugins/utils.ts: Refactored content extraction/setting logic into dedicated request/response functions and added 'messages' requestType handling.
  • src/globals.ts: Added '302ai' to the list of valid providers.
  • src/middlewares/hooks/index.ts: Updated hook skipping logic to include 'messages' requestType.
  • src/providers/302ai/api.ts: New file defining API configuration for the '302ai' provider.
  • src/providers/302ai/chatComplete.ts: New file defining chat completion configuration and response transformations for '302ai'.
  • src/providers/302ai/index.ts: New file exporting the '302ai' provider's overall configuration.
  • src/providers/index.ts: Integrated the new '302ai' provider into the main Providers object.

🧪 Test Added

Manual Testing: The PR body indicates testing with different reasoning levels, implying manual verification of the changes.

🔒 Security Vulnerabilities

N/A - No security vulnerabilities detected.

Motivation

This change was needed to properly support OpenRouter's reasoning parameters and usage tracking by transforming the input parameters into the correct format expected by the OpenRouter API.

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • 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
  • 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. Add comprehensive unit tests for the new 302ai provider integration, specifically covering AI302ChatCompleteResponseTransform and AI302ChatCompleteStreamChunkTransform to ensure correct response parsing and error handling.

  2. Implement unit tests for the refactored utility functions (getText, getCurrentContentPart, getRequestContentPart, getResponseContentPart, setCurrentContentPart, setRequestContentPart, setResponseContentPart) in plugins/utils.ts to verify their behavior across all supported requestType values and edge cases.

  3. Consider adding more robust error handling or validation within getRequestContentPart and getResponseContentPart to gracefully manage cases where expected JSON structures (e.g., json.messages, json.choices) might be missing or malformed, preventing potential runtime errors.

Tanka Poem ♫

New provider blooms,
Messages flow, refactored streams,
Code now clearer, bright.
AI's wisdom, ever vast,
Logic shines, a cosmic dance. ✨

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.

Good implementation of parameter transformation utilities. Consider adding input validation and comprehensive tests.

@VisargD VisargD merged commit 598ab6f into Portkey-AI:main Aug 13, 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.

Fix reasoning parameter transform for openrouter

2 participants