feat(embeddings): add LM Studio embeddings node#5877
feat(embeddings): add LM Studio embeddings node#5877stablegenius49 wants to merge 2 commits intoFlowiseAI:mainfrom
Conversation
Summary of ChangesHello, 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 Flowise's capabilities by integrating native support for LM Studio embeddings. It provides users with a dedicated node to generate embeddings using LM Studio's OpenAI-compatible API, facilitating local and private embedding workflows. This addition addresses a community request and expands the range of available embedding providers within the platform. 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
This pull request introduces support for LM Studio embeddings by adding a new credential and a new embeddings node. The implementation correctly leverages the existing OpenAIEmbeddings class, which is suitable for LM Studio's OpenAI-compatible API. The code is well-structured and follows the patterns of existing nodes. I have one suggestion to improve the robustness of handling numeric input parameters to prevent potential issues with certain values like 0 or non-numeric inputs, aligning with repository guidelines for nullish checks.
| if (batchSize) obj.batchSize = parseInt(batchSize, 10) | ||
| if (timeout) obj.timeout = parseInt(timeout, 10) | ||
| if (dimensions) obj.dimensions = parseInt(dimensions, 10) |
There was a problem hiding this comment.
The current implementation for handling numeric inputs (along with their declarations on lines 81-83) can be made more robust. The if (variable) check evaluates to false for a numeric value of 0, which might be a valid input for timeout. Also, the as string type assertion is unsafe, and parseInt can result in NaN for invalid inputs.
Consider this more robust approach that validates the input before parsing and assigning it. This also makes the separate variable declarations on lines 81-83 unnecessary. This suggestion aligns with the repository's guideline to use loose equality (== null) for nullish checks in TypeScript, covering both null and undefined.
| if (batchSize) obj.batchSize = parseInt(batchSize, 10) | |
| if (timeout) obj.timeout = parseInt(timeout, 10) | |
| if (dimensions) obj.dimensions = parseInt(dimensions, 10) | |
| if (nodeData.inputs?.batchSize != null && nodeData.inputs?.batchSize !== '') { | |
| const batchSize = parseInt(String(nodeData.inputs.batchSize), 10) | |
| if (!isNaN(batchSize)) obj.batchSize = batchSize | |
| } | |
| if (nodeData.inputs?.timeout != null && nodeData.inputs?.timeout !== '') { | |
| const timeout = parseInt(String(nodeData.inputs.timeout), 10) | |
| if (!isNaN(timeout)) obj.timeout = timeout | |
| } | |
| if (nodeData.inputs?.dimensions != null && nodeData.inputs?.dimensions !== '') { | |
| const dimensions = parseInt(String(nodeData.inputs.dimensions), 10) | |
| if (!isNaN(dimensions)) obj.dimensions = dimensions | |
| } |
References
- In JavaScript/TypeScript, use loose equality (
== null) as a standard idiom for a 'nullish' check that covers bothnullandundefined.
|
Addressed the robustness suggestion in a follow-up commit (b4e6b1d).
Local checks passed:
|
Summary
Adds first-class LM Studio embedding support via a dedicated node in Flowise.
What changed
lmStudioApipackages/components/credentials/LMStudioApi.credential.tslmStudioApiKeyLM Studio Embeddingspackages/components/nodes/embeddings/LMStudioEmbedding/LMStudioEmbedding.tsOpenAIEmbeddingsfrom@langchain/openaihttp://localhost:1234/v1openAIApiKey: 'sk-') and accepts key when providedpackages/components/nodes/embeddings/LMStudioEmbedding/lmstudio.svgWhy
Issue #1277 requests native LM Studio embeddings support. LM Studio exposes an OpenAI-compatible API and is commonly used for local/private embedding workflows.
Verification
Commands run locally:
corepack pnpm exec eslint \ packages/components/credentials/LMStudioApi.credential.ts \ packages/components/nodes/embeddings/LMStudioEmbedding/LMStudioEmbedding.ts corepack pnpm --filter flowise-components buildBuild completed successfully.
Fixes #1277