Skip to content

Commit 56ce1ed

Browse files
authored
Update utils.py
+ Support for local LLM models
1 parent 8f95ec6 commit 56ce1ed

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

utils.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import docx
33
import json
44
from sentence_transformers import SentenceTransformer
5+
from ctransformers import AutoModelForCausalLM
56
from openai import OpenAI
67
import datetime
78

@@ -32,15 +33,21 @@ def load_settings():
3233
settings = json.load(f)
3334
OPENAI_API_KEY = settings.get("OPENAI_API_KEY", "")
3435
model_type = settings.get("model_type", "small")
36+
llm_model = settings.get("llm_model", "OpenAI api")
3537
except FileNotFoundError:
3638
OPENAI_API_KEY = ""
3739
model_type = "small"
38-
return([OPENAI_API_KEY, model_type])
40+
llm_model = "OpenAI api"
41+
return([OPENAI_API_KEY, model_type, llm_model])
3942

40-
def initialize_openai_and_embedding(OPENAI_API_KEY, model_type):
43+
def initialize_openai_and_embedding(OPENAI_API_KEY, model_type, llm_model):
4144

42-
if OPENAI_API_KEY:
45+
if OPENAI_API_KEY and llm_model == "OpenAI api":
4346
client = OpenAI(api_key=OPENAI_API_KEY)
47+
elif llm_model == "Tinyllama(Q5)":
48+
client = AutoModelForCausalLM.from_pretrained("TheBloke/TinyLlama-1.1B-Chat-v1.0-GGUF", model_file="tinyllama-1.1b-chat-v1.0.Q5_K_M.gguf", model_type="llama", gpu_layers=0)
49+
elif llm_model == "Llama2-7B(Q4)":
50+
client = AutoModelForCausalLM.from_pretrained("TheBloke/Llama-2-7B-Chat-GGUF", model_file=" llama-2-7b-chat.Q4_K_M.gguf", model_type="llama", gpu_layers=0)
4451
else:
4552
client = None
4653

0 commit comments

Comments
 (0)