Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Shubham Badgujar committed Apr 3, 2023
0 parents commit 5e2366d
Show file tree
Hide file tree
Showing 11 changed files with 383 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.DS_Store
npm-debug.log
node_modules
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
## 0.1.0 - First Release
* Basic feature added
20 changes: 20 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Copyright (c) 2023 <Your name here>

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.
34 changes: 34 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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.
5 changes: 5 additions & 0 deletions keymaps/writer-ai.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"body": {
"ctrl-alt-a": "ai:alpaca7b"
}
}
105 changes: 105 additions & 0 deletions lib/writer-ai-main.js
Original file line number Diff line number Diff line change
@@ -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 (
<Dialog {...modal.state} onBackdropClick={modal.close} style="max-width: 300px;">
<Dialog.Title>Writer Ai</Dialog.Title>
<Dialog.Content>Processing the request. Please wait.</Dialog.Content>
<Dialog.Actions>
<button className="ui button" onClick={modal.close}>
Close
</button>
</Dialog.Actions>
</Dialog>
);
}


export default askAiMessageDialog;
47 changes: 47 additions & 0 deletions lib/writer-ai.js
Original file line number Diff line number Diff line change
@@ -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);
},
};
31 changes: 31 additions & 0 deletions menus/writer-ai.json
Original file line number Diff line number Diff line change
@@ -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"
}
]
}
]
}
]
}
119 changes: 119 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
2 changes: 2 additions & 0 deletions styles/writer-ai.less
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.writer-ai {
}

0 comments on commit 5e2366d

Please sign in to comment.