Instructions to use PyThaGo/LLMLit with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- llama-cpp-python
How to use PyThaGo/LLMLit with llama-cpp-python:
# !pip install llama-cpp-python from llama_cpp import Llama llm = Llama.from_pretrained( repo_id="PyThaGo/LLMLit", filename="LLMLit-0.2-8B-Instruct.gguf", )
llm.create_chat_completion( messages = "No input example has been defined for this model task." )
- Notebooks
- Google Colab
- Kaggle
- Local Apps
- llama.cpp
How to use PyThaGo/LLMLit with llama.cpp:
Install from brew
brew install llama.cpp # Start a local OpenAI-compatible server with a web UI: llama-server -hf PyThaGo/LLMLit # Run inference directly in the terminal: llama-cli -hf PyThaGo/LLMLit
Install from WinGet (Windows)
winget install llama.cpp # Start a local OpenAI-compatible server with a web UI: llama-server -hf PyThaGo/LLMLit # Run inference directly in the terminal: llama-cli -hf PyThaGo/LLMLit
Use pre-built binary
# Download pre-built binary from: # https://github.com/ggerganov/llama.cpp/releases # Start a local OpenAI-compatible server with a web UI: ./llama-server -hf PyThaGo/LLMLit # Run inference directly in the terminal: ./llama-cli -hf PyThaGo/LLMLit
Build from source code
git clone https://github.com/ggerganov/llama.cpp.git cd llama.cpp cmake -B build cmake --build build -j --target llama-server llama-cli # Start a local OpenAI-compatible server with a web UI: ./build/bin/llama-server -hf PyThaGo/LLMLit # Run inference directly in the terminal: ./build/bin/llama-cli -hf PyThaGo/LLMLit
Use Docker
docker model run hf.co/PyThaGo/LLMLit
- LM Studio
- Jan
- Ollama
How to use PyThaGo/LLMLit with Ollama:
ollama run hf.co/PyThaGo/LLMLit
- Unsloth Studio new
How to use PyThaGo/LLMLit with Unsloth Studio:
Install Unsloth Studio (macOS, Linux, WSL)
curl -fsSL https://unsloth.ai/install.sh | sh # Run unsloth studio unsloth studio -H 0.0.0.0 -p 8888 # Then open http://localhost:8888 in your browser # Search for PyThaGo/LLMLit to start chatting
Install Unsloth Studio (Windows)
irm https://unsloth.ai/install.ps1 | iex # Run unsloth studio unsloth studio -H 0.0.0.0 -p 8888 # Then open http://localhost:8888 in your browser # Search for PyThaGo/LLMLit to start chatting
Using HuggingFace Spaces for Unsloth
# No setup required # Open https://huggingface.co/spaces/unsloth/studio in your browser # Search for PyThaGo/LLMLit to start chatting
- Pi new
How to use PyThaGo/LLMLit with Pi:
Start the llama.cpp server
# Install llama.cpp: brew install llama.cpp # Start a local OpenAI-compatible server: llama-server -hf PyThaGo/LLMLit
Configure the model in Pi
# Install Pi: npm install -g @mariozechner/pi-coding-agent # Add to ~/.pi/agent/models.json: { "providers": { "llama-cpp": { "baseUrl": "http://localhost:8080/v1", "api": "openai-completions", "apiKey": "none", "models": [ { "id": "PyThaGo/LLMLit" } ] } } }Run Pi
# Start Pi in your project directory: pi
- Hermes Agent new
How to use PyThaGo/LLMLit with Hermes Agent:
Start the llama.cpp server
# Install llama.cpp: brew install llama.cpp # Start a local OpenAI-compatible server: llama-server -hf PyThaGo/LLMLit
Configure Hermes
# Install Hermes: curl -fsSL https://hermes-agent.nousresearch.com/install.sh | bash hermes setup # Point Hermes at the local server: hermes config set model.provider custom hermes config set model.base_url http://127.0.0.1:8080/v1 hermes config set model.default PyThaGo/LLMLit
Run Hermes
hermes
- Docker Model Runner
How to use PyThaGo/LLMLit with Docker Model Runner:
docker model run hf.co/PyThaGo/LLMLit
- Lemonade
How to use PyThaGo/LLMLit with Lemonade:
Pull the model
# Download Lemonade from https://lemonade-server.ai/ lemonade pull PyThaGo/LLMLit
Run and chat with the model
lemonade run user.LLMLit-{{QUANT_TAG}}List all available models
lemonade list
Cristian Sas commited on
Create RAG LLMLit
Browse files- RAG LLMLit +115 -0
RAG LLMLit
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
### **Pași pentru implementarea RAG cu LLMLit pe Hugging Face 🚀**
|
| 2 |
+
---
|
| 3 |
+
|
| 4 |
+
**Retrieval-Augmented Generation (RAG)** folosind modelul **LLMLit** disponibil pe Hugging Face. RAG combină căutarea informațiilor relevante cu generarea de texte pentru a produce răspunsuri mai precise. Vom utiliza Hugging Face pentru a integra acest model și vom folosi o bază de date externă pentru a face interogări și a îmbogăți răspunsurile generate de modelul LLMLit.
|
| 5 |
+
|
| 6 |
+
#### 1. **Instalarea pachetelor necesare 🛠️**
|
| 7 |
+
|
| 8 |
+
În primul rând, trebuie să instalezi librăriile necesare pentru a lucra cu **Hugging Face** și **LLMLit**. Poți face acest lucru folosind pip:
|
| 9 |
+
|
| 10 |
+
```bash
|
| 11 |
+
pip install transformers datasets faiss-cpu
|
| 12 |
+
```
|
| 13 |
+
|
| 14 |
+
- `transformers` este pachetul care ne permite să interacționăm cu modelele de la Hugging Face.
|
| 15 |
+
- `datasets` ne ajută să gestionăm datele externe pentru căutare.
|
| 16 |
+
- `faiss-cpu` este opțional, dar îl recomandăm pentru căutarea vectorială rapidă a documentelor.
|
| 17 |
+
|
| 18 |
+
#### 2. **Încărcarea modelului LLMLit de pe Hugging Face 🔄**
|
| 19 |
+
|
| 20 |
+
Acum, putem încarcă modelul **LLMLit** folosind Hugging Face:
|
| 21 |
+
|
| 22 |
+
```python
|
| 23 |
+
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
|
| 24 |
+
|
| 25 |
+
# Încărcăm modelul LLMLit și tokenizer-ul
|
| 26 |
+
tokenizer = AutoTokenizer.from_pretrained("LLMLit/LLMLit")
|
| 27 |
+
model = AutoModelForSeq2SeqLM.from_pretrained("LLMLit/LLMLit")
|
| 28 |
+
```
|
| 29 |
+
|
| 30 |
+
#### 3. **Configurarea bazei de date de documente 🔍**
|
| 31 |
+
|
| 32 |
+
Pentru a folosi RAG, avem nevoie de o sursă externă de documente pentru a recupera informațiile relevante. În exemplul de față, vom folosi **FAISS** pentru căutarea rapidă a documentelor. Începe prin a crea un index FAISS:
|
| 33 |
+
|
| 34 |
+
```python
|
| 35 |
+
import faiss
|
| 36 |
+
import numpy as np
|
| 37 |
+
|
| 38 |
+
# Crearea unui set de documente fictive
|
| 39 |
+
documents = [
|
| 40 |
+
"LLMLit este un model puternic de procesare a limbajului natural.",
|
| 41 |
+
"RAG combină generarea de texte cu căutarea de informații externe.",
|
| 42 |
+
"Hugging Face oferă o platformă excelentă pentru modelele AI.",
|
| 43 |
+
"FAISS este un tool de căutare vectorială rapidă pentru baze de date mari."
|
| 44 |
+
]
|
| 45 |
+
|
| 46 |
+
# Tokenizare și crearea vectorilor pentru documente
|
| 47 |
+
embedding_model = AutoModelForSeq2SeqLM.from_pretrained("sentence-transformers/all-MiniLM-L6-v2")
|
| 48 |
+
tokenizer = AutoTokenizer.from_pretrained("sentence-transformers/all-MiniLM-L6-v2")
|
| 49 |
+
|
| 50 |
+
def encode_documents(documents):
|
| 51 |
+
embeddings = []
|
| 52 |
+
for doc in documents:
|
| 53 |
+
inputs = tokenizer(doc, return_tensors="pt", padding=True, truncation=True)
|
| 54 |
+
with torch.no_grad():
|
| 55 |
+
embeddings.append(embedding_model(**inputs).last_hidden_state.mean(dim=1).numpy())
|
| 56 |
+
return np.vstack(embeddings)
|
| 57 |
+
|
| 58 |
+
document_vectors = encode_documents(documents)
|
| 59 |
+
|
| 60 |
+
# Crearea indexului FAISS
|
| 61 |
+
index = faiss.IndexFlatL2(document_vectors.shape[1]) # Distanta L2
|
| 62 |
+
index.add(document_vectors)
|
| 63 |
+
```
|
| 64 |
+
|
| 65 |
+
#### 4. **Căutarea celor mai relevante documente 🔍**
|
| 66 |
+
|
| 67 |
+
Acum, putem folosi FAISS pentru a căuta documentele cele mai relevante pe baza întrebării utilizatorului:
|
| 68 |
+
|
| 69 |
+
```python
|
| 70 |
+
def retrieve_documents(query, top_k=3):
|
| 71 |
+
query_vector = encode_documents([query]) # Încodifică întrebarea
|
| 72 |
+
distances, indices = index.search(query_vector, top_k) # Căutăm cele mai apropiate documente
|
| 73 |
+
return [documents[i] for i in indices[0]]
|
| 74 |
+
|
| 75 |
+
# Exemplu de interogare
|
| 76 |
+
query = "Cum se folosește RAG în aplicațiile AI?"
|
| 77 |
+
relevant_documents = retrieve_documents(query)
|
| 78 |
+
print(relevant_documents)
|
| 79 |
+
```
|
| 80 |
+
|
| 81 |
+
#### 5. **Generarea răspunsului folosind LLMLit 📝**
|
| 82 |
+
|
| 83 |
+
Acum că avem documentele relevante, le putem utiliza pentru a genera un răspuns contextului întrebării. Vom adăuga aceste documente la promptul nostru pentru LLMLit:
|
| 84 |
+
|
| 85 |
+
```python
|
| 86 |
+
def generate_answer(query, documents):
|
| 87 |
+
context = " ".join(documents) # Adăugăm documentele relevante ca și context
|
| 88 |
+
prompt = f"Întrebare: {query}\nContext: {context}\nRăspuns:"
|
| 89 |
+
|
| 90 |
+
# Tokenizarea promptului
|
| 91 |
+
inputs = tokenizer(prompt, return_tensors="pt", padding=True, truncation=True)
|
| 92 |
+
|
| 93 |
+
# Generarea răspunsului
|
| 94 |
+
outputs = model.generate(inputs['input_ids'], max_length=200, num_beams=5, early_stopping=True)
|
| 95 |
+
answer = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 96 |
+
return answer
|
| 97 |
+
|
| 98 |
+
# Generarea răspunsului final
|
| 99 |
+
answer = generate_answer(query, relevant_documents)
|
| 100 |
+
print(answer)
|
| 101 |
+
```
|
| 102 |
+
|
| 103 |
+
#### 6. **Rezultatul final 🎯**
|
| 104 |
+
|
| 105 |
+
În acest moment, ai un sistem complet RAG care combină **căutarea de documente externe** cu **generarea de text** utilizând LLMLit. Modelul va căuta informațiile relevante în documentele tale și va genera un răspuns informativ și precis.
|
| 106 |
+
|
| 107 |
+
---
|
| 108 |
+
|
| 109 |
+
### **Concluzie 🌟**
|
| 110 |
+
|
| 111 |
+
Implementarea **RAG** folosind **LLMLit** îmbunătățește semnificativ calitatea răspunsurilor oferite de modele de limbaj, deoarece acestea pot accesa o bază de date externă pentru a obține informații mai precise și mai detaliate. Utilizând Hugging Face și librăriile precum FAISS, poți construi un sistem puternic de întrebări și răspunsuri bazat pe RAG.
|
| 112 |
+
|
| 113 |
+
🔗 **Pentru a experimenta cu LLMLit și pentru mai multe informații, vizitează [pagina oficială Hugging Face a modelului LLMLit](https://huggingface.co/LLMLit/LLMLit).**
|
| 114 |
+
|
| 115 |
+
Sper că acest ghid îți va fi de ajutor! 😊
|