Spaces:
Build error
Build error
Update rag_agent.py
Browse files- rag_agent.py +17 -9
rag_agent.py
CHANGED
|
@@ -5,7 +5,7 @@ from llama_index.llms.huggingface import HuggingFaceLLM
|
|
| 5 |
from llama_index.embeddings.huggingface import HuggingFaceEmbedding
|
| 6 |
from llama_index.core.tools import QueryEngineTool, ToolMetadata
|
| 7 |
from transformers import AutoTokenizer, AutoModelForCausalLM
|
| 8 |
-
|
| 9 |
|
| 10 |
import os
|
| 11 |
from huggingface_hub import login
|
|
@@ -22,15 +22,23 @@ login(token=hf_token)
|
|
| 22 |
Settings.embed_model = HuggingFaceEmbedding(model_name="sentence-transformers/all-MiniLM-L6-v2")
|
| 23 |
|
| 24 |
# ==== 2. Load Hugging Face LLM (Locally Installed or Remote Hosted) ====
|
| 25 |
-
llm = HuggingFaceLLM(
|
| 26 |
-
model_name="unsloth/Mistral-Small-3.1-24B-Instruct-2503-GGUF", # You must have access!
|
| 27 |
-
tokenizer_name="unsloth/Mistral-Small-3.1-24B-Instruct-2503-GGUF",
|
| 28 |
-
context_window=2048,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
max_new_tokens=512,
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
)
|
| 35 |
|
| 36 |
Settings.llm = llm # Apply to global settings
|
|
|
|
| 5 |
from llama_index.embeddings.huggingface import HuggingFaceEmbedding
|
| 6 |
from llama_index.core.tools import QueryEngineTool, ToolMetadata
|
| 7 |
from transformers import AutoTokenizer, AutoModelForCausalLM
|
| 8 |
+
from llama_index.llms.llama_cpp import LlamaCPP
|
| 9 |
|
| 10 |
import os
|
| 11 |
from huggingface_hub import login
|
|
|
|
| 22 |
Settings.embed_model = HuggingFaceEmbedding(model_name="sentence-transformers/all-MiniLM-L6-v2")
|
| 23 |
|
| 24 |
# ==== 2. Load Hugging Face LLM (Locally Installed or Remote Hosted) ====
|
| 25 |
+
#llm = HuggingFaceLLM(
|
| 26 |
+
# model_name="unsloth/Mistral-Small-3.1-24B-Instruct-2503-GGUF", # You must have access!
|
| 27 |
+
# tokenizer_name="unsloth/Mistral-Small-3.1-24B-Instruct-2503-GGUF",
|
| 28 |
+
# context_window=2048,
|
| 29 |
+
# max_new_tokens=512,
|
| 30 |
+
# generate_kwargs={"temperature": 0.1},
|
| 31 |
+
# tokenizer_kwargs={"padding_side": "left"},
|
| 32 |
+
# device_map="auto" # Automatically assign model layers to available devices
|
| 33 |
+
#
|
| 34 |
+
#)
|
| 35 |
+
llm = LlamaCPP(
|
| 36 |
+
model_path="/path/to/your/model.gguf",
|
| 37 |
+
temperature=0.1,
|
| 38 |
max_new_tokens=512,
|
| 39 |
+
context_window=4096,
|
| 40 |
+
generate_kwargs={"stop": ["</s>"]},
|
| 41 |
+
model_kwargs={"n_threads": 4}, # adjust for your CPU
|
|
|
|
| 42 |
)
|
| 43 |
|
| 44 |
Settings.llm = llm # Apply to global settings
|