embedding model default is None
This commit is contained in:
parent
496c828429
commit
a61727bc28
@ -30,8 +30,6 @@ 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_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.
|
# Model Option (moop) — penyimpanan model/provider/key pindah ke sqlite.
|
||||||
moop_db_path = os.path.expanduser(
|
moop_db_path = os.path.expanduser(
|
||||||
|
|||||||
@ -121,11 +121,11 @@ def _uuid(val):
|
|||||||
return uuid.UUID(val) if isinstance(val, str) else val
|
return uuid.UUID(val) if isinstance(val, str) else val
|
||||||
|
|
||||||
def embedding_endpoint():
|
def embedding_endpoint():
|
||||||
"""Endpoint embedding: default chain moop ('embedding') > fallback yaml."""
|
"""Endpoint embedding dari default chain moop ('embedding')."""
|
||||||
ep = moop.embedding_endpoint()
|
ep = moop.embedding_endpoint()
|
||||||
if ep:
|
if ep:
|
||||||
return ep[0], ep[1]
|
return ep[0], ep[1]
|
||||||
return config.ragroleplay_model_url, config.ragroleplay_model_name
|
return None, None
|
||||||
|
|
||||||
def embed_text(url, model, text):
|
def embed_text(url, model, text):
|
||||||
response = requests.post(url=url, json={"model": model, "input": text} )
|
response = requests.post(url=url, json={"model": model, "input": text} )
|
||||||
|
|||||||
@ -4,6 +4,14 @@ from lib import personality
|
|||||||
|
|
||||||
_emb_url, _emb_model = ragroleplay_lib.embedding_endpoint()
|
_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):
|
def _uuid(val):
|
||||||
if isinstance(val, str):
|
if isinstance(val, str):
|
||||||
return uuid.UUID(val)
|
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):
|
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:
|
try:
|
||||||
success = ragroleplay_lib.users_store(
|
success = ragroleplay_lib.users_store(
|
||||||
config.ragroleplay_db_path,
|
config.ragroleplay_db_path,
|
||||||
@ -530,6 +539,7 @@ schema_todos_delete = {
|
|||||||
|
|
||||||
|
|
||||||
def memories_check(prompt_text, search_limit):
|
def memories_check(prompt_text, search_limit):
|
||||||
|
if not _emb_ready(): return _EMB_GUIDANCE
|
||||||
try:
|
try:
|
||||||
db = lancedb.connect(config.ragroleplay_db_path)
|
db = lancedb.connect(config.ragroleplay_db_path)
|
||||||
table = db.open_table("knowledge_memories")
|
table = db.open_table("knowledge_memories")
|
||||||
@ -565,6 +575,7 @@ def memories_check(prompt_text, search_limit):
|
|||||||
return f"Error searching memories: {str(e)}"
|
return f"Error searching memories: {str(e)}"
|
||||||
|
|
||||||
def memories_store(character, user, event, category, detail, physical, emotional):
|
def memories_store(character, user, event, category, detail, physical, emotional):
|
||||||
|
if not _emb_ready(): return _EMB_GUIDANCE
|
||||||
try:
|
try:
|
||||||
success = ragroleplay_lib.memories_store(
|
success = ragroleplay_lib.memories_store(
|
||||||
config.ragroleplay_db_path,
|
config.ragroleplay_db_path,
|
||||||
@ -607,6 +618,7 @@ def memories_filter(category=None, character=None, user=None):
|
|||||||
return f"Error filtering memories: {str(e)}"
|
return f"Error filtering memories: {str(e)}"
|
||||||
|
|
||||||
def memories_summarize(prompt_text, search_limit=5):
|
def memories_summarize(prompt_text, search_limit=5):
|
||||||
|
if not _emb_ready(): return _EMB_GUIDANCE
|
||||||
try:
|
try:
|
||||||
result = ragroleplay_lib.memories_summarize(
|
result = ragroleplay_lib.memories_summarize(
|
||||||
config.ragroleplay_db_path,
|
config.ragroleplay_db_path,
|
||||||
@ -643,6 +655,7 @@ def memories_latest(character, user, limit=3):
|
|||||||
return f"Error retrieving latest memories: {str(e)}"
|
return f"Error retrieving latest memories: {str(e)}"
|
||||||
|
|
||||||
def memories_update(memory_id, **updates):
|
def memories_update(memory_id, **updates):
|
||||||
|
if not _emb_ready(): return _EMB_GUIDANCE
|
||||||
try:
|
try:
|
||||||
success = ragroleplay_lib.memories_update(
|
success = ragroleplay_lib.memories_update(
|
||||||
config.ragroleplay_db_path,
|
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)}"
|
return f"Error filtering users: {str(e)}"
|
||||||
|
|
||||||
def users_update(user_id, **updates):
|
def users_update(user_id, **updates):
|
||||||
|
if not _emb_ready(): return _EMB_GUIDANCE
|
||||||
try:
|
try:
|
||||||
success = ragroleplay_lib.users_update(
|
success = ragroleplay_lib.users_update(
|
||||||
config.ragroleplay_db_path,
|
config.ragroleplay_db_path,
|
||||||
@ -726,6 +740,7 @@ def users_delete(user_id):
|
|||||||
|
|
||||||
# --- OBJECTS IMPLEMENTATION ---
|
# --- OBJECTS IMPLEMENTATION ---
|
||||||
def objects_store(keyword, when, where, name, description, shape, usage):
|
def objects_store(keyword, when, where, name, description, shape, usage):
|
||||||
|
if not _emb_ready(): return _EMB_GUIDANCE
|
||||||
try:
|
try:
|
||||||
success = ragroleplay_lib.objects_store(config.ragroleplay_db_path, _emb_url, _emb_model, keyword, when, where, name, description, shape, usage)
|
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."
|
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)}"
|
except Exception as e: return f"Error: {str(e)}"
|
||||||
|
|
||||||
def objects_update(object_id, **updates):
|
def objects_update(object_id, **updates):
|
||||||
|
if not _emb_ready(): return _EMB_GUIDANCE
|
||||||
try:
|
try:
|
||||||
success = ragroleplay_lib.objects_update(config.ragroleplay_db_path, _emb_url, _emb_model, _uuid(object_id), **updates)
|
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."
|
return "Berhasil memperbarui objek." if success else "Gagal memperbarui objek."
|
||||||
@ -755,6 +771,7 @@ def objects_delete(object_id):
|
|||||||
|
|
||||||
# --- OUTFIT IMPLEMENTATION ---
|
# --- OUTFIT IMPLEMENTATION ---
|
||||||
def outfits_store(keyword, when, outfit):
|
def outfits_store(keyword, when, outfit):
|
||||||
|
if not _emb_ready(): return _EMB_GUIDANCE
|
||||||
try:
|
try:
|
||||||
success = ragroleplay_lib.outfits_store(config.ragroleplay_db_path, _emb_url, _emb_model, keyword, when, outfit)
|
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."
|
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)}"
|
except Exception as e: return f"Error: {str(e)}"
|
||||||
|
|
||||||
def outfits_update(outfit_id, **updates):
|
def outfits_update(outfit_id, **updates):
|
||||||
|
if not _emb_ready(): return _EMB_GUIDANCE
|
||||||
try:
|
try:
|
||||||
success = ragroleplay_lib.outfits_update(config.ragroleplay_db_path, _emb_url, _emb_model, _uuid(outfit_id), **updates)
|
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."
|
return "Berhasil memperbarui outfit." if success else "Gagal memperbarui outfit."
|
||||||
@ -784,6 +802,7 @@ def outfits_delete(outfit_id):
|
|||||||
|
|
||||||
# --- TODO IMPLEMENTATION ---
|
# --- TODO IMPLEMENTATION ---
|
||||||
def todos_store(keyword, when, do):
|
def todos_store(keyword, when, do):
|
||||||
|
if not _emb_ready(): return _EMB_GUIDANCE
|
||||||
try:
|
try:
|
||||||
success = ragroleplay_lib.todos_store(config.ragroleplay_db_path, _emb_url, _emb_model, keyword, when, do)
|
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."
|
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)}"
|
except Exception as e: return f"Error: {str(e)}"
|
||||||
|
|
||||||
def todos_update(todo_id, **updates):
|
def todos_update(todo_id, **updates):
|
||||||
|
if not _emb_ready(): return _EMB_GUIDANCE
|
||||||
try:
|
try:
|
||||||
success = ragroleplay_lib.todos_update(config.ragroleplay_db_path, _emb_url, _emb_model, _uuid(todo_id), **updates)
|
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."
|
return "Berhasil memperbarui to-do." if success else "Gagal memperbarui to-do."
|
||||||
@ -813,6 +833,7 @@ def todos_delete(todo_id):
|
|||||||
|
|
||||||
# --- WORLD IMPLEMENTATION ---
|
# --- WORLD IMPLEMENTATION ---
|
||||||
def worlds_store(category, location, description):
|
def worlds_store(category, location, description):
|
||||||
|
if not _emb_ready(): return _EMB_GUIDANCE
|
||||||
try:
|
try:
|
||||||
success = ragroleplay_lib.worlds_store(config.ragroleplay_db_path, _emb_url, _emb_model, category, location, description)
|
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."
|
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)}"
|
except Exception as e: return f"Error: {str(e)}"
|
||||||
|
|
||||||
def worlds_update(world_id, **updates):
|
def worlds_update(world_id, **updates):
|
||||||
|
if not _emb_ready(): return _EMB_GUIDANCE
|
||||||
try:
|
try:
|
||||||
success = ragroleplay_lib.worlds_update(config.ragroleplay_db_path, _emb_url, _emb_model, _uuid(world_id), **updates)
|
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."
|
return "Berhasil memperbarui lokasi dunia." if success else "Gagal memperbarui lokasi dunia."
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user