Safetensors
GGUF
Portuguese
English
nl2sql
text-to-sql
postgis
geospatial
cpu-inference
qwen2.5-coder
conversational
Instructions to use thiagonishimura/TerraModel with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- llama.cpp
How to use thiagonishimura/TerraModel with llama.cpp:
Install (macOS, Linux)
curl -LsSf https://llama.app/install.sh | sh # Start a local OpenAI-compatible server with a web UI: llama serve -hf thiagonishimura/TerraModel:Q4_K_M # Run inference directly in the terminal: llama cli -hf thiagonishimura/TerraModel:Q4_K_M
Install from WinGet (Windows)
winget install llama.cpp # Start a local OpenAI-compatible server with a web UI: llama serve -hf thiagonishimura/TerraModel:Q4_K_M # Run inference directly in the terminal: llama cli -hf thiagonishimura/TerraModel:Q4_K_M
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 thiagonishimura/TerraModel:Q4_K_M # Run inference directly in the terminal: ./llama-cli -hf thiagonishimura/TerraModel:Q4_K_M
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 thiagonishimura/TerraModel:Q4_K_M # Run inference directly in the terminal: ./build/bin/llama-cli -hf thiagonishimura/TerraModel:Q4_K_M
Use Docker
docker model run hf.co/thiagonishimura/TerraModel:Q4_K_M
- LM Studio
- Jan
- Ollama
How to use thiagonishimura/TerraModel with Ollama:
ollama run hf.co/thiagonishimura/TerraModel:Q4_K_M
- Unsloth Desktop
- Pi
How to use thiagonishimura/TerraModel with Pi:
Start the llama.cpp server
# Install llama.cpp: brew install llama.cpp # Start a local OpenAI-compatible server: llama serve -hf thiagonishimura/TerraModel:Q4_K_M
Configure the model in Pi
# Install Pi: npm install -g @earendil-works/pi-coding-agent # Add to ~/.pi/agent/models.json: { "providers": { "llama-cpp": { "baseUrl": "http://localhost:8080/v1", "api": "openai-completions", "apiKey": "none", "models": [ { "id": "thiagonishimura/TerraModel:Q4_K_M" } ] } } }Run Pi
# Start Pi in your project directory: pi
- Docker Model Runner
How to use thiagonishimura/TerraModel with Docker Model Runner:
docker model run hf.co/thiagonishimura/TerraModel:Q4_K_M
- Lemonade
How to use thiagonishimura/TerraModel with Lemonade:
Pull the model
# Download Lemonade from https://lemonade-server.ai/ lemonade pull thiagonishimura/TerraModel:Q4_K_M
Run and chat with the model
lemonade run user.TerraModel-Q4_K_M
List all available models
lemonade list
- Hermes Agent
How to use thiagonishimura/TerraModel with Hermes Agent:
Start the llama.cpp server
# Install llama.cpp: brew install llama.cpp # Start a local OpenAI-compatible server: llama serve -hf thiagonishimura/TerraModel:Q4_K_M
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 thiagonishimura/TerraModel:Q4_K_M
Run Hermes
hermes
- Atomic Chat
- OpenClaw
How to use thiagonishimura/TerraModel with OpenClaw:
Start the llama.cpp server
# Install llama.cpp: brew install llama.cpp # Start a local OpenAI-compatible server: llama serve -hf thiagonishimura/TerraModel:Q4_K_M
Configure OpenClaw
# Install OpenClaw: npm install -g openclaw@latest # Register the local server and set it as the default model: openclaw onboard --non-interactive --mode local \ --auth-choice custom-api-key \ --custom-base-url http://127.0.0.1:8080/v1 \ --custom-model-id "thiagonishimura/TerraModel:Q4_K_M" \ --custom-provider-id llama-cpp \ --custom-compatibility openai \ --custom-text-input \ --accept-risk \ --skip-health
Run OpenClaw
openclaw agent --local --agent main --message "Hello from Hugging Face"
Update README.md
Browse files
README.md
CHANGED
|
@@ -45,4 +45,67 @@ Para rodar o modelo localmente utilizando apenas CPU, recomendamos a biblioteca
|
|
| 45 |
|
| 46 |
### Instalação
|
| 47 |
```bash
|
| 48 |
-
pip install llama-cpp-python
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
|
| 46 |
### Instalação
|
| 47 |
```bash
|
| 48 |
+
pip install llama-cpp-python
|
| 49 |
+
```
|
| 50 |
+
|
| 51 |
+
### Exemplo de Código (Python)
|
| 52 |
+
```bash
|
| 53 |
+
from llama_cpp import Llama
|
| 54 |
+
|
| 55 |
+
def generate_spatial_query(prompt: str, model_path: str) -> str:
|
| 56 |
+
"""
|
| 57 |
+
Gera uma consulta PostGIS a partir de linguagem natural utilizando o TerraModel.
|
| 58 |
+
|
| 59 |
+
Args:
|
| 60 |
+
prompt (str): A pergunta em linguagem natural.
|
| 61 |
+
model_path (str): O caminho local para o arquivo .gguf.
|
| 62 |
+
|
| 63 |
+
Returns:
|
| 64 |
+
str: A consulta SQL gerada pelo modelo.
|
| 65 |
+
"""
|
| 66 |
+
# Instanciação do modelo otimizada para CPU
|
| 67 |
+
llm = Llama(
|
| 68 |
+
model_path=model_path,
|
| 69 |
+
n_ctx=2048, # Janela de contexto
|
| 70 |
+
n_threads=8, # Ajuste para a quantidade de núcleos físicos da sua CPU
|
| 71 |
+
verbose=False
|
| 72 |
+
)
|
| 73 |
+
|
| 74 |
+
# System Prompt exato utilizado no fine-tuning do TerraModel
|
| 75 |
+
system_prompt = """Você é o TerraModel, um especialista em análise geoespacial e PostgreSQL/PostGIS.
|
| 76 |
+
Sua tarefa é traduzir perguntas em linguagem natural para consultas SQL rigorosas e otimizadas.
|
| 77 |
+
|
| 78 |
+
Você deve basear sua sintaxe ESTRITAMENTE no seguinte esquema de banco de dados:
|
| 79 |
+
CREATE TABLE public.dados_deter (gid integer, fid varchar, classname varchar, quadrant varchar, path_row varchar, view_date date, sensor varchar, satellite varchar, areauckm numeric, uc varchar, areamunkm numeric, municipali varchar, geocodibge varchar, uf varchar, geom geometry);
|
| 80 |
+
Nota: Use unaccent() para buscar textos."""
|
| 81 |
+
|
| 82 |
+
# Formatação ChatML requerida pelo Qwen2.5-Coder
|
| 83 |
+
formatted_prompt = f"<|im_start|>system\n{system_prompt}<|im_end|>\n<|im_start|>user\n{prompt}<|im_end|>\n<|im_start|>assistant\n"
|
| 84 |
+
|
| 85 |
+
# Inferência
|
| 86 |
+
response = llm(
|
| 87 |
+
formatted_prompt,
|
| 88 |
+
max_tokens=256,
|
| 89 |
+
stop=["<|im_end|>"],
|
| 90 |
+
temperature=0.1 # Temperatura baixa para garantir determinismo na sintaxe SQL
|
| 91 |
+
)
|
| 92 |
+
|
| 93 |
+
return response['choices'][0]['text'].strip()
|
| 94 |
+
|
| 95 |
+
# Exemplo de uso
|
| 96 |
+
if __name__ == "__main__":
|
| 97 |
+
pergunta = "Calcule a área total em hectares dos polígonos que representam áreas de desmatamento e que estão dentro de um raio de 10 km de um ponto específico."
|
| 98 |
+
caminho_gguf = "./terramodel-7b-q4_k_m.gguf"
|
| 99 |
+
|
| 100 |
+
sql_gerado = generate_spatial_query(pergunta, caminho_gguf)
|
| 101 |
+
print("Query Gerada:\n", sql_gerado)
|
| 102 |
+
```
|
| 103 |
+
|
| 104 |
+
## 📊 Avaliação e Desempenho
|
| 105 |
+
O modelo foi submetido a um rigoroso benchmark empírico. A versão TerraModel 7B Q8 atingiu uma Acurácia de Execução de 82.00% no PostGIS, superando APIs comerciais como o GPT-4o-mini em cenários de inferência zero-shot focados no esquema do projeto.
|
| 106 |
+
|
| 107 |
+
Para aprofundamento metodológico, métricas de Throughput de memória e validação semântica (RAGAS), consulte o artigo científico completo vinculado a este projeto.
|
| 108 |
+
|
| 109 |
+
## 🔗 Conjunto de Dados e Reprodutibilidade
|
| 110 |
+
O dataset sintético com as 3.000 amostras (pares NL-SQL) utilizadas para a injeção de conhecimento topológico e as métricas de benchmark estão disponíveis no repositório do GitHub:
|
| 111 |
+
👉 [Acesse o Repositório](https://github.com/thiagonishimura/terramodel)
|