-
Notifications
You must be signed in to change notification settings - Fork 149
Added ML Sklearn Prediction Node #715
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
Draft
Tejeshyewale
wants to merge
59
commits into
rocketride-org:develop
Choose a base branch
from
Tejeshyewale:develop
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 17 commits
Commits
Show all changes
59 commits
Select commit
Hold shift + click to select a range
f4f7aa5
Fix typo in pipeline source node description
Tejeshyewale b22e844
docs: improve README clarity and deployment instructions
Tejeshyewale 319fca1
Update README.md
Tejeshyewale 7ce10e3
Create README.md
Tejeshyewale 90fac4d
Create code.py
Tejeshyewale b0598a2
Create IGlobal.py
Tejeshyewale ca2b870
Create IInstance.py
Tejeshyewale 5862bd8
Create services.json
Tejeshyewale b33eff4
Create requirements.txt
Tejeshyewale be13299
Update code.py
Tejeshyewale 4d88f21
Add files via upload
Tejeshyewale 48a784f
Rename IInstance.py to Instance.py
Tejeshyewale 7e6963d
Update services.json
Tejeshyewale 5952843
Update requirements.txt
Tejeshyewale c667348
Update README.md
Tejeshyewale 12c00e2
Update requirements.txt
Tejeshyewale c587ada
Update code.py
Tejeshyewale bb482f0
Merge branch 'rocketride-org:develop' into develop
Tejeshyewale 8e676e5
Fix PreProcessor structure and improve error handling
Tejeshyewale 50a0bd4
Fix PreProcessor node structure and improve error handling
Tejeshyewale 96cf781
Update IGlobal.py
Tejeshyewale 92593be
Update Instance.py
Tejeshyewale fe1f418
Update code.py
Tejeshyewale 89504f9
Update code.py
Tejeshyewale dc7f679
Update IGlobal.py
Tejeshyewale 4c9d406
Update Instance.py
Tejeshyewale c39113d
Update services.json
Tejeshyewale 47ad4f9
Update code.py
Tejeshyewale 3e8e46b
Update IGlobal.py
Tejeshyewale 5399865
Update Instance.py
Tejeshyewale 43c725d
Update README.md
Tejeshyewale 5602c71
Merge branch 'rocketride-org:develop' into develop
Tejeshyewale 9eaba7e
Update IGlobal.py
Tejeshyewale efa13f6
Update Instance.py
Tejeshyewale 66e54c3
Update code.py
Tejeshyewale cc8840e
Create __init__.py
Tejeshyewale 1f33c2f
Update requirements.txt
Tejeshyewale 4d29752
Update services.json
Tejeshyewale 9ad5458
Rename Instance.py to IInstance.py
Tejeshyewale 282a102
Delete nodes/src/nodes/ml_sklearn/model.pkl
Tejeshyewale 718b5ce
Merge branch 'rocketride-org:develop' into develop
Tejeshyewale 46d6428
Merge branch 'develop' into develop
kwit75 83abe32
Merge branch 'develop' into develop
kwit75 3d91916
Merge branch 'rocketride-org:develop' into develop
Tejeshyewale 2f66442
Update code.py
Tejeshyewale 7039924
Update IGlobal.py
Tejeshyewale dc2ab2f
Update IInstance.py
Tejeshyewale f36b225
Update services.json
Tejeshyewale 0e4e36a
Update requirements.txt
Tejeshyewale c20d8ed
Merge branch 'rocketride-org:develop' into develop
Tejeshyewale 5db3751
fix: ml_sklearn node - working inference, fixed services.json, added …
Tejeshyewale 6c53920
fix: ruff linting issues in ml_sklearn node
Tejeshyewale 40a4ee5
fix: ml_sklearn - forward input unchanged when no model loaded
Tejeshyewale d359ae4
fix: ml_sklearn - add writeText handler for text lane input
Tejeshyewale 9671737
fix: ml_sklearn - ruff format fixes
Tejeshyewale 57943c9
fix: ml_sklearn - writeText takes plain string not question object
Tejeshyewale 26c9ac7
fix: ml_sklearn - use Answer object with getText/setText pattern
Tejeshyewale f61ba71
fix: ml_sklearn - use answers lane for input and test
Tejeshyewale 6894f7b
fix: ml_sklearn - fix test case format to match guardrails pattern
Tejeshyewale File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| # ============================================================================= | ||
| # MIT License | ||
| # Copyright (c) 2026 Aparavi Software AG | ||
| # | ||
| # Permission is hereby granted, free of charge, to any person obtaining a copy | ||
| # of this software and associated documentation files (the "Software"), to deal | ||
| # in the Software without restriction, including without limitation the rights | ||
| # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
| # copies of the Software, and to permit persons to whom the Software is | ||
| # furnished to do so, subject to the following conditions: | ||
| # | ||
| # The above copyright notice and this permission notice shall be included in | ||
| # all copies or substantial portions of the Software. | ||
| # | ||
| # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
| # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
| # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
| # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
| # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
| # SOFTWARE. | ||
| # ============================================================================= | ||
|
|
||
| from rocketlib import IGlobalBase, OPEN_MODE | ||
| from ai.common.preprocessor import PreProcessorBase | ||
|
|
||
|
|
||
| class IGlobal(IGlobalBase): | ||
| preprocessor: PreProcessorBase | None = None | ||
|
|
||
| def beginGlobal(self): | ||
| # Are we in config mode or some other mode? | ||
| if self.IEndpoint.endpoint.openMode == OPEN_MODE.CONFIG: | ||
| # We are going to get a call to configureService but | ||
| # we don't actually need to load the driver for that | ||
| pass | ||
| else: | ||
| from .code import PreProcessor | ||
|
|
||
| # Get our bag | ||
| bag = self.IEndpoint.endpoint.bag | ||
|
|
||
| # Create the preprocessor | ||
| self.preprocessor = PreProcessor(self.glb.logicalType, self.glb.connConfig, bag) | ||
|
|
||
| def endGlobal(self): | ||
| # Destroy the preprocessor | ||
| self.preprocessor = None | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| # ============================================================================= | ||
| # MIT License | ||
| # Copyright (c) 2026 Aparavi Software AG | ||
| # | ||
| # Permission is hereby granted, free of charge, to any person obtaining a copy | ||
| # of this software and associated documentation files (the "Software"), to deal | ||
| # in the Software without restriction, including without limitation the rights | ||
| # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
| # copies of the Software, and to permit persons to whom the Software is | ||
| # furnished to do so, subject to the following conditions: | ||
| # | ||
| # The above copyright notice and this permission notice shall be included in | ||
| # all copies or substantial portions of the Software. | ||
| # | ||
| # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
| # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
| # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
| # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
| # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
| # SOFTWARE. | ||
| # ============================================================================= | ||
|
|
||
| from rocketlib import IInstanceBase, Entry, warning | ||
| from typing import List | ||
| from ai.common.schema import Doc, DocMetadata | ||
| from . import IGlobal | ||
|
|
||
|
|
||
| class IInstance(IInstanceBase): | ||
| IGlobal: IGlobal | ||
|
|
||
| chunkId: int = 0 | ||
| tableId: int = 0 | ||
|
|
||
| def _writeTableOrText(self, text: str, isTable: bool = False): | ||
| # Fill in the metadata | ||
| metadata = DocMetadata( | ||
| self, | ||
| chunkId=0, | ||
| isTable=isTable, | ||
| tableId=0, | ||
| isDeleted=False, | ||
| ) | ||
|
|
||
| # Chunk the document | ||
| textChunks = self.IGlobal.preprocessor.process(text) | ||
| if not textChunks: | ||
| warning(f'The file {self.instance.currentObject.path} could not be processed, because it does not appear to contain supported source code in one of these languages: c/c++, python, javascript, typescript, typescript.') | ||
|
coderabbitai[bot] marked this conversation as resolved.
Outdated
|
||
| return | ||
|
|
||
| # Create the documents | ||
| documents: List[Doc] = [] | ||
| for chunk in textChunks: | ||
| # Create the document from it | ||
| document = Doc(page_content=chunk, metadata=metadata.model_copy()) | ||
|
|
||
| # Assign the chunk id | ||
| document.metadata.chunkId = self.chunkId | ||
| self.chunkId = self.chunkId + 1 | ||
|
|
||
| # If this is a table or not | ||
| if isTable: | ||
| self.tableId = self.tableId | ||
| else: | ||
| self.tableId = 0 | ||
|
|
||
| # Append it to the list | ||
| documents.append(document) | ||
|
|
||
| # If there are no documents, done | ||
| if not len(documents): | ||
| return | ||
|
|
||
| # If this is a table | ||
| if isTable: | ||
| metadata.tableId = self.tableId | ||
| self.tableId += 1 | ||
|
|
||
|
coderabbitai[bot] marked this conversation as resolved.
Outdated
|
||
| # Write the documents | ||
| self.instance.writeDocuments(documents) | ||
|
|
||
| def open(self, object: Entry): | ||
|
coderabbitai[bot] marked this conversation as resolved.
Outdated
|
||
| self.chunkId = 0 | ||
| self.tableId = 0 | ||
|
|
||
| def writeTable(self, table: str): | ||
| self._writeTableOrText(table, True) | ||
|
|
||
| def writeText(self, text: str): | ||
| self._writeTableOrText(text, False) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| # ML Sklearn Prediction Node | ||
|
|
||
| This node performs predictions using a trained sklearn model. | ||
|
|
||
| ## Input | ||
| - price (number) | ||
|
|
||
| ## Output | ||
| - prediction (number) | ||
|
|
||
| ## Example | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| Input: | ||
| { | ||
| "price": 250 | ||
| } | ||
|
|
||
| Output: | ||
| { | ||
| "prediction": 3.5 | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| import pickle | ||
| import os | ||
|
|
||
| class Node: | ||
| def __init__(self): | ||
| # Load model safely | ||
| model_path = os.path.join(os.path.dirname(__file__), "model.pkl") | ||
| with open(model_path, "rb") as f: | ||
| self.model = pickle.load(f) | ||
|
coderabbitai[bot] marked this conversation as resolved.
Outdated
|
||
|
|
||
| def run(self, input_data): | ||
| try: | ||
| # Validate input | ||
| if not isinstance(input_data, dict): | ||
| return {"error": "Input must be a dictionary"} | ||
|
|
||
| price = input_data.get("price") | ||
|
|
||
| if price is None: | ||
| return {"error": "Missing 'price'"} | ||
|
|
||
| # Convert to float safely | ||
| try: | ||
| price = float(price) | ||
| except ValueError: | ||
| return {"error": "Price must be a number"} | ||
|
coderabbitai[bot] marked this conversation as resolved.
Outdated
|
||
|
|
||
| # Prediction | ||
| prediction = self.model.predict([[price]]) | ||
|
|
||
| return { | ||
| "prediction": float(prediction[0]) | ||
| } | ||
|
|
||
| except Exception: | ||
| return {"error": "Prediction failed"} | ||
|
coderabbitai[bot] marked this conversation as resolved.
Outdated
|
||
Binary file not shown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| scikit-learn>=1.0 | ||
| numpy>=1.21 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| { | ||
| "title": "ML Sklearn Prediction", | ||
| "protocol": "ml_sklearn://", | ||
| "classType": ["machine_learning"], | ||
| "capabilities": [], | ||
| "register": "filter", | ||
| "node": "python", | ||
| "path": "nodes.ml_sklearn", | ||
| "prefix": "ML", | ||
| "description": [ | ||
| "A machine learning node that performs prediction using a trained sklearn model.", | ||
| "It accepts numerical input and returns predicted output." | ||
| ], | ||
| "icon": "python.svg", | ||
| "documentation": "https://docs.rocketride.org", | ||
| "lanes": { | ||
| "input": ["data"] | ||
| }, | ||
| "input": [ | ||
| { | ||
| "lane": "input", | ||
| "output": [ | ||
| { | ||
| "lane": "data" | ||
| } | ||
| ] | ||
| } | ||
| ] | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.