embedding model default is None

This commit is contained in:
Dita Aji Pratama 2026-08-15 09:13:28 +07:00
parent 496c828429
commit a61727bc28
3 changed files with 24 additions and 4 deletions

View File

@ -30,8 +30,6 @@ TUI_USER_ID = _yaml_get("user", "id", default=None)
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_model_url = _yaml_get("ragroleplay", "model_url", default="http://localhost:11434/api/embed" )
ragroleplay_model_name = _yaml_get("ragroleplay", "model_name", default="nomic-embed-text" ) # Need to download model from local ollama
# Model Option (moop) — penyimpanan model/provider/key pindah ke sqlite.
moop_db_path = os.path.expanduser(

View File

@ -121,11 +121,11 @@ def _uuid(val):
return uuid.UUID(val) if isinstance(val, str) else val
def embedding_endpoint():
"""Endpoint embedding: default chain moop ('embedding') > fallback yaml."""
"""Endpoint embedding dari default chain moop ('embedding')."""
ep = moop.embedding_endpoint()
if ep:
return ep[0], ep[1]
return config.ragroleplay_model_url, config.ragroleplay_model_name
return None, None
def embed_text(url, model, text):
response = requests.post(url=url, json={"model": model, "input": text} )

View File

@ -4,6 +4,14 @@ from lib import personality
_emb_url, _emb_model = ragroleplay_lib.embedding_endpoint()
_EMB_GUIDANCE = "Ragroleplay butuh embedding model set. Atur dulu di TUI: Model > Manage Sets (Model Option), tipe 'embedding'."
def _emb_ready():
if not _emb_url or not _emb_model:
print(f"[ragroleplay] {_EMB_GUIDANCE}", flush=True)
return False
return True
def _uuid(val):
if isinstance(val, str):
return uuid.UUID(val)
@ -34,6 +42,7 @@ schema_users_store = {
}
def users_store(fullname, nickname, character, id=None, alias=None, salutation=None, persona=None, telegram_id=None, telegram_username=None, xmpp_username=None, familyname=None):
if not _emb_ready(): return _EMB_GUIDANCE
try:
success = ragroleplay_lib.users_store(
config.ragroleplay_db_path,
@ -530,6 +539,7 @@ schema_todos_delete = {
def memories_check(prompt_text, search_limit):
if not _emb_ready(): return _EMB_GUIDANCE
try:
db = lancedb.connect(config.ragroleplay_db_path)
table = db.open_table("knowledge_memories")
@ -565,6 +575,7 @@ def memories_check(prompt_text, search_limit):
return f"Error searching memories: {str(e)}"
def memories_store(character, user, event, category, detail, physical, emotional):
if not _emb_ready(): return _EMB_GUIDANCE
try:
success = ragroleplay_lib.memories_store(
config.ragroleplay_db_path,
@ -607,6 +618,7 @@ def memories_filter(category=None, character=None, user=None):
return f"Error filtering memories: {str(e)}"
def memories_summarize(prompt_text, search_limit=5):
if not _emb_ready(): return _EMB_GUIDANCE
try:
result = ragroleplay_lib.memories_summarize(
config.ragroleplay_db_path,
@ -643,6 +655,7 @@ def memories_latest(character, user, limit=3):
return f"Error retrieving latest memories: {str(e)}"
def memories_update(memory_id, **updates):
if not _emb_ready(): return _EMB_GUIDANCE
try:
success = ragroleplay_lib.memories_update(
config.ragroleplay_db_path,
@ -699,6 +712,7 @@ def user_load(query_name=None, unique_id=None, persona_keyword=None, user_id=Non
return f"Error filtering users: {str(e)}"
def users_update(user_id, **updates):
if not _emb_ready(): return _EMB_GUIDANCE
try:
success = ragroleplay_lib.users_update(
config.ragroleplay_db_path,
@ -726,6 +740,7 @@ def users_delete(user_id):
# --- OBJECTS IMPLEMENTATION ---
def objects_store(keyword, when, where, name, description, shape, usage):
if not _emb_ready(): return _EMB_GUIDANCE
try:
success = ragroleplay_lib.objects_store(config.ragroleplay_db_path, _emb_url, _emb_model, keyword, when, where, name, description, shape, usage)
return "Berhasil menyimpan objek baru." if success else "Gagal menyimpan objek."
@ -742,6 +757,7 @@ def objects_filter(keyword=None, object_id=None):
except Exception as e: return f"Error: {str(e)}"
def objects_update(object_id, **updates):
if not _emb_ready(): return _EMB_GUIDANCE
try:
success = ragroleplay_lib.objects_update(config.ragroleplay_db_path, _emb_url, _emb_model, _uuid(object_id), **updates)
return "Berhasil memperbarui objek." if success else "Gagal memperbarui objek."
@ -755,6 +771,7 @@ def objects_delete(object_id):
# --- OUTFIT IMPLEMENTATION ---
def outfits_store(keyword, when, outfit):
if not _emb_ready(): return _EMB_GUIDANCE
try:
success = ragroleplay_lib.outfits_store(config.ragroleplay_db_path, _emb_url, _emb_model, keyword, when, outfit)
return "Berhasil menyimpan outfit baru." if success else "Gagal menyimpan outfit."
@ -771,6 +788,7 @@ def outfits_filter(keyword=None, outfit_id=None):
except Exception as e: return f"Error: {str(e)}"
def outfits_update(outfit_id, **updates):
if not _emb_ready(): return _EMB_GUIDANCE
try:
success = ragroleplay_lib.outfits_update(config.ragroleplay_db_path, _emb_url, _emb_model, _uuid(outfit_id), **updates)
return "Berhasil memperbarui outfit." if success else "Gagal memperbarui outfit."
@ -784,6 +802,7 @@ def outfits_delete(outfit_id):
# --- TODO IMPLEMENTATION ---
def todos_store(keyword, when, do):
if not _emb_ready(): return _EMB_GUIDANCE
try:
success = ragroleplay_lib.todos_store(config.ragroleplay_db_path, _emb_url, _emb_model, keyword, when, do)
return "Berhasil menyimpan to-do baru." if success else "Gagal menyimpan to-do."
@ -800,6 +819,7 @@ def todos_filter(keyword=None, todo_id=None):
except Exception as e: return f"Error: {str(e)}"
def todos_update(todo_id, **updates):
if not _emb_ready(): return _EMB_GUIDANCE
try:
success = ragroleplay_lib.todos_update(config.ragroleplay_db_path, _emb_url, _emb_model, _uuid(todo_id), **updates)
return "Berhasil memperbarui to-do." if success else "Gagal memperbarui to-do."
@ -813,6 +833,7 @@ def todos_delete(todo_id):
# --- WORLD IMPLEMENTATION ---
def worlds_store(category, location, description):
if not _emb_ready(): return _EMB_GUIDANCE
try:
success = ragroleplay_lib.worlds_store(config.ragroleplay_db_path, _emb_url, _emb_model, category, location, description)
return "Berhasil menyimpan lokasi dunia baru." if success else "Gagal menyimpan lokasi dunia."
@ -829,6 +850,7 @@ def worlds_filter(category=None, location=None, world_id=None):
except Exception as e: return f"Error: {str(e)}"
def worlds_update(world_id, **updates):
if not _emb_ready(): return _EMB_GUIDANCE
try:
success = ragroleplay_lib.worlds_update(config.ragroleplay_db_path, _emb_url, _emb_model, _uuid(world_id), **updates)
return "Berhasil memperbarui lokasi dunia." if success else "Gagal memperbarui lokasi dunia."