Skip to content

Commit 83efc1c

Browse files
authored
Merge pull request
2 parents 9da8f42 + b194ca7 commit 83efc1c

28 files changed

Lines changed: 235 additions & 18 deletions

.env

Lines changed: 0 additions & 1 deletion
This file was deleted.

.gitignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
.env
2+
3+
**/__pycache__/
4+
*.py[cod]
5+
*$py.class
6+
*.so
7+
8+
cursor/

SQL/instructions_for_creation.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Para criar o banco:
2+
mysql -u root -p -e "CREATE DATABASE IF NOT EXISTS pybot CHARACTER SET utf8mb4;"

SQL/schema.sql

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
CREATE TABLE IF NOT EXISTS knowledge (
2+
id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
3+
title VARCHAR(255) NOT NULL,
4+
content TEXT NOT NULL,
5+
category VARCHAR(100) NOT NULL DEFAULT 'geral',
6+
active TINYINT(1) NOT NULL DEFAULT 1,
7+
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
8+
updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
9+
INDEX idx_active_category (active, category)
10+
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
-195 Bytes
Binary file not shown.
-4.75 KB
Binary file not shown.

api/routes.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
from fastapi import APIRouter, HTTPException, Request
99
from fastapi.responses import HTMLResponse, StreamingResponse
1010

11+
from collections.abc import AsyncGenerator
12+
1113
log = logging.getLogger("kernelbots.api.chat")
1214

1315
router = APIRouter()
@@ -75,6 +77,28 @@ async def chat(request: Request) -> StreamingResponse:
7577
detail="Campo 'session_id' deve ser string ou omitido.",
7678
)
7779

80+
if user_message.strip().lower() == "/reload":
81+
log.info("🔄 Comando /reload recebido — reconstruindo índice BM25...")
82+
services.search_engine.rebuild()
83+
chunk_count = len(services.search_engine.chunks)
84+
db_count = sum(1 for c in services.search_engine.chunks if c.get("source", "").startswith("db:"))
85+
md_count = chunk_count - db_count
86+
status = (
87+
f"Índice reconstruído: {chunk_count} chunk(s) total "
88+
f"({md_count} de arquivos .md + {db_count} do MySQL)."
89+
)
90+
log.info("✅ /reload concluído — %s", status)
91+
92+
async def _reload_stream() -> AsyncGenerator[str, None]:
93+
yield f"data: {status}\n\n"
94+
yield "data: [DONE]\n\n"
95+
96+
return StreamingResponse(
97+
_reload_stream(),
98+
media_type="text/event-stream",
99+
headers={"Cache-Control": "no-cache", "X-Accel-Buffering": "no", "Connection": "keep-alive"},
100+
)
101+
78102
built = services.context_manager.build_messages(
79103
user_message,
80104
discipline_filter=discipline,
-300 Bytes
Binary file not shown.
-2.95 KB
Binary file not shown.
-1.03 KB
Binary file not shown.

0 commit comments

Comments
 (0)