feat: deploy ask TUI to ask.xn--2dk.xyz

- Add ttyd service for ask on port 7682
- Update haloy.yml with new domain and GEMINI_API_KEY
- Update Caddyfile to route ask.xn--2dk.xyz to ttyd
- Update Dockerfile to include ask binary
- Update README with ask section and schema files documentation
This commit is contained in:
2026-03-28 12:12:31 +01:00
parent e1c2377343
commit 8f62a79bbe
5 changed files with 98 additions and 5 deletions

View File

@@ -3,6 +3,27 @@
respond 200 respond 200
} }
# ask.xn--2dk.xyz - Natural language to SQL TUI
ask.xn--2dk.xyz {
@websocket {
header Connection *Upgrade*
header Upgrade websocket
}
handle @websocket {
reverse_proxy localhost:7682 {
flush_interval -1
}
}
handle {
reverse_proxy localhost:7682 {
flush_interval -1
}
}
}
# db.xn--2dk.xyz - DuckDB SQL shell
handle /login { handle /login {
reverse_proxy 127.0.0.1:8081 reverse_proxy 127.0.0.1:8081
} }

View File

@@ -26,7 +26,8 @@ ENV LANG=C.UTF-8 \
WORKDIR /app WORKDIR /app
COPY basedosdados.duckdb Caddyfile start.sh auth.py ./ COPY basedosdados.duckdb Caddyfile start.sh auth.py ./
RUN chmod +x start.sh COPY ask/target/release/ask /app/ask
RUN chmod +x start.sh /app/ask
EXPOSE 8080 EXPOSE 8080

View File

@@ -86,7 +86,68 @@ python prepara_db.py # gera basedosdados.duckdb com views apontando para o S3
duckdb basedosdados.duckdb duckdb basedosdados.duckdb
``` ```
Requer as credenciais do S3 no `.env` (veja seção de configuração abaixo). As queries são executadas diretamente sobre os arquivos Parquet no S3 — não há download de dados. O DuckDB lê os arquivos remotos sob demanda via `httpfs`.
---
## Ask: linguagem natural → SQL
Interface TUI que permite fazer perguntas em português e obter SQL automaticamente.
### No browser
Acesse **https://ask.xn--2dk.xyz** → autentique → digite sua pergunta em português.
### Local
```bash
cd ask
cargo build --release
./target/release/ask # modo interativo
./target/release/ask "Quantos municípios tem SP?" # modo CLI
```
### Variáveis de ambiente
| Variável | Descrição |
|---|---|
| `GEMINI_API_KEY` | Chave da API Gemini (obrigatória para usar modelos Gemini) |
| `OPENROUTER_API_KEY` | Chave para usar modelos via OpenRouter |
| `GEMINI_MODEL` | Modelo a usar (padrão: `gemini-flash-latest`) |
| `SCHEMA_FILE` | Arquivo de schema (padrão: `context/schema_compact_inline.txt`) |
| `DB_FILE` | Arquivo DuckDB (padrão: `basedosdados.duckdb`) |
---
## Arquivos de schema
O diretório `context/` contém artefatos gerados automaticamente para contexto do LLM e descoberta de tabelas:
| Arquivo | Descrição |
|---|---|
| `schema_compact_inline.txt` | Schema condensado para contexto do LLM |
| `schema_compact.txt` | Schema mais verboso |
| `schema_ddl.sql` | DDL das views DuckDB |
| `join_graph.json` | Relacionamentos entre tabelas |
| `file_tree.md` | Estrutura de arquivos no S3 com tamanhos |
| `schemas.json` | Schema raw do BigQuery |
---
## Descobrindo tabelas
```sql
-- listar todos os datasets (schemas)
SHOW SCHEMAS;
-- listar tabelas de um dataset
SHOW TABLES IN br_anatel_banda_larga_fixa;
-- ver colunas de uma tabela
DESCRIBE br_anatel_banda_larga_fixa.densidade_brasil;
```
No shell do browser, `.tables` lista tudo de uma vez. Para descoberta programática, use os arquivos em `context/`.
--- ---
@@ -130,6 +191,7 @@ Resume automático: se interrompido, basta rodar novamente.
| `AWS_ACCESS_KEY_ID` | Access key do Hetzner Object Storage | | `AWS_ACCESS_KEY_ID` | Access key do Hetzner Object Storage |
| `AWS_SECRET_ACCESS_KEY` | Secret key do Hetzner Object Storage | | `AWS_SECRET_ACCESS_KEY` | Secret key do Hetzner Object Storage |
| `BASIC_AUTH_PASSWORD` | Senha do shell web e endpoint `/query` | | `BASIC_AUTH_PASSWORD` | Senha do shell web e endpoint `/query` |
| `GEMINI_API_KEY` | Chave da API Gemini para o ask |
### Executando ### Executando

View File

@@ -7,7 +7,13 @@ domains:
- domain: db.xn--2dk.xyz - domain: db.xn--2dk.xyz
port: 8080 port: 8080
health_check_path: /health health_check_path: /health
- domain: ask.xn--2dk.xyz
port: 8080
health_check_path: /health
env: env:
- name: GEMINI_API_KEY
from:
env: GEMINI_API_KEY
- name: HETZNER_S3_ENDPOINT - name: HETZNER_S3_ENDPOINT
from: from:
env: HETZNER_S3_ENDPOINT env: HETZNER_S3_ENDPOINT

View File

@@ -18,9 +18,12 @@ SET memory_limit='4GB';
SQL SQL
chmod 600 /app/ssh_init.sql chmod 600 /app/ssh_init.sql
echo "[start] Starting ttyd terminal..." echo "[start] Starting ttyd terminal (db)..."
ttyd --port 7681 --writable duckdb -readonly --init /app/ssh_init.sql /app/basedosdados.duckdb & ttyd --port 7681 --writable duckdb -readonly --init /app/ssh_init.sql /app/basedosdados.duckdb &
echo "[start] Starting ttyd terminal (ask)..."
ttyd --port 7682 --writable /app/ask &
echo "[start] Starting auth service..." echo "[start] Starting auth service..."
python3 /app/auth.py & python3 /app/auth.py &