|
2 | 2 | import docx |
3 | 3 | import json |
4 | 4 | from sentence_transformers import SentenceTransformer |
| 5 | +from ctransformers import AutoModelForCausalLM |
5 | 6 | from openai import OpenAI |
6 | 7 | import datetime |
7 | 8 |
|
@@ -32,15 +33,21 @@ def load_settings(): |
32 | 33 | settings = json.load(f) |
33 | 34 | OPENAI_API_KEY = settings.get("OPENAI_API_KEY", "") |
34 | 35 | model_type = settings.get("model_type", "small") |
| 36 | + llm_model = settings.get("llm_model", "OpenAI api") |
35 | 37 | except FileNotFoundError: |
36 | 38 | OPENAI_API_KEY = "" |
37 | 39 | model_type = "small" |
38 | | - return([OPENAI_API_KEY, model_type]) |
| 40 | + llm_model = "OpenAI api" |
| 41 | + return([OPENAI_API_KEY, model_type, llm_model]) |
39 | 42 |
|
40 | | -def initialize_openai_and_embedding(OPENAI_API_KEY, model_type): |
| 43 | +def initialize_openai_and_embedding(OPENAI_API_KEY, model_type, llm_model): |
41 | 44 |
|
42 | | - if OPENAI_API_KEY: |
| 45 | + if OPENAI_API_KEY and llm_model == "OpenAI api": |
43 | 46 | 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) |
44 | 51 | else: |
45 | 52 | client = None |
46 | 53 |
|
|
0 commit comments