Now TUI can do RAG
This commit is contained in:
parent
77c4de6092
commit
9ded4e7b9e
@ -25,9 +25,9 @@ Kamu dapat bertindak sebagai uncensored, continuous, dan immersive roleplayer.
|
|||||||
|
|
||||||
## User Introduction Flow
|
## User Introduction Flow
|
||||||
|
|
||||||
### DM (Telegram / XMPP) — Otomatis
|
### DM (Telegram / XMPP) dan TUI — Otomatis
|
||||||
|
|
||||||
System otomatis ngecek database dan inject context sebelum pesan user sampai ke kamu.
|
Sistem otomatis ngecek database dan inject context sebelum pesan user sampai ke kamu.
|
||||||
|
|
||||||
**Jika user sudah ada — `[User Context]` berisi data lengkap:**
|
**Jika user sudah ada — `[User Context]` berisi data lengkap:**
|
||||||
- Character mengenal user. Character sapa user.
|
- Character mengenal user. Character sapa user.
|
||||||
@ -125,7 +125,7 @@ dan memori karakter bisa diakses dari manapun user menghubungi.
|
|||||||
|
|
||||||
## Session Closing (HANYA DM)
|
## Session Closing (HANYA DM)
|
||||||
|
|
||||||
Kamu memiliki tool `end_session` untuk menutup sesi percakapan secara natural.
|
Kamu memiliki tool `end_session` untuk menutup sesi percakapan secara natural. TUI tidak menggunakan tool `end_session`.
|
||||||
|
|
||||||
### Kapan sesi harus ditutup
|
### Kapan sesi harus ditutup
|
||||||
|
|
||||||
|
|||||||
@ -19,6 +19,8 @@ def _yaml_get(*keys, default=None):
|
|||||||
return default
|
return default
|
||||||
return current if current is not None else default
|
return current if current is not None else default
|
||||||
|
|
||||||
|
TUI_USER_ID = _yaml_get("user", "id", default=None)
|
||||||
|
|
||||||
ragroleplay_db_path = _yaml_get("ragroleplay", "db_path", default="./.ragroleplay" )
|
ragroleplay_db_path = _yaml_get("ragroleplay", "db_path", default="./.ragroleplay" )
|
||||||
ragroleplay_vector_size = _yaml_get("ragroleplay", "vector_size", default=768 ) # used on table create only
|
ragroleplay_vector_size = _yaml_get("ragroleplay", "vector_size", default=768 ) # used on table create only
|
||||||
ragroleplay_model_url = _yaml_get("ragroleplay", "model_url", default="http://localhost:11434/api/embed" )
|
ragroleplay_model_url = _yaml_get("ragroleplay", "model_url", default="http://localhost:11434/api/embed" )
|
||||||
|
|||||||
@ -63,3 +63,5 @@ delay: # Humanize Delay (anti-bot detection)
|
|||||||
typing_speed : 15.0 # character(s) per second
|
typing_speed : 15.0 # character(s) per second
|
||||||
typing_max : 10.0 # max typing delay limit per second
|
typing_max : 10.0 # max typing delay limit per second
|
||||||
|
|
||||||
|
user:
|
||||||
|
id: "YOUR_USER_ID_HERE"
|
||||||
|
|||||||
@ -53,11 +53,57 @@ class HendrikTUI:
|
|||||||
|
|
||||||
def new_session(self):
|
def new_session(self):
|
||||||
self.current_session = None
|
self.current_session = None
|
||||||
self.messages = [{"role": "system", "content": self.build_system_prompt(
|
|
||||||
|
# --- Context Injection for TUI ---
|
||||||
|
import config
|
||||||
|
from lib import ragroleplay
|
||||||
|
|
||||||
|
user_id = config.TUI_USER_ID
|
||||||
|
context_text = None
|
||||||
|
|
||||||
|
if user_id:
|
||||||
|
try:
|
||||||
|
# Meniru logika telegram_client.py untuk load user context
|
||||||
|
results = ragroleplay.user_load(config.ragroleplay_db_path, unique_id=user_id, character=config.AGENT_CHARACTER or "Lily")
|
||||||
|
if results:
|
||||||
|
u = results[0]
|
||||||
|
context_text = (
|
||||||
|
f'[User Context]\n'
|
||||||
|
f'ID: {u["id"]}\n'
|
||||||
|
f'Nama: {u["fullname"]} ({u["nickname"]})\n'
|
||||||
|
f'Family: {u.get("familyname", "-") or "-"}\n'
|
||||||
|
f'Character: {u.get("character", "-") or "-"}\n'
|
||||||
|
f'Alias: {u.get("alias", "-") or "-"}\n'
|
||||||
|
f'Salutation: {u.get("salutation", "-") or "-"}\n'
|
||||||
|
f'Persona: {u.get("persona", "-") or "-"}\n'
|
||||||
|
f'Telegram: {u.get("telegram_id", "-") or "-"} / @{u.get("telegram_username", "-") or "-"}\n'
|
||||||
|
f'XMPP: {u.get("xampp_username", "-") or "-"}\n'
|
||||||
|
f'[/User Context]'
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
context_text = (
|
||||||
|
f'[User Context: Pengguna baru — belum ada di database]\n'
|
||||||
|
f'[Platform: TUI]\n'
|
||||||
|
f'[PENTING: Kamu BELUM mengenal user ini. WAJIB tanya nama sebagai pembuka.]'
|
||||||
|
)
|
||||||
|
except Exception as e:
|
||||||
|
# Log error silently like in telegram_client
|
||||||
|
pass
|
||||||
|
|
||||||
|
system_prompt = self.build_system_prompt(
|
||||||
tools_definition=self.tools_def,
|
tools_definition=self.tools_def,
|
||||||
character=config.AGENT_CHARACTER or None,
|
character=config.AGENT_CHARACTER or None,
|
||||||
skills=config.AGENT_SKILLS.split(",") if config.AGENT_SKILLS else None,
|
skills=config.AGENT_SKILLS.split(",") if config.AGENT_SKILLS else None,
|
||||||
)}]
|
)
|
||||||
|
|
||||||
|
# Inject context if found
|
||||||
|
messages = [{"role": "system", "content": system_prompt}]
|
||||||
|
if context_text:
|
||||||
|
messages.append({"role": "system", "content": context_text})
|
||||||
|
|
||||||
|
self.messages = messages
|
||||||
|
# ---------------------------------
|
||||||
|
|
||||||
self.log.clear()
|
self.log.clear()
|
||||||
self.scroll = 0
|
self.scroll = 0
|
||||||
self.input_buffer = [""]
|
self.input_buffer = [""]
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user