added ctransformers
Browse files- .env.example +4 -0
- Makefile +2 -2
- app_modules/llm_loader.py +16 -1
- app_modules/utils.py +3 -0
- requirements_extra.txt +1 -0
.env.example
CHANGED
@@ -2,6 +2,7 @@
|
|
2 |
# LLM_MODEL_TYPE=gpt4all-j
|
3 |
# LLM_MODEL_TYPE=gpt4all
|
4 |
# LLM_MODEL_TYPE=llamacpp
|
|
|
5 |
# LLM_MODEL_TYPE=huggingface
|
6 |
# LLM_MODEL_TYPE=mosaicml
|
7 |
# LLM_MODEL_TYPE=stablelm
|
@@ -71,6 +72,9 @@ GPT4ALL_DOWNLOAD_LINK=https://gpt4all.io/models/ggml-nous-gpt4-vicuna-13b.bin
|
|
71 |
LLAMACPP_MODEL_PATH="../models/llama-2-7b-chat.ggmlv3.q4_K_M.bin"
|
72 |
LLAMACPP_DOWNLOAD_LINK=https://huggingface.co/TheBloke/Llama-2-7B-Chat-GGML/resolve/main/llama-2-7b-chat.ggmlv3.q4_K_M.bin
|
73 |
|
|
|
|
|
|
|
74 |
# Index for AI Books PDF files - chunk_size=1024 chunk_overlap=512
|
75 |
# CHROMADB_INDEX_PATH="./data/chromadb_1024_512/"
|
76 |
FAISS_INDEX_PATH="./data/ai_books/"
|
|
|
2 |
# LLM_MODEL_TYPE=gpt4all-j
|
3 |
# LLM_MODEL_TYPE=gpt4all
|
4 |
# LLM_MODEL_TYPE=llamacpp
|
5 |
+
# LLM_MODEL_TYPE=ctransformers
|
6 |
# LLM_MODEL_TYPE=huggingface
|
7 |
# LLM_MODEL_TYPE=mosaicml
|
8 |
# LLM_MODEL_TYPE=stablelm
|
|
|
72 |
LLAMACPP_MODEL_PATH="../models/llama-2-7b-chat.ggmlv3.q4_K_M.bin"
|
73 |
LLAMACPP_DOWNLOAD_LINK=https://huggingface.co/TheBloke/Llama-2-7B-Chat-GGML/resolve/main/llama-2-7b-chat.ggmlv3.q4_K_M.bin
|
74 |
|
75 |
+
CTRANSFORMERS_MODEL_PATH="../models/llama-2-7b-chat.ggmlv3.q4_K_M.bin"
|
76 |
+
CTRANSFORMERS_DOWNLOAD_LINK=https://huggingface.co/TheBloke/Llama-2-7B-Chat-GGML/resolve/main/llama-2-7b-chat.ggmlv3.q4_K_M.bin
|
77 |
+
|
78 |
# Index for AI Books PDF files - chunk_size=1024 chunk_overlap=512
|
79 |
# CHROMADB_INDEX_PATH="./data/chromadb_1024_512/"
|
80 |
FAISS_INDEX_PATH="./data/ai_books/"
|
Makefile
CHANGED
@@ -55,9 +55,9 @@ install:
|
|
55 |
|
56 |
install-extra:
|
57 |
CXX=g++-11 CC=gcc-11 pip install -U -r requirements_extra.txt
|
58 |
-
pip show
|
59 |
|
60 |
install-extra-mac:
|
61 |
# brew install llvm libomp
|
62 |
CXX=/usr/local/opt/llvm/bin/clang++ CC=/usr/local/opt/llvm/bin/clang pip install -U -r requirements_extra.txt
|
63 |
-
pip show
|
|
|
55 |
|
56 |
install-extra:
|
57 |
CXX=g++-11 CC=gcc-11 pip install -U -r requirements_extra.txt
|
58 |
+
pip show llama-cpp-python ctransformers
|
59 |
|
60 |
install-extra-mac:
|
61 |
# brew install llvm libomp
|
62 |
CXX=/usr/local/opt/llvm/bin/clang++ CC=/usr/local/opt/llvm/bin/clang pip install -U -r requirements_extra.txt
|
63 |
+
pip show llama-cpp-python ctransformers
|
app_modules/llm_loader.py
CHANGED
@@ -9,7 +9,13 @@ from langchain import HuggingFaceTextGenInference
|
|
9 |
from langchain.callbacks.base import BaseCallbackHandler
|
10 |
from langchain.callbacks.streaming_stdout import StreamingStdOutCallbackHandler
|
11 |
from langchain.chat_models import ChatOpenAI
|
12 |
-
from langchain.llms import
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
from langchain.schema import LLMResult
|
14 |
from transformers import (
|
15 |
AutoConfig,
|
@@ -189,6 +195,15 @@ class LLMLoader:
|
|
189 |
verbose=True,
|
190 |
use_mlock=True,
|
191 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
192 |
elif self.llm_model_type == "hftgi":
|
193 |
HFTGI_SERVER_URL = os.environ.get("HFTGI_SERVER_URL")
|
194 |
self.max_tokens_limit = 4096
|
|
|
9 |
from langchain.callbacks.base import BaseCallbackHandler
|
10 |
from langchain.callbacks.streaming_stdout import StreamingStdOutCallbackHandler
|
11 |
from langchain.chat_models import ChatOpenAI
|
12 |
+
from langchain.llms import (
|
13 |
+
CTransformers,
|
14 |
+
GPT4All,
|
15 |
+
HuggingFacePipeline,
|
16 |
+
LlamaCpp,
|
17 |
+
OpenLLM,
|
18 |
+
)
|
19 |
from langchain.schema import LLMResult
|
20 |
from transformers import (
|
21 |
AutoConfig,
|
|
|
195 |
verbose=True,
|
196 |
use_mlock=True,
|
197 |
)
|
198 |
+
elif self.llm_model_type == "ctransformers":
|
199 |
+
MODEL_PATH = ensure_model_is_downloaded(self.llm_model_type)
|
200 |
+
config = {
|
201 |
+
"max_new_tokens": self.max_tokens_limit,
|
202 |
+
"repetition_penalty": 1.1,
|
203 |
+
}
|
204 |
+
self.llm = CTransformers(
|
205 |
+
model=MODEL_PATH, model_type="llama", config=config
|
206 |
+
)
|
207 |
elif self.llm_model_type == "hftgi":
|
208 |
HFTGI_SERVER_URL = os.environ.get("HFTGI_SERVER_URL")
|
209 |
self.max_tokens_limit = 4096
|
app_modules/utils.py
CHANGED
@@ -132,6 +132,9 @@ def ensure_model_is_downloaded(llm_model_type):
|
|
132 |
elif llm_model_type == "llamacpp":
|
133 |
local_path = os.environ.get("LLAMACPP_MODEL_PATH")
|
134 |
url = os.environ.get("LLAMACPP_DOWNLOAD_LINK")
|
|
|
|
|
|
|
135 |
else:
|
136 |
raise ValueError(f"wrong model typle: {llm_model_type}")
|
137 |
|
|
|
132 |
elif llm_model_type == "llamacpp":
|
133 |
local_path = os.environ.get("LLAMACPP_MODEL_PATH")
|
134 |
url = os.environ.get("LLAMACPP_DOWNLOAD_LINK")
|
135 |
+
elif llm_model_type == "ctransformers":
|
136 |
+
local_path = os.environ.get("CTRANSFORMERS_MODEL_PATH")
|
137 |
+
url = os.environ.get("CTRANSFORMERS_DOWNLOAD_LINK")
|
138 |
else:
|
139 |
raise ValueError(f"wrong model typle: {llm_model_type}")
|
140 |
|
requirements_extra.txt
CHANGED
@@ -1,3 +1,4 @@
|
|
1 |
llama-cpp-python
|
2 |
pyllamacpp
|
3 |
chromadb
|
|
|
|
1 |
llama-cpp-python
|
2 |
pyllamacpp
|
3 |
chromadb
|
4 |
+
ctransformers
|