contsql 0.2.2__tar.gz → 0.2.3__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {contsql-0.2.2 → contsql-0.2.3}/PKG-INFO +1 -1
- {contsql-0.2.2 → contsql-0.2.3}/contsql.egg-info/PKG-INFO +1 -1
- {contsql-0.2.2 → contsql-0.2.3}/contsql.py +45 -8
- {contsql-0.2.2 → contsql-0.2.3}/pyproject.toml +1 -1
- {contsql-0.2.2 → contsql-0.2.3}/README.md +0 -0
- {contsql-0.2.2 → contsql-0.2.3}/contsql.egg-info/SOURCES.txt +0 -0
- {contsql-0.2.2 → contsql-0.2.3}/contsql.egg-info/dependency_links.txt +0 -0
- {contsql-0.2.2 → contsql-0.2.3}/contsql.egg-info/entry_points.txt +0 -0
- {contsql-0.2.2 → contsql-0.2.3}/contsql.egg-info/requires.txt +0 -0
- {contsql-0.2.2 → contsql-0.2.3}/contsql.egg-info/top_level.txt +0 -0
- {contsql-0.2.2 → contsql-0.2.3}/setup.cfg +0 -0
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env python3
|
|
2
|
-
# v0.2.
|
|
2
|
+
# v0.2.3 | 2026-04-13 | entity_id+unvan zorunlu kural + slash commands (/s /schema /trace /help)
|
|
3
3
|
"""contsql — Minimal DuckDB SQL agent. Soru sor, SQL üret, çalıştır, göster."""
|
|
4
4
|
|
|
5
5
|
import argparse
|
|
@@ -85,7 +85,7 @@ Kurallar:
|
|
|
85
85
|
- SQL öncesi veya sonrası açıklama ekleme.
|
|
86
86
|
- Emin değilsen "Bu soruyu mevcut tablolarla cevaplayamıyorum" de.
|
|
87
87
|
- Veri uydurma. Sorgu sonucu olmadan liste verme.
|
|
88
|
-
- HER sorguda entity_id ve unvan kolonlarını dahil et. Firmalar bu iki alanla tanımlanır
|
|
88
|
+
- HER sorguda entity_id ve unvan kolonlarını dahil et. Firmalar bu iki alanla tanımlanır. Sadece COUNT/SUM gibi tek değer döndüren aggregation sorgularında entity_id gerekmez.
|
|
89
89
|
- String karşılaştırmalarında LIKE yerine her zaman ILIKE kullan. Türkçe karakter eşleştirmesi (İ↔i, I↔ı, Ş↔ş, Ü↔ü, Ö↔ö, Ç↔ç, Ğ↔ğ) için ILIKE şart.
|
|
90
90
|
|
|
91
91
|
Veritabanı şeması:
|
|
@@ -338,12 +338,46 @@ def run_query(conn, system_prompt, question):
|
|
|
338
338
|
return None
|
|
339
339
|
|
|
340
340
|
|
|
341
|
+
def handle_slash_command(cmd, state):
|
|
342
|
+
"""Slash command işle. True → normal sorgu akışına girme."""
|
|
343
|
+
cmd = cmd.strip().lower()
|
|
344
|
+
|
|
345
|
+
if cmd == "/s":
|
|
346
|
+
state["last_result_entities"] = None
|
|
347
|
+
print("🧹 Bellek temizlendi.")
|
|
348
|
+
return True
|
|
349
|
+
|
|
350
|
+
if cmd == "/schema":
|
|
351
|
+
print(f"\n{state['schema_text']}\n")
|
|
352
|
+
return True
|
|
353
|
+
|
|
354
|
+
if cmd == "/trace":
|
|
355
|
+
state["trace"] = not state.get("trace", False)
|
|
356
|
+
print(f"🔍 Trace: {'açık' if state['trace'] else 'kapalı'}")
|
|
357
|
+
return True
|
|
358
|
+
|
|
359
|
+
if cmd == "/help":
|
|
360
|
+
print("Komutlar:")
|
|
361
|
+
print(" /s — önceki sorgu hafızasını temizle")
|
|
362
|
+
print(" /schema — veritabanı şemasını göster")
|
|
363
|
+
print(" /trace — SQL trace modunu aç/kapa")
|
|
364
|
+
print(" /help — bu mesaj")
|
|
365
|
+
print(" quit — çıkış")
|
|
366
|
+
return True
|
|
367
|
+
|
|
368
|
+
return False
|
|
369
|
+
|
|
370
|
+
|
|
341
371
|
def interactive_loop(conn, schema_text, domain_text):
|
|
342
372
|
"""REPL döngüsü."""
|
|
343
|
-
print(f"\ncontsql hazır. Model: {MODEL}")
|
|
373
|
+
print(f"\ncontsql hazır. Model: {MODEL} | /help komutlar")
|
|
344
374
|
print("Çıkmak için: quit/exit/q\n")
|
|
345
375
|
|
|
346
|
-
|
|
376
|
+
state = {
|
|
377
|
+
"last_result_entities": None,
|
|
378
|
+
"trace": False,
|
|
379
|
+
"schema_text": schema_text,
|
|
380
|
+
}
|
|
347
381
|
|
|
348
382
|
while True:
|
|
349
383
|
try:
|
|
@@ -356,15 +390,18 @@ def interactive_loop(conn, schema_text, domain_text):
|
|
|
356
390
|
continue
|
|
357
391
|
if question.lower() in ("quit", "exit", "q", "çık"):
|
|
358
392
|
break
|
|
359
|
-
|
|
360
|
-
|
|
393
|
+
|
|
394
|
+
if question.startswith("/"):
|
|
395
|
+
if not handle_slash_command(question, state):
|
|
396
|
+
print(f"Bilinmeyen komut: {question}. /help yazın.")
|
|
361
397
|
continue
|
|
362
398
|
|
|
363
|
-
system_prompt = build_system_prompt(schema_text, domain_text,
|
|
399
|
+
system_prompt = build_system_prompt(schema_text, domain_text,
|
|
400
|
+
state["last_result_entities"],
|
|
364
401
|
question=question)
|
|
365
402
|
entities = run_query(conn, system_prompt, question)
|
|
366
403
|
if entities is not None:
|
|
367
|
-
last_result_entities = entities
|
|
404
|
+
state["last_result_entities"] = entities
|
|
368
405
|
print()
|
|
369
406
|
|
|
370
407
|
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|