feat(cohere-rerank): add custom API endpoint and model name support#5799
feat(cohere-rerank): add custom API endpoint and model name support#5799hztBUAA wants to merge 2 commits intoFlowiseAI:mainfrom
Conversation
Add Base URL and Custom Model Name inputs to the Cohere Rerank Retriever node, allowing users to configure custom API endpoints and use fine-tuned rerank models. The Base URL defaults to the standard Cohere API when not specified. Custom Model Name overrides the dropdown selection when provided. Closes FlowiseAI#4086
Summary of ChangesHello @hztBUAA, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly enhances the flexibility and configurability of the Cohere Rerank Retriever. It introduces options for users to specify custom API endpoints and utilize fine-tuned rerank models, catering to advanced use cases such as private deployments or specialized model applications. These additions empower users with greater control over their reranking infrastructure without cluttering the primary interface. Highlights
Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
The pull request successfully introduces support for custom API endpoints and model names for the Cohere Rerank Retriever node. The implementation is clean, follows existing patterns, and includes a comprehensive set of unit tests. I have suggested a few minor improvements to enhance robustness and clarity, such as trimming user inputs to handle accidental whitespace and renaming the 'Base URL' label to 'Endpoint URL' to more accurately reflect its function as a full API endpoint.
| this.model = model | ||
| this.k = k | ||
| this.maxChunksPerDoc = maxChunksPerDoc | ||
| this.cohereApiUrl = baseURL ? baseURL.replace(/\/+$/, '') : 'https://api.cohere.ai/v1/rerank' |
There was a problem hiding this comment.
It is a good practice to trim the baseURL to handle any accidental leading or trailing whitespace that might be pasted into the UI field.
| this.cohereApiUrl = baseURL ? baseURL.replace(/\/+$/, '') : 'https://api.cohere.ai/v1/rerank' | |
| this.cohereApiUrl = baseURL ? baseURL.trim().replace(/\/+$/, '') : 'https://api.cohere.ai/v1/rerank' |
| optional: true | ||
| }, | ||
| { | ||
| label: 'Base URL', |
There was a problem hiding this comment.
| const output = nodeData.outputs?.output as string | ||
|
|
||
| const cohereCompressor = new CohereRerank(cohereApiKey, model, k, max_chunks_per_doc) | ||
| const selectedModel = customModel || model |
… label - Trim baseURL to handle accidental leading/trailing whitespace from UI - Rename label from 'Base URL' to 'API Endpoint URL' for clarity - Trim customModel input to prevent invalid model names from whitespace - Add test for baseURL whitespace trimming
|
Thanks for the review and feedback. I am following up on this PR now and will either push the requested changes or reply point-by-point shortly. |
|
Quick follow-up: I am reviewing the feedback and will update this PR shortly. |
Summary
Closes #4086
Changes
CohereRerank.ts(compressor class)baseURLconstructor parameterhttps://api.cohere.ai/v1/rerankCohereRerankRetriever.ts(node definition)Custom Model Name(customModel) string input in Additional ParametersBase URL(baseURL) string input in Additional ParameterscustomModeloverrides dropdownmodelselection when providedbaseURLtoCohereRerankconstructorCohereRerank.test.ts(new test file)Test plan
npx jest CohereRerank.test.ts)