Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Basic Level Support for Linux #17

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,9 @@ mpnet/
baai/
whisper
espeak-ng-data

## LINUX IGNORE
env/
__pycache__/
*.log
*.out
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,16 @@ Now python should be setup and running! However, there is still a few more steps

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)

## Linux Installation
```bash
$ chmod +x setup_python.sh
$ ./setup_python.sh
```
The above command will check if python is installed on your system and start the setup.
Once the setup is done, configure all the models by specifying their features in the config file located at `llm/config.ini`

Finally, run `npm start`

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 :)


Expand Down
2 changes: 2 additions & 0 deletions llm/config.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[EMBEDDING MODEL CONFIG]
MODEL_NAME=sentence-transformers/all-mpnet-base-v2
8 changes: 8 additions & 0 deletions llm/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
torch
langchain-community
faiss-cpu
huggingface_hub
llama-cpp-python -C cmake.args="-DLLAMA_BLAS=ON;-DLLAMA_BLAS_VENDOR=OpenBLAS;-DLLAMA_CUDA=ON"
pypdf
unstructured
docx2txt
51 changes: 26 additions & 25 deletions llm/scripts/bigdot.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
from langchain.prompts import PromptTemplate
from langchain.chains import LLMChain
from langchain.llms import LlamaCpp
from langchain.memory import ConversationBufferWindowMemory
from langchain_core.prompts.prompt import PromptTemplate
from langchain.chains.llm import LLMChain
from langchain_community.llms.llamacpp import LlamaCpp
from langchain.memory.buffer_window import ConversationBufferWindowMemory
import sys
import json
import os


def read_config(config_path):
try:
with open(config_path, 'r') as file:
with open(config_path, "r") as file:
config = json.load(file)
return config
except FileNotFoundError:
Expand All @@ -18,6 +19,7 @@ def read_config(config_path):
print("Error decoding JSON from configuration file.")
return {}


if __name__ == "__main__":
if len(sys.argv) > 1:

Expand All @@ -26,24 +28,27 @@ def read_config(config_path):
folder_name = "Dot-Data"
folder_path = os.path.join(documents_path, folder_name)
if not os.path.exists(folder_path):
print('LLM NOT FOUND!')
print("LLM NOT FOUND!")
os.makedirs(folder_path)
model_path = os.path.join(folder_path, "Phi-3-mini-4k-instruct-q4.gguf")

config_path = sys.argv[1].strip('"') # Remove any surrounding quotes
config = read_config(config_path)
#print("Current Configuration:", config)
# print("Current Configuration:", config)

# Setup configuration with defaults in case some settings are missing
n_gpu_layers = -1 # Metal set to 1 is typically enough for Apple Silicon
n_batch = config.get('n_batch', 256)
max_tokens = config.get('max_tokens', 500)
temperature = config.get('big_dot_temperature', 0.7)
n_ctx = config.get('n_ctx', 4000)
initial_prompt = config.get('big_dot_prompt', "You are called Dot, You are a helpful and honest assistant.")
if 'ggufFilePath' in config and config['ggufFilePath'] is None:
del config['ggufFilePath'] # Removes the key if it's explicitly None
llm_model = config.get('ggufFilePath', model_path)
n_batch = config.get("n_batch", 256)
max_tokens = config.get("max_tokens", 500)
temperature = config.get("big_dot_temperature", 0.7)
n_ctx = config.get("n_ctx", 4000)
initial_prompt = config.get(
"big_dot_prompt",
"You are called Dot, You are a helpful and honest assistant.",
)
if "ggufFilePath" in config and config["ggufFilePath"] is None:
del config["ggufFilePath"] # Removes the key if it's explicitly None
llm_model = config.get("ggufFilePath", model_path)

# Initialize the LLM with the configuration
llm = LlamaCpp(
Expand All @@ -67,12 +72,7 @@ def read_config(config_path):
Response:"""
prompt = PromptTemplate.from_template(template)
memory = ConversationBufferWindowMemory(memory_key="chat_history", k=2)
conversation = LLMChain(
llm=llm,
prompt=prompt,
verbose=False,
memory=memory
)
conversation = LLMChain(llm=llm, prompt=prompt, verbose=False, memory=memory)

def send_response(response):
response_json = json.dumps({"result": response})
Expand All @@ -85,9 +85,10 @@ def send_response(response):
if not user_input:
break

result = conversation({"question": user_input})['text']
result = conversation({"question": user_input})["text"]
max_chunk_length = 1000 # Define max length for output chunks
chunks = [result[i:i + max_chunk_length] for i in range(0, len(result), max_chunk_length)]
chunks = [
result[i : i + max_chunk_length]
for i in range(0, len(result), max_chunk_length)
]
send_response(chunks)


Loading