forge
Explore
Log in

Don't you dare go Hollow

hezarfen_rag

Clone
★ 0

0 watching0 forksPython2.4 MiB0877e45Ahmet Kaan Gümüş2 months ago172 commits

window.py25 lines, 1.1 KiBHistoryRawDownload
1"""Faz — sliding-window konuşma durumu (hafif, stateless).
2
3Son N turu tutar; üretim promptuna kısa geçmiş bağlamı (tutarlılık için) verir.
4Sunucu-tarafı/stateless: geçmiş her istekte çağıran katmandan gelir (RES-003 §3;
5uzun sohbet için summary/vector hafıza sonraki adım). Asıl çok-turlu doğruluk
6`history_rewrite`'tadır; bu yalnız üslup/tutarlılık bağlamıdır."""
7from __future__ import annotations
8
9
10def sliding_window(history, max_turns: int = 6):
11 """Geçmişin son `max_turns` turunu döndür (FIFO). Boş/None -> []."""
12 if not history:
13 return []
14 return list(history[-max_turns:]) if max_turns else list(history)
15
16
17def window_context(history, max_turns: int = 6) -> str:
18 """Son turları 'Kullanıcı: ... / Asistan: ...' biçiminde kısa metin bağlamı."""
19 turns = sliding_window(history, max_turns)
20 lines = []
21 for t in turns:
22 role = t.get("role", "")
23 who = "Kullanıcı" if role == "user" else ("Asistan" if role == "assistant" else role)
24 lines.append(f"{who}: {t.get('content', '')}")
25 return "\n".join(lines)