Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@kazuhitoyokoi/node-red-contrib-plugin-codecompletion

Package Overview
Dependencies
Maintainers
0
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@kazuhitoyokoi/node-red-contrib-plugin-codecompletion - npm Package Compare versions

Comparing version 0.0.3 to 0.0.4

fizzbuzz.mp4

60

index.js
const http = require("http");
module.exports = async function (RED) {
RED.httpAdmin.post("/codecomplete", RED.auth.needsPermission("codecomplete.write"), async function (req, res) {
const data1 = JSON.stringify({ "name": "granite-code" });
const options1 = {
hostname: "localhost",
port: 11434,
path: "/api/pull",
method: "POST",
headers: {
"Content-Type": "application/json",
"Content-Length": data1.length
}
};
RED.log.info("loading model...");
const req1 = http.request(options1, function (res1) {
res1.on("data", function (chunk) {
let status = JSON.parse(chunk);
RED.log.info("downloding model... " + parseInt(100 * status.completed / status.total) + "%");
});
res1.on("end", function () {
RED.log.info("model for codecompletion is loaded");
RED.comms.publish('completion', { "message": "model for code completion is loaded" });
});
});
req1.on("error", function (error) {
RED.log.info("failed to connect to Ollama server");
RED.comms.publish('completion', {
"message": "failed to connect to Ollama server",
"options": { "type": "error" }
});
});
req1.write(data1);
req1.end();
RED.httpAdmin.post("/completion", RED.auth.needsPermission("completion.write"), async function (req, res) {
let code = req.body.code;
code = code.replace("\nreturn msg;", "");
const data = JSON.stringify({
const data2 = JSON.stringify({
"model": "granite-code",

@@ -42,3 +76,3 @@ "raw": true,

const options = {
const options2 = {
hostname: "localhost",

@@ -50,3 +84,3 @@ port: 11434,

"Content-Type": "application/json",
"Content-Length": data.length
"Content-Length": data2.length
}

@@ -56,6 +90,9 @@ };

RED.log.info("generating code...");
const req2 = http.request(options, function (res2) {
const req2 = http.request(options2, function (res2) {
let completion = "";
res2.on("data", function (chunk) {
completion += JSON.parse(chunk).response;
let parsedChunk = JSON.parse(chunk);
if (parsedChunk.response) {
completion += parsedChunk.response;
}
});

@@ -69,10 +106,13 @@ res2.on("end", function () {

req2.on("error", function (error) {
RED.log.info("Failed to connect to Ollama server: " + error);
RED.log.info("failed to connect to Ollama server");
RED.comms.publish('completion', {
"message": "failed to connect to Ollama server",
"options": { "type": "error" }
});
});
req2.write(data);
req2.write(data2);
req2.end();
});
RED.plugins.registerPlugin("codecomplete", { type: "codecomplete" });
RED.plugins.registerPlugin("completion", { type: "completion" });
};

4

package.json
{
"name": "@kazuhitoyokoi/node-red-contrib-plugin-codecompletion",
"version": "0.0.3",
"version": "0.0.4",
"description": "Code completion plugin for Node-RED's function nodes",

@@ -12,3 +12,3 @@ "main": "index.js",

"plugins": {
"codecompletion": "index.js"
"completion": "index.js"
}

@@ -15,0 +15,0 @@ },

# node-red-contrib-plugin-codecompletion
Code completion plugin for Node-RED's function nodes
This plugin enables the code completion in the code editor of function nodes.
While typing code, the editor will automatically suggests the code based on the existing code.
The user can accept and insert the suggested code by simply pressing the tab key.
![](fizzbuzz.png)
## Setting up
Since this plugin uses Ollama, users need to install it in advance.
- For Windows and macOS
To set up the Ollama environment, you can use the installer provided on the following website.
https://ollama.com/download
- For Linux
Run the following command in the terminal.
```
curl -fsSL https://ollama.com/install.sh | sh
```
## Demonstration
Generating FizzBuzz code
https://github.com/user-attachments/assets/b9dabb40-ee5b-47c6-ace5-979d3cb5e03f

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc