-
Notifications
You must be signed in to change notification settings - Fork 670
feat: add 302AI provider integration #1235
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
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR adds integration for the 302AI provider with chat completion functionality. The implementation follows the existing patterns for provider integration, but I have a few suggestions to improve the code.
} catch (error) { | ||
console.error('Error parsing 302AI stream chunk:', error); | ||
return `data: ${chunk}\n\n`; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Code Refactor
Issue: The error handling in the stream chunk transformation could be improved to provide more specific error information.
Fix: Add more context to the error logging to help with debugging.
Impact: Improves troubleshooting capabilities when stream parsing fails.
} catch (error) { | |
console.error('Error parsing 302AI stream chunk:', error); | |
return `data: ${chunk}\n\n`; | |
} | |
} catch (error) { | |
console.error('Error parsing 302AI stream chunk:', error, 'Chunk:', chunk); | |
return `data: ${chunk}\ | |
\ | |
`; | |
} |
getEndpoint: ({ fn }) => { | ||
switch (fn) { | ||
case 'chatComplete': | ||
return '/v1/chat/completions'; | ||
default: | ||
return ''; | ||
} | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Code Refactor
Issue: The API endpoint handling doesn't include a case for potential future endpoints.
Fix: Add a more descriptive error for unsupported function types.
Impact: Improves developer experience when implementing new functions.
getEndpoint: ({ fn }) => { | |
switch (fn) { | |
case 'chatComplete': | |
return '/v1/chat/completions'; | |
default: | |
return ''; | |
} | |
}, | |
getEndpoint: ({ fn }) => { | |
switch (fn) { | |
case 'chatComplete': | |
return '/v1/chat/completions'; | |
default: | |
console.warn(`Unsupported function type for 302AI: ${fn}`); | |
return ''; | |
} | |
}, |
) => string = (responseChunk) => { | ||
let chunk = responseChunk.trim(); | ||
chunk = chunk.replace(/^data: /, ''); | ||
chunk = chunk.trim(); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
⚡️ Performance Improvement
Issue: The stream chunk parsing has redundant trim operations.
Fix: Combine the trim operations into a single step.
Impact: Slightly improves performance by reducing string operations.
) => string = (responseChunk) => { | |
let chunk = responseChunk.trim(); | |
chunk = chunk.replace(/^data: /, ''); | |
chunk = chunk.trim(); | |
) => { | |
let chunk = responseChunk.replace(/^data: /, '').trim(); | |
if (chunk === '[DONE]') { |
Important PR Review SkippedPR review skipped as per the configuration setting. Run a manually review by commenting /matter review 💡Tips to use Matter AICommand List
|
Description
Add 302AI Provider
Motivation
Expand the gateway's provider ecosystem
Type of Change
How Has This Been Tested?
Screenshots (if applicable)
Checklist