Skip to content

Commit

Permalink
Merge pull request #38 from Eroxl/chat
Browse files Browse the repository at this point in the history
Chat
  • Loading branch information
Eroxl authored Apr 30, 2023
2 parents df43fe7 + f7d34dc commit c2849c1
Show file tree
Hide file tree
Showing 43 changed files with 1,846 additions and 991 deletions.
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
**/.DS_Store

# -=- Eroxl's Device Specific Ignores -=-
**/Icon?
Icon?
!icons

# -=- Node Modules -=-
**/node_modules/**
Expand All @@ -13,3 +14,6 @@
# -=- Cypress -=-
**/cypress/screenshots
**/cypress/videos

# -=- Security -=-
/config/.env
118 changes: 26 additions & 92 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,16 @@
</div>

## 🌳 Features
* Basic Markdown Syntax
* H1, H2, H3, H4, H5
* Markdown
* Headings (H1 - H5)
* Quotes
* Custom Markdown Syntax
* Call Outs
* Page Management
* Sub Pages
* Page Navigation
* Page Styling
* Exporting
* Math
* Other Features
* Global Search
* [PDF Exporting](./images/Note%20Rack%20Page.pdf)

## 🎹 Keybinds
## 📄 Markdown Syntax
- Headings
- `#` - H1
- `##` - H2
Expand All @@ -29,103 +26,40 @@
- Other
- `>` Quote
- `|` Callout
- `$$` Math [KaTeX](https://katex.org/)
- `$$` Math ([KaTeX](https://katex.org/))
- `[[ Page Name ]]` Page ("Page Name" can be any string)

## 🎹 Keyboard Shortcuts
- `Ctrl + F` or `Cmd + F` Global Search
- `Ctrl + P` or `Cmd + P` Save Page

## 📦 Installation
1. Download the repo
* Clone the repo
```bash
git clone https://github.com/Eroxl/Note-Rack.git
```
* Or download the [zip file](https://github.com/Eroxl/Note-Rack/archive/refs/heads/main.zip)
1. Clone the repo
```bash
git clone https://github.com/Eroxl/Note-Rack.git
```

2. Navigate to the repository
* If you cloned the repo
```bash
cd Note-Rack
```
* If you downloaded the zip file
1. Unzip the file
```bash
unzip main.zip
```
2. Navigate to the folder
```bash
cd Note-Rack-main
```

2. Copy the server environment file and fill in the values
```bash
cp ./backend/.env.example /backend.env
cd ./Note-Rack
```
* If you want to open it in a text editor
```bash
nano ./backend/.env
```

3. Copy the client environment file and fill in the values
3. Copy the server environment file and fill in the values
```bash
cp ./web/src/.env.example ./web/src/.env.local
cp ./config/.env.example ./config/.env
```

* If you want to open it in a text editor
```bash
nano ./web/src/.env.local
```

4. With Docker
1. Install Docker and Docker Compose
- [Docker](https://docs.docker.com/get-docker/)
- [Docker Compose](https://docs.docker.com/compose/install/)

2. Run the Docker Compose file
```bash
docker-compose up --build
```

6. Navigate to the web application at [http://127.0.0.1:3000](http://127.0.0.1:3000)
4. Install Docker and Docker Compose
- [Docker](https://docs.docker.com/get-docker/)

5. Without Docker
1. Install Node.js
- [Node.js](https://nodejs.org/en/download/)

2. Install Yarn
- [Yarn](https://classic.yarnpkg.com/en/docs/install)

3. Install Dependencies
```bash
cd ./backend && \
yarn install && \
cd ../web && \
yarn install
```

4. Setup a MongoDB database
- Local
- [MongoDB](https://docs.mongodb.com/manual/installation/)
- Cloud
- [MongoDB Atlas](https://www.mongodb.com/cloud/atlas)

5. Setup a Supertokens instance
- Locally
- [Supertokens](https://supertokens.com/docs/thirdparty/pre-built-ui/setup/core/without-docker)
- Cloud
- [Supertokens](https://supertokens.com/docs/thirdparty/pre-built-ui/setup/core/saas-setup)

6. Run the server
```bash
cd ./backend && \
yarn dev
```
5. Run the Docker Compose file
```bash
yarn start
```

7. Run the client
```bash
cd ./web && \
yarn dev
```
6. Navigate to the web application at [http://127.0.0.1:3000](http://127.0.0.1:3000)

## 🔬 Examples

#### Current State (dark)
#### Editor
<img src="./images/Desktop_Current_State_Dark.png" width="500">
16 changes: 0 additions & 16 deletions backend/.env.example

This file was deleted.

6 changes: 0 additions & 6 deletions backend/nodemon.json

This file was deleted.

14 changes: 9 additions & 5 deletions backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
"devDependencies": {
"@types/cors": "^2.8.12",
"@types/express": "^4.17.13",
"@types/redis": "^4.0.11",
"@types/swagger-jsdoc": "^6.0.1",
"@types/swagger-ui-express": "^4.1.3",
"@types/yamljs": "^0.2.31",
Expand All @@ -19,12 +18,12 @@
"eslint-plugin-jsx-a11y": "^6.5.1",
"eslint-plugin-react": "^7.28.0",
"eslint-plugin-react-hooks": "^4.3.0",
"nodemon": "^2.0.15",
"ts-node": "^10.4.0",
"ts-node": "^10.9.1",
"ts-node-dev": "^2.0.0",
"typescript": "^4.5.5"
},
"scripts": {
"dev": "nodemon",
"dev": "ts-node-dev --respawn --transpile-only --ignore-watch node_modules src/index.ts",
"build": "tsc && node ./"
},
"keywords": [],
Expand All @@ -37,19 +36,24 @@
"@types/ioredis": "^4.28.8",
"@types/jsonwebtoken": "^8.5.8",
"@types/node": "^17.0.10",
"@zilliz/milvus2-sdk-node": "^2.2.7",
"add": "^2.0.6",
"bcrypt": "^5.0.1",
"body-parser": "^1.19.1",
"commonjs": "^0.0.1",
"cors": "^2.8.5",
"dotenv": "^14.2.0",
"express": "^4.17.2",
"fastest-levenshtein": "^1.0.16",
"ioredis": "^4.28.5",
"jsonwebtoken": "^8.5.1",
"mongoose": "^6.1.7",
"openai": "^3.2.1",
"rate-limiter-flexible": "^2.3.6",
"supertokens-node": "^12.1.3",
"swagger-jsdoc": "^6.2.1",
"swagger-ui-express": "^4.5.0",
"yamljs": "^0.3.0"
"yamljs": "^0.3.0",
"yarn": "^1.22.19"
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Client } from '@elastic/elasticsearch';

if (!process.env.ELASTICSEARCH_URL) {
throw new Error('ELASTICSEARCH_URL is not defined');
if (!process.env.ELASTICSEARCH_URL && !process.env.ELASTICSEARCH_CLOUD_ID) {
throw new Error('ELASTICSEARCH_URL is not defined or ELASTICSEARCH_CLOUD_ID is not defined');
}

if (!process.env.ELASTICSEARCH_PASSWORD) {
Expand All @@ -12,8 +12,18 @@ if (!process.env.ELASTICSEARCH_USERNAME) {
throw new Error('ELASTICSEARCH_USERNAME is not defined');
}

const URLConnection = process.env.ELASTICSEARCH_URL !== undefined
? {
node: process.env.ELASTICSEARCH_URL as string,
}
: {
cloud: {
id: process.env.ELASTICSEARCH_CLOUD_ID as string,
}
}

const client = new Client({
node: process.env.ELASTICSEARCH_URL,
...URLConnection,
auth: {
password: process.env.ELASTICSEARCH_PASSWORD,
username: process.env.ELASTICSEARCH_USERNAME,
Expand Down
76 changes: 76 additions & 0 deletions backend/src/helpers/clients/MilvusClient.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import { MilvusClient, DataType } from "@zilliz/milvus2-sdk-node";

if (!process.env.MILVUS_URL) {
throw new Error('MILVUS_URL is not defined');
}

const EMBEDDING_DIM = 1536;

const BLOCK_FIELDS = [
{
name: 'block_id',
description: 'The ID of the block (Same as the ID of the block in mongoDB)',
data_type: DataType.VarChar,
max_length: 24,
is_primary_key: true,
},
{
name: 'page_id',
description: 'The ID of the page that the block belongs to',
max_length: 24,
data_type: DataType.VarChar,
},
{
name: 'embedding',
description: 'The embedding of the block (Generated by OpenAI)',
data_type: DataType.FloatVector,
dim: EMBEDDING_DIM,
},
{
name: 'content',
description: 'The content of the block',
data_type: DataType.VarChar,
max_length: 1000,
},
{
name: 'context',
description: 'The context of the block',
data_type: DataType.VarChar,
max_length: (24 + 2) * 11 + 2,
}
]

const milvusClient = new MilvusClient(
process.env.MILVUS_URL,
true,
process.env.MILVUS_USERNAME,
process.env.MILVUS_PASSWORD
);

(async () => {
const doesCollectionExist = await milvusClient.hasCollection({
collection_name: 'blocks',
});

if (doesCollectionExist.status.error_code !== 'Success') {
throw new Error(doesCollectionExist.status.reason);
}

if (doesCollectionExist.value) return;

await milvusClient.createCollection({
collection_name: 'blocks',
description: 'Collection for storing block embeddings',
fields: BLOCK_FIELDS,
});

await milvusClient.createIndex({
collection_name: 'blocks',
field_name: 'embedding',
index_type: 'AUTOINDEX',
index_name: 'embedding_index',
metric_type: 'L2',
});
})();

export default milvusClient;
14 changes: 14 additions & 0 deletions backend/src/helpers/clients/OpenAIClient.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { Configuration, OpenAIApi } from 'openai';

if (!process.env.OPENAI_API_KEY) {
throw new Error('OPENAI_API_KEY is not defined');
}

const configuration = new Configuration({
apiKey: process.env.OPENAI_API_KEY,
});

const OpenAIClient = new OpenAIApi(configuration);

export default OpenAIClient;

2 changes: 1 addition & 1 deletion backend/src/helpers/deletePage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import PageMapModel from '../models/pageMap';
import PageModel from '../models/pageModel';
import PageTreeModel from '../models/pageTreeModel';
import mongoose from 'mongoose';
import ElasticSearchClient from './search/ElasticSearchClient';
import ElasticSearchClient from './clients/ElasticSearchClient';

interface pageTreeType {
_id: string,
Expand Down
Loading

0 comments on commit c2849c1

Please sign in to comment.