scripts: setup-bt.sh + run.py --no-llm mode for first ELM test
This commit is contained in:
@@ -11,9 +11,12 @@
|
||||
7. Сохраняет всё в SQLite
|
||||
|
||||
Использование:
|
||||
DEEPSEEK_API_KEY=sk-... python run.py
|
||||
DEEPSEEK_API_KEY=sk-... python run.py # полный цикл
|
||||
python run.py --no-llm # только чтение данных (без LLM)
|
||||
python run.py --no-llm --port /dev/rfcomm0 # свой порт
|
||||
"""
|
||||
|
||||
import argparse
|
||||
import sys
|
||||
|
||||
from elmer.config import load
|
||||
@@ -24,21 +27,29 @@ from elmer.prompts import SYSTEM_PROMPT, build_user_prompt
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(description="Elmer — диагностика авто через ELM327 + LLM")
|
||||
parser.add_argument("--no-llm", action="store_true", help="Только чтение данных, без LLM")
|
||||
parser.add_argument("--port", help="Порт ELM327 (по умолчанию из config.yaml)")
|
||||
args = parser.parse_args()
|
||||
|
||||
config = load()
|
||||
|
||||
# ── 1. ELM327 ────────────────────────────────────
|
||||
print("🔌 Подключение к ELM327...")
|
||||
elm_cfg = config["elm327"]
|
||||
port = args.port or elm_cfg["port"]
|
||||
|
||||
try:
|
||||
elm = ELM327(port=elm_cfg["port"], baudrate=elm_cfg["baudrate"])
|
||||
elm = ELM327(port=port, baudrate=elm_cfg["baudrate"])
|
||||
except Exception as e:
|
||||
print(f"❌ Не удалось открыть порт {elm_cfg['port']}: {e}")
|
||||
print(" Проверь Bluetooth-сопряжение: bluetoothctl pair <MAC>")
|
||||
print(f"❌ Не удалось открыть порт {port}: {e}")
|
||||
print(" Проверь Bluetooth-сопряжение:")
|
||||
print(" bash scripts/setup-bt.sh")
|
||||
sys.exit(1)
|
||||
|
||||
if not elm.init():
|
||||
print("❌ ELM327 не ответил на ATZ. Проверь соединение.")
|
||||
elm.close()
|
||||
sys.exit(1)
|
||||
print("✅ ELM327 готов")
|
||||
|
||||
@@ -70,11 +81,27 @@ def main():
|
||||
|
||||
elm.close()
|
||||
|
||||
# ── 5. DeepSeek ──────────────────────────────────
|
||||
# ── 5. Сохранение в SQLite (всегда) ──────────────
|
||||
db = Database()
|
||||
car_id = db.get_or_create_car(vin)
|
||||
token_id = db.create_token(car_id)
|
||||
for dtc in dtc_codes:
|
||||
db.add_dtc(token_id, dtc["code"], dtc.get("description", ""), dtc["status"])
|
||||
for p in parameters:
|
||||
db.add_parameter(token_id, p["pid_code"], p["name"], p["value"], p["unit"])
|
||||
print(f"\n💾 Сохранено в elmer.db (token_id={token_id})")
|
||||
|
||||
# ── 6. DeepSeek (опционально) ────────────────────
|
||||
if args.no_llm:
|
||||
print("\n⏭️ Пропуск LLM (--no-llm). Данные сохранены в elmer.db")
|
||||
return
|
||||
|
||||
api_key = config["deepseek"]["api_key"]
|
||||
if not api_key:
|
||||
print("\n❌ DEEPSEEK_API_KEY не задан. Установи переменную окружения.")
|
||||
sys.exit(1)
|
||||
print("\n❌ DEEPSEEK_API_KEY не задан.")
|
||||
print(" Установи: export DEEPSEEK_API_KEY=sk-...")
|
||||
print(" Или запусти без LLM: python run.py --no-llm")
|
||||
return
|
||||
|
||||
print("\n🧠 Отправка в DeepSeek...")
|
||||
diagnoser = Diagnoser(
|
||||
@@ -89,19 +116,9 @@ def main():
|
||||
print(answer)
|
||||
print("=" * 60)
|
||||
|
||||
# ── 6. Сохранение в SQLite ──────────────────────
|
||||
db = Database()
|
||||
car_id = db.get_or_create_car(vin)
|
||||
token_id = db.create_token(car_id)
|
||||
|
||||
for dtc in dtc_codes:
|
||||
db.add_dtc(token_id, dtc["code"], dtc.get("description", ""), dtc["status"])
|
||||
for p in parameters:
|
||||
db.add_parameter(token_id, p["pid_code"], p["name"], p["value"], p["unit"])
|
||||
db.add_llm_message(token_id, "user", user_prompt)
|
||||
db.add_llm_message(token_id, "assistant", answer)
|
||||
|
||||
print(f"\n💾 Сохранено в elmer.db (token_id={token_id})")
|
||||
print(f"\n💾 LLM-ответ сохранён (token_id={token_id})")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
Reference in New Issue
Block a user