71 lines
2.4 KiB
Python
Executable File
71 lines
2.4 KiB
Python
Executable File
import json
|
|
import os
|
|
|
|
# --- KONFIGURACJA ---
|
|
# Tutaj mapujemy nazwę pliku na kategorię, którą chcemy "wypalić" w treści
|
|
FILES_MAPPING = {
|
|
"sniadania.jsonl": "ŚNIADANIE (RANO)",
|
|
"drugie_sniadania.jsonl": "DRUGIE ŚNIADANIE / PRZEKĄSKA",
|
|
"obiady.jsonl": "OBIAD (DANIE GŁÓWNE)",
|
|
"kolacje.jsonl": "KOLACJA (WIECZÓR)",
|
|
# "desery.jsonl": "DESER"
|
|
}
|
|
|
|
OUTPUT_DIR = "./gotowe_do_rag"
|
|
if not os.path.exists(OUTPUT_DIR):
|
|
os.makedirs(OUTPUT_DIR)
|
|
|
|
def process_files():
|
|
print("--- ROZPOCZYNAM PRZETWARZANIE DANYCH ---")
|
|
|
|
for filename, category_tag in FILES_MAPPING.items():
|
|
if not os.path.exists(filename):
|
|
print(f"⚠️ Pominięto {filename} (brak pliku)")
|
|
continue
|
|
|
|
output_path = os.path.join(OUTPUT_DIR, f"processed_{filename}")
|
|
|
|
print(f"🔄 Przetwarzanie: {filename} -> Kategoria: {category_tag}")
|
|
|
|
with open(filename, 'r', encoding='utf-8') as fin, \
|
|
open(output_path, 'w', encoding='utf-8') as fout:
|
|
|
|
count = 0
|
|
for line in fin:
|
|
line = line.strip()
|
|
if not line: continue
|
|
|
|
try:
|
|
# 1. Wczytaj oryginalny JSON
|
|
record = json.loads(line)
|
|
|
|
# 2. Stwórz wersję tekstową idealną dla LLM
|
|
# Ignorujemy techniczne ID, skupiamy się na treści
|
|
content_for_ai = f"""
|
|
### TYP POSIŁKU: {category_tag}
|
|
NAZWA: {record.get('name', 'Bez nazwy')}
|
|
KALORIE: {record.get('calories', 'brak danych')} kcal
|
|
SKŁADNIKI: {', '.join(record.get('ingredients', []))}
|
|
PRZYGOTOWANIE: {record.get('preparation', '')}
|
|
""".strip()
|
|
|
|
# 3. Zapisz jako nowy obiekt JSONL z gotowym polem 'text_content'
|
|
# RAG będzie czytał tylko to pole 'text_content'
|
|
new_record = {
|
|
"source_file": filename,
|
|
"category": category_tag,
|
|
"text_content": content_for_ai
|
|
}
|
|
|
|
fout.write(json.dumps(new_record, ensure_ascii=False) + "\n")
|
|
count += 1
|
|
except json.JSONDecodeError:
|
|
continue
|
|
|
|
print(f"✅ Zapisano {count} przepisów do {output_path}")
|
|
|
|
print(f"\nGotowe! Pliki do wgrania znajdują się w folderze: {OUTPUT_DIR}")
|
|
|
|
if __name__ == "__main__":
|
|
process_files()
|