Skip to content

Commit 045a66a

Browse files
committed
Implemented features
-Dot now remembers the last loaded directory -Dot now is not installed with a packaged version of mistral but rather installs it upon first opening the app -Improved the pdf and file dispalying
1 parent a9efff7 commit 045a66a

29 files changed

+6368
-29028
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ src/.env
88
dist
99
.DS_Store
1010
mpnet/
11+
baai/

README.md

Lines changed: 61 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,61 @@
1-
# HELLO!
2-
3-
![ezgif-4-b96c0b5548](https://github.com/alexpinel/Dot/assets/93524949/e5983c61-d59c-45ac-86f6-9d62cffaf37b)
4-
5-
This is Dot, a standalone open source app meant for easy use of local LLMs and RAG in particular to interact with documents and files similarly to Nvidia's Chat with RTX. Dot itself is completely standalone and is packaged with all dependencies including a copy of Mistral 7B, this is to ensure the app is as accessible as possible and no prior knowledge of programming or local LLMs is required to use it. You can install the app (available for Apple Silicon and Windows) here: [Dot website ](https://dotapp.uk/)
6-
7-
### What does it do?
8-
9-
Dot can be used to load multiple documents into an llm and interact with them in a fully local environment through Retrieval Augmented Generation (RAG), supported documents are: pdf, docx, pptx, xlsx, and markdown. Apart from RAG, users can also switch to Big Dot for any interactions unrelated to their documents similarly to ChatGPT.
10-
11-
12-
https://github.com/alexpinel/Dot/assets/93524949/807fb58c-40e0-407e-afb3-a3813477ce9e
13-
14-
15-
16-
### How does it work?
17-
18-
Dot is built with Electron JS, but its main functionalities come from a bundled install of Python that contains all libraries and necessary files. A multitude of libraries are used to make everything work, but perhaps the most important to be aware of are: llama.cpp to run the LLM, FAISS to create local vector stores, and Langchain & Huggingface to setup the conversation chains and embedding process.
19-
20-
### Install
21-
22-
You can either install the packaged app in the [Dot website ](https://dotapp.uk/) or can set up the project for development, to do so follow these steps:
23-
24-
- Clone the repository `$ https://github.com/alexpinel/Dot.git`
25-
- Install Node js and then run `npm install` inside the project repository, you can run `npm install --force` if you face any issues at this stage
26-
27-
Now, it is time to add a full python bundle to the app. The purpose of this is to create a distributable environment with all necessary libraries, if you only plan on using Dot from the console you might not need to follow this particular step but then make sure to replace the python path locations specified in `src/index.js`. Creating the python bundle is covered in detail here: [https://til.simonwillison.net/electron/python-inside-electron](https://til.simonwillison.net/electron/python-inside-electron) , the bundles can also be installed from here: [https://github.com/indygreg/python-build-standalone/releases/tag/20240224](https://github.com/indygreg/python-build-standalone/releases/tag/20240224)
28-
29-
Having created the bundle, please rename it to 'python' and place it inside the `llm` directory. It is now time to get all necessary libraries, keep in mind that running a simple `pip install` will not work without specifying the actual path of the bundle so use this instead: `path/to/python/.bin/or/.exe -m pip install`
30-
31-
Required python libraries:
32-
- pytorch [link](https://pytorch.org/get-started/locally/) (CPU version recommended as it is lighter than GPU)
33-
- langchain [link](https://python.langchain.com/docs/get_started/quickstart)
34-
- FAISS [link](https://python.langchain.com/docs/integrations/vectorstores/faiss)
35-
- HuggingFace [link](https://python.langchain.com/docs/integrations/platforms/huggingface)
36-
- llama.cpp [link](https://github.com/abetlen/llama-cpp-python) (Use CUDA implementation if you have an Nvidia GPU!)
37-
- pypdf [link](https://python.langchain.com/docs/modules/data_connection/document_loaders/pdf)
38-
- docx2txt [link](https://python.langchain.com/docs/integrations/document_loaders/microsoft_word)
39-
- Unstructured [link](https://github.com/Unstructured-IO/unstructured) (Use `pip install "unstructured[pptx, md, xlsx]` for the file formats)
40-
41-
Now python should be setup and running! However, there is still a few more steps left, now is the time to add the final magic to Dot! First, create a folder inside the `llm` directory and name it `mpnet`, there you will need to install sentence-transformers to use for the document embeddings, fetch all the files from the following link and place them inside the new folder: [sentence-transformers/all-mpnet-base-v2](https://huggingface.co/sentence-transformers/all-mpnet-base-v2/tree/main)
42-
43-
Finally, download the Mistral 7B LLM from the following link and place it inside the `llm/scripts` directory alongside the python scripts used by Dot: [TheBloke/Mistral-7B-Instruct-v0.2-GGUF](https://huggingface.co/TheBloke/Mistral-7B-Instruct-v0.2-GGUF/blob/main/mistral-7b-instruct-v0.2.Q4_K_M.gguf)
44-
45-
That's it! If you follow these steps you should be able to get it all running, please let me know if you are facing any issues :)
46-
47-
### Future features I'd like to add:
48-
49-
- Linux support
50-
- Ability to choose LLM
51-
- Image support would be cool
52-
- Increased awarnes of documents apart from merely their content
53-
- Loading individual files instead of selecting a folder (This is really needed, some users get confused by this and I cannot blame them at all)
54-
- Increased security considerations, after all this is the whole point of using a local LLM
55-
- Support for more docs
56-
- Storing file databases, allowing users to quickly switch between groups of files without having to load them all again
57-
- idk, will find out along the way
58-
59-
# Want to help?
60-
61-
Please do! I am a busy student working on this as a side project so help is more than welcome!
62-
63-
1+
# HELLO!
2+
3+
![ezgif-4-b96c0b5548](https://github.com/alexpinel/Dot/assets/93524949/e5983c61-d59c-45ac-86f6-9d62cffaf37b)
4+
5+
This is Dot, a standalone open source app meant for easy use of local LLMs and RAG in particular to interact with documents and files similarly to Nvidia's Chat with RTX. Dot itself is completely standalone and is packaged with all dependencies including a copy of Mistral 7B, this is to ensure the app is as accessible as possible and no prior knowledge of programming or local LLMs is required to use it. You can install the app (available for Apple Silicon and Windows) here: [Dot website ](https://dotapp.uk/)
6+
7+
### What does it do?
8+
9+
Dot can be used to load multiple documents into an llm and interact with them in a fully local environment through Retrieval Augmented Generation (RAG), supported documents are: pdf, docx, pptx, xlsx, and markdown. Apart from RAG, users can also switch to Big Dot for any interactions unrelated to their documents similarly to ChatGPT.
10+
11+
12+
https://github.com/alexpinel/Dot/assets/93524949/807fb58c-40e0-407e-afb3-a3813477ce9e
13+
14+
15+
16+
### How does it work?
17+
18+
Dot is built with Electron JS, but its main functionalities come from a bundled install of Python that contains all libraries and necessary files. A multitude of libraries are used to make everything work, but perhaps the most important to be aware of are: llama.cpp to run the LLM, FAISS to create local vector stores, and Langchain & Huggingface to setup the conversation chains and embedding process.
19+
20+
### Install
21+
22+
You can either install the packaged app in the [Dot website ](https://dotapp.uk/) or can set up the project for development, to do so follow these steps:
23+
24+
- Clone the repository `$ https://github.com/alexpinel/Dot.git`
25+
- Install Node js and then run `npm install` inside the project repository, you can run `npm install --force` if you face any issues at this stage
26+
27+
Now, it is time to add a full python bundle to the app. The purpose of this is to create a distributable environment with all necessary libraries, if you only plan on using Dot from the console you might not need to follow this particular step but then make sure to replace the python path locations specified in `src/index.js`. Creating the python bundle is covered in detail here: [https://til.simonwillison.net/electron/python-inside-electron](https://til.simonwillison.net/electron/python-inside-electron) , the bundles can also be installed from here: [https://github.com/indygreg/python-build-standalone/releases/tag/20240224](https://github.com/indygreg/python-build-standalone/releases/tag/20240224)
28+
29+
Having created the bundle, please rename it to 'python' and place it inside the `llm` directory. It is now time to get all necessary libraries, keep in mind that running a simple `pip install` will not work without specifying the actual path of the bundle so use this instead: `path/to/python/.bin/or/.exe -m pip install`
30+
31+
Required python libraries:
32+
- pytorch [link](https://pytorch.org/get-started/locally/) (CPU version recommended as it is lighter than GPU)
33+
- langchain [link](https://python.langchain.com/docs/get_started/quickstart)
34+
- FAISS [link](https://python.langchain.com/docs/integrations/vectorstores/faiss)
35+
- HuggingFace [link](https://python.langchain.com/docs/integrations/platforms/huggingface)
36+
- llama.cpp [link](https://github.com/abetlen/llama-cpp-python) (Use CUDA implementation if you have an Nvidia GPU!)
37+
- pypdf [link](https://python.langchain.com/docs/modules/data_connection/document_loaders/pdf)
38+
- docx2txt [link](https://python.langchain.com/docs/integrations/document_loaders/microsoft_word)
39+
- Unstructured [link](https://github.com/Unstructured-IO/unstructured) (Use `pip install "unstructured[pptx, md, xlsx]` for the file formats)
40+
41+
Now python should be setup and running! However, there is still a few more steps left, now is the time to add the final magic to Dot! First, create a folder inside the `llm` directory and name it `mpnet`, there you will need to install sentence-transformers to use for the document embeddings, fetch all the files from the following link and place them inside the new folder: [sentence-transformers/all-mpnet-base-v2](https://huggingface.co/sentence-transformers/all-mpnet-base-v2/tree/main)
42+
43+
Finally, download the Mistral 7B LLM from the following link and place it inside the `llm/scripts` directory alongside the python scripts used by Dot: [TheBloke/Mistral-7B-Instruct-v0.2-GGUF](https://huggingface.co/TheBloke/Mistral-7B-Instruct-v0.2-GGUF/blob/main/mistral-7b-instruct-v0.2.Q4_K_M.gguf)
44+
45+
That's it! If you follow these steps you should be able to get it all running, please let me know if you are facing any issues :)
46+
47+
### Future features I'd like to add:
48+
49+
- Linux support
50+
- Ability to choose LLM
51+
- Image support would be cool
52+
- Increased awarnes of documents apart from merely their content
53+
- Loading individual files instead of selecting a folder (This is really needed, some users get confused by this and I cannot blame them at all)
54+
- Increased security considerations, after all this is the whole point of using a local LLM
55+
- Support for more docs
56+
- Storing file databases, allowing users to quickly switch between groups of files without having to load them all again
57+
- idk, will find out along the way
58+
59+
# Want to help?
60+
61+
Please do! I am a busy student working on this as a side project so help is more than welcome!

llm/scripts/bigdot.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,26 @@
1010

1111

1212
n_gpu_layers = 1 # Metal set to 1 is enough.
13-
n_batch = 512 # Should be between 1 and n_ctx, consider the amount of RAM of your Apple Silicon Chip.
13+
n_batch = 256 # Should be between 1 and n_ctx, consider the amount of RAM of your Apple Silicon Chip.
1414

1515

16-
# Find the current script's directory
17-
script_dir = os.path.dirname(__file__)
16+
# Specify the desktop path
17+
documents_path = os.path.join(os.path.expanduser("~"), "Documents")
18+
19+
# Specify the folder name
20+
folder_name = "Dot-data"
21+
22+
# Combine the desktop path and folder name
23+
folder_path = os.path.join(documents_path, folder_name)
24+
25+
# Create the folder if it doesn't exist
26+
if not os.path.exists(folder_path):
27+
print('LLM NOT FOUND!')
28+
os.makedirs(folder_path)
1829

1930
# Construct the relative path
2031
relative_model_path = "mistral-7b-instruct-v0.2.Q4_K_M.gguf"
21-
model_path = os.path.join(script_dir, relative_model_path)
32+
model_path = os.path.join(folder_path, relative_model_path)
2233

2334

2435
llm = LlamaCpp(

llm/scripts/docdot.py

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,39 +14,40 @@
1414

1515

1616
# Specify the desktop path
17-
desktop_path = os.path.join(os.path.expanduser("~"), "Documents")
17+
documents_path = os.path.join(os.path.expanduser("~"), "Documents")
1818

1919
# Specify the folder name
20-
folder_name = "Dot-data"
20+
folder_name = "Dot-Data"
2121

2222
# Combine the desktop path and folder name
23-
folder_path = os.path.join(desktop_path, folder_name)
23+
folder_path = os.path.join(documents_path, folder_name)
2424

2525
# Create the folder if it doesn't exist
2626
if not os.path.exists(folder_path):
27+
print('LLM NOT FOUND!')
2728
os.makedirs(folder_path)
2829

2930

3031

3132

3233
current_directory = os.path.dirname(os.path.realpath(__file__))
33-
model_directory = os.path.join(current_directory, '..', 'mpnet')
34+
model_directory = os.path.join(current_directory, '..', 'baai')
3435

3536
#print("Model Directory:", os.path.abspath(model_directory))
3637

3738
### LOAD EMBEDDING SETTINGS
3839
embeddings=HuggingFaceEmbeddings(model_name=model_directory, model_kwargs={'device':'mps'}) # SET TO 'cpu' for PC
3940
vector_store = FAISS.load_local(os.path.join(folder_path, "Dot-data"), embeddings)
4041
n_gpu_layers = 1 # Metal set to 1 is enough.
41-
n_batch = 512 # Should be between 1 and n_ctx, consider the amount of RAM of your Apple Silicon Chip.
42+
n_batch = 256 # Should be between 1 and n_ctx, consider the amount of RAM of your Apple Silicon Chip.
4243

4344

4445
# Find the current script's directory
4546
script_dir = os.path.dirname(__file__)
4647

4748
# Construct the relative path
4849
relative_model_path = "mistral-7b-instruct-v0.2.Q4_K_M.gguf"
49-
model_path = os.path.join(script_dir, relative_model_path)
50+
model_path = os.path.join(folder_path, relative_model_path)
5051

5152

5253
llm = LlamaCpp(
@@ -100,15 +101,16 @@ def generate_prompt(prompt: str, system_prompt: str = DEFAULT_SYSTEM_PROMPT) ->
100101
def format_response(dictionary):
101102
"""
102103
Formats the response dictionary to:
103-
- Print metadata.
104+
- Print metadata for each document.
104105
- Embed an iframe for PDF documents, attempting to open it at a specified page.
105106
- Display page_content text for Word, Excel, or PowerPoint documents.
107+
- Display the overall result after the document details.
106108
Assumes each document in source_documents is an instance of a Document class.
107109
"""
108-
formatted_result = dictionary["result"]
110+
# Correctly define source_documents from the dictionary
109111
source_documents = dictionary["source_documents"]
110112

111-
sources = "\n\n---\n\n### Source Documents:\n"
113+
sources = "### Source Documents:\n"
112114
for doc in source_documents:
113115
# Safely get the 'source' and 'page' from metadata, default if not found
114116
source_path = doc.metadata.get("source", "Source path not available.")
@@ -131,7 +133,13 @@ def format_response(dictionary):
131133
page_content_text = doc.page_content.replace('\n', ' ') if doc.page_content else "Page content not available."
132134
sources += f"\n\n{metadata_info}\n{page_content_text}\n\n"
133135

134-
return formatted_result + sources
136+
# Now appending the formatted result at the end
137+
formatted_result = dictionary["result"]
138+
complete_response = sources + "\n\n---\n\n### Result:\n" + formatted_result
139+
140+
return complete_response
141+
142+
135143

136144

137145

llm/scripts/embeddings.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
def embeddings(chosen_directory):
1313

1414
current_directory = os.path.dirname(os.path.realpath(__file__))
15-
model_directory = os.path.join(current_directory, '..', 'mpnet')
15+
model_directory = os.path.join(current_directory, '..', 'baai')
1616

1717
print("Model Directory:", os.path.abspath(model_directory))
1818

@@ -31,7 +31,7 @@ def embeddings(chosen_directory):
3131
desktop_path = os.path.join(os.path.expanduser("~"), "Documents")
3232

3333
# Specify the folder name
34-
folder_name = "Dot-data"
34+
folder_name = "Dot-Data"
3535

3636
# Combine the desktop path and folder name
3737
folder_path = os.path.join(desktop_path, folder_name)

0 commit comments

Comments
 (0)