From 5e2366dd70687e258d065ba52bffed5151b2d126 Mon Sep 17 00:00:00 2001 From: Shubham Badgujar Date: Mon, 3 Apr 2023 13:34:53 +0530 Subject: [PATCH] first commit --- .gitignore | 3 ++ CHANGELOG.md | 2 + LICENSE.md | 20 +++++++ README.md | 34 ++++++++++++ keymaps/writer-ai.json | 5 ++ lib/writer-ai-main.js | 105 ++++++++++++++++++++++++++++++++++++ lib/writer-ai.js | 47 ++++++++++++++++ menus/writer-ai.json | 31 +++++++++++ package-lock.json | 119 +++++++++++++++++++++++++++++++++++++++++ package.json | 15 ++++++ styles/writer-ai.less | 2 + 11 files changed, 383 insertions(+) create mode 100644 .gitignore create mode 100644 CHANGELOG.md create mode 100644 LICENSE.md create mode 100644 README.md create mode 100644 keymaps/writer-ai.json create mode 100644 lib/writer-ai-main.js create mode 100644 lib/writer-ai.js create mode 100644 menus/writer-ai.json create mode 100644 package-lock.json create mode 100644 package.json create mode 100644 styles/writer-ai.less diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ade14b9 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +.DS_Store +npm-debug.log +node_modules diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..24a8b10 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,2 @@ +## 0.1.0 - First Release +* Basic feature added diff --git a/LICENSE.md b/LICENSE.md new file mode 100644 index 0000000..e6a8da5 --- /dev/null +++ b/LICENSE.md @@ -0,0 +1,20 @@ +Copyright (c) 2023 + +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. diff --git a/README.md b/README.md new file mode 100644 index 0000000..0f6c15c --- /dev/null +++ b/README.md @@ -0,0 +1,34 @@ +# Writer AI Plugin for Inkdrop +The Writer AI plugin for Inkdrop adds artificial intelligence (AI) functionality to your note-taking workflow. Powered by the Alpaca AI model, this plugin allows you to perform various AI tasks directly in your Inkdrop notes, without leaving your local system. + +![](./assets/video_001.gif) + + +## Features + +- Natural Language Generation: Generate natural-sounding text based on prompts or existing text. +- Text Summarization: Summarize long texts to extract the main points. +- Text Completion: Automatically complete text based on what you've already written. +- Sentiment Analysis: Analyze the sentiment of a piece of text and get a score. +- Topic Modeling: Identify the main topics in a piece of text and get a list of keywords. + +> Modify Instructions Option in plugins settings to have this possible features or thers to you liking + +## Requirements + +To use this plugin, you need to have the following software installed on your local system: + +- Inkdrop +- [Dalai](https://github.com/cocktailpeanut/dalai) (make sure Dalai server is on and you have alpaca 7B modal installed) + + +## Keybindings + +| Keybinding | Description | +| ---------- | -------------------------------- | +| Ctrl-Alt-A | Starts the magic | + + +## License + +This plugin is released under the MIT License. \ No newline at end of file diff --git a/keymaps/writer-ai.json b/keymaps/writer-ai.json new file mode 100644 index 0000000..37e1e5c --- /dev/null +++ b/keymaps/writer-ai.json @@ -0,0 +1,5 @@ +{ + "body": { + "ctrl-alt-a": "ai:alpaca7b" + } +} diff --git a/lib/writer-ai-main.js b/lib/writer-ai-main.js new file mode 100644 index 0000000..eef23dc --- /dev/null +++ b/lib/writer-ai-main.js @@ -0,0 +1,105 @@ +"use babel"; + +import { useModal, actions } from "inkdrop"; +import { io } from "socket.io-client"; + + +let modal +const socket = io("ws://localhost:3000"); +socket.on('connect', () => { + console.log('Successfully connected!'); + + }); + socket.io.on("error", (error) => { + console.log("SOcket err"); + modal.close() + }); + + +const askFunction =async () => { + if (!socket.connected){ + + inkdrop.notifications.addError('Writer AI', { dismissable: true, detail: "Cant Connect to dalai server. Please start Dalai server and restart Inkdrop" }) + + return + } + console.log("ask funcction"); + const { editingNote } = inkdrop.store.getState() + const noteBody = editingNote.body + modal.show() + let prompt=`### Instruction: +${inkdrop.config.get('writer-ai.instruction')} + +${noteBody} + +### Response: +` + + + + socket.emit("request",{ + seed: -1, + threads: inkdrop.config.get('writer-ai.threads'), + n_predict: inkdrop.config.get('writer-ai.n_predict'), + top_k: 40, + top_p:0.9, + temp: 0.8, + repeat_last_n: 64, + repeat_penalty: 1.3, + skip_end:true, + debug: false, + models: ["alpaca.7B"], + model: inkdrop.config.get('writer-ai.model') , + prompt: prompt, //.split("\n").join("\\n") + } ); + let count=0 + let flag = false; + function callonce(){ + if (!flag) { + inkdrop.store.dispatch(actions.editingNote.update({ body: (inkdrop.store.getState()).editingNote.body+"\nAI:" })) + inkdrop.store.dispatch(actions.editor.change(true)) + flag = true; + modal.close() + } + } + + socket.on("result", (data) => { + let token=data["response"] + count+=token.length + console.log(token); + if(count>=prompt.length){ + + inkdrop.store.dispatch(actions.editingNote.update({ body: (inkdrop.store.getState()).editingNote.body+token })) + inkdrop.store.dispatch(actions.editor.change(true)) + callonce() + } + + }); + + +} + + +inkdrop.commands.add(document.body, { + "ai:alpaca7b": askFunction, +}) + +const askAiMessageDialog = (props) => { + modal = useModal(); + const { Dialog } = inkdrop.components.classes; + + return ( + + Writer Ai + Processing the request. Please wait. + + + + + ); +} + + + export default askAiMessageDialog; \ No newline at end of file diff --git a/lib/writer-ai.js b/lib/writer-ai.js new file mode 100644 index 0000000..975d4b9 --- /dev/null +++ b/lib/writer-ai.js @@ -0,0 +1,47 @@ +"use babel"; + + import askAiMessageDialog from "./writer-ai-main"; + +module.exports = { + config : { + instruction: { + title: 'Write An Instruction For AI model(you can ask it to translate,autocomplete or anything you want)', + type: 'string', + default: 'Can you explain this concept in simple terms?' + }, + model: { + title: 'Select LLM Model', + type: 'string', + default: 'alpaca.7B' , + enum: [ 'alpaca.7B' ] + }, + n_predict: { + title: 'Amount Of Token ..To Predict', + type: 'integer', + default: 75, + minimum: 1 + }, + threads: { + title: 'Number Threads Model Should Use?', + type: 'integer', + default: 8, + minimum: 1 + } + }, + + activate() { + console.log("activate funcction2"); + + inkdrop.components.registerClass(askAiMessageDialog); + inkdrop.layouts.addComponentToLayout("modal", "askAiMessageDialog"); + }, + + deactivate() { + console.log("deactivate funcction"); + inkdrop.layouts.removeComponentFromLayout( + "modal", + "askAiMessageDialog" + ); + inkdrop.components.deleteClass(askAiMessageDialog); + }, +}; diff --git a/menus/writer-ai.json b/menus/writer-ai.json new file mode 100644 index 0000000..3f78255 --- /dev/null +++ b/menus/writer-ai.json @@ -0,0 +1,31 @@ +{ + "context-menu": { + ".CodeMirror": [ + { + "label": "Writer-AI", + "submenu": [ + { + "label": "Alpaca 7B", + "command": "ai:alpaca7b" + } + ] + } + ] + }, + "menu": [ + { + "label": "Plugins", + "submenu": [ + { + "label": "Writer-AI (offline-AI)", + "submenu": [ + { + "label": "Alpaca 7B", + "command": "ai:alpaca7b" + } + ] + } + ] + } + ] +} diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 0000000..35bef14 --- /dev/null +++ b/package-lock.json @@ -0,0 +1,119 @@ +{ + "name": "writer-ai", + "version": "0.1.0", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "name": "writer-ai", + "version": "0.1.0", + "license": "MIT", + "dependencies": { + "socket.io-client": "^4.6.1" + }, + "engines": { + "inkdrop": "^5.3.1" + } + }, + "node_modules/@socket.io/component-emitter": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/@socket.io/component-emitter/-/component-emitter-3.1.0.tgz", + "integrity": "sha512-+9jVqKhRSpsc591z5vX+X5Yyw+he/HCB4iQ/RYxw35CEPaY1gnsNE43nf9n9AaYjAQrTiI/mOwKUKdUs9vf7Xg==" + }, + "node_modules/debug": { + "version": "4.3.4", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.4.tgz", + "integrity": "sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ==", + "dependencies": { + "ms": "2.1.2" + }, + "engines": { + "node": ">=6.0" + }, + "peerDependenciesMeta": { + "supports-color": { + "optional": true + } + } + }, + "node_modules/engine.io-client": { + "version": "6.4.0", + "resolved": "https://registry.npmjs.org/engine.io-client/-/engine.io-client-6.4.0.tgz", + "integrity": "sha512-GyKPDyoEha+XZ7iEqam49vz6auPnNJ9ZBfy89f+rMMas8AuiMWOZ9PVzu8xb9ZC6rafUqiGHSCfu22ih66E+1g==", + "dependencies": { + "@socket.io/component-emitter": "~3.1.0", + "debug": "~4.3.1", + "engine.io-parser": "~5.0.3", + "ws": "~8.11.0", + "xmlhttprequest-ssl": "~2.0.0" + } + }, + "node_modules/engine.io-parser": { + "version": "5.0.6", + "resolved": "https://registry.npmjs.org/engine.io-parser/-/engine.io-parser-5.0.6.tgz", + "integrity": "sha512-tjuoZDMAdEhVnSFleYPCtdL2GXwVTGtNjoeJd9IhIG3C1xs9uwxqRNEu5WpnDZCaozwVlK/nuQhpodhXSIMaxw==", + "engines": { + "node": ">=10.0.0" + } + }, + "node_modules/ms": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", + "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==" + }, + "node_modules/socket.io-client": { + "version": "4.6.1", + "resolved": "https://registry.npmjs.org/socket.io-client/-/socket.io-client-4.6.1.tgz", + "integrity": "sha512-5UswCV6hpaRsNg5kkEHVcbBIXEYoVbMQaHJBXJCyEQ+CiFPV1NIOY0XOFWG4XR4GZcB8Kn6AsRs/9cy9TbqVMQ==", + "dependencies": { + "@socket.io/component-emitter": "~3.1.0", + "debug": "~4.3.2", + "engine.io-client": "~6.4.0", + "socket.io-parser": "~4.2.1" + }, + "engines": { + "node": ">=10.0.0" + } + }, + "node_modules/socket.io-parser": { + "version": "4.2.2", + "resolved": "https://registry.npmjs.org/socket.io-parser/-/socket.io-parser-4.2.2.tgz", + "integrity": "sha512-DJtziuKypFkMMHCm2uIshOYC7QaylbtzQwiMYDuCKy3OPkjLzu4B2vAhTlqipRHHzrI0NJeBAizTK7X+6m1jVw==", + "dependencies": { + "@socket.io/component-emitter": "~3.1.0", + "debug": "~4.3.1" + }, + "engines": { + "node": ">=10.0.0" + } + }, + "node_modules/ws": { + "version": "8.11.0", + "resolved": "https://registry.npmjs.org/ws/-/ws-8.11.0.tgz", + "integrity": "sha512-HPG3wQd9sNQoT9xHyNCXoDUa+Xw/VevmY9FoHyQ+g+rrMn4j6FB4np7Z0OhdTgjx6MgQLK7jwSy1YecU1+4Asg==", + "engines": { + "node": ">=10.0.0" + }, + "peerDependencies": { + "bufferutil": "^4.0.1", + "utf-8-validate": "^5.0.2" + }, + "peerDependenciesMeta": { + "bufferutil": { + "optional": true + }, + "utf-8-validate": { + "optional": true + } + } + }, + "node_modules/xmlhttprequest-ssl": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/xmlhttprequest-ssl/-/xmlhttprequest-ssl-2.0.0.tgz", + "integrity": "sha512-QKxVRxiRACQcVuQEYFsI1hhkrMlrXHPegbbd1yn9UHOmRxY+si12nQYzri3vbzt8VdTTRviqcKxcyllFas5z2A==", + "engines": { + "node": ">=0.4.0" + } + } + } +} diff --git a/package.json b/package.json new file mode 100644 index 0000000..57281cc --- /dev/null +++ b/package.json @@ -0,0 +1,15 @@ +{ + "name": "writer-ai", + "main": "./lib/writer-ai", + "version": "1.0.0", + "description": "An Offile Ai - Features of Alpaca 7B(LLama) model similar to GPT but free and offline which uses dalai", + "keywords": [], + "repository": "https://github.com/shubham8550/writer-ai", + "license": "MIT", + "engines": { + "inkdrop": "^5.x" + }, + "dependencies": { + "socket.io-client": "^4.6.1" + } +} diff --git a/styles/writer-ai.less b/styles/writer-ai.less new file mode 100644 index 0000000..1c8d774 --- /dev/null +++ b/styles/writer-ai.less @@ -0,0 +1,2 @@ +.writer-ai { +}