ready to use
This commit is contained in:
parent
ac8f37b266
commit
b4a499e12c
@ -1,6 +1,6 @@
|
||||
model_url = "http://localhost:11434/api/embed"
|
||||
model_name = "nomic-embed-text"
|
||||
ragroleplay_db_path = "./ragroleplay"
|
||||
ragroleplay_vector_size = 768 # used on table create only
|
||||
ragroleplay_model_url = "http://localhost:11434/api/embed"
|
||||
ragroleplay_model_name = "nomic-embed-text"
|
||||
|
||||
memories_db_path = "./ragroleplay"
|
||||
memories_vector_size = 768
|
||||
|
||||
|
||||
@ -2,9 +2,9 @@ import gc, sys, lancedb
|
||||
import config, lib.ragroleplay as ragroleplay
|
||||
|
||||
def memories_check(question, search_limit):
|
||||
db = lancedb.connect(config.memories_db_path)
|
||||
db = lancedb.connect(config.ragroleplay_db_path)
|
||||
table = db.open_table("knowledge_memories")
|
||||
query_vector = ragroleplay.embed_text(config.model_url, config.model_name, question)
|
||||
query_vector = ragroleplay.embed_text(config.ragroleplay_model_url, config.ragroleplay_model_name, question)
|
||||
results = table.search(query_vector, vector_column_name="vector_context").limit(search_limit).to_list()
|
||||
|
||||
print("")
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
import config, lib.ragroleplay as ragroleplay
|
||||
text = "Saya lupa password"
|
||||
vector = ragroleplay.embed_text(config.model_url, config.model_name, text)
|
||||
vector = ragroleplay.embed_text(config.ragroleplay_model_url, config.ragroleplay_model_name, text)
|
||||
print("Text:")
|
||||
print(text)
|
||||
print("Vector:")
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import config, lib.ragroleplay as ragroleplay
|
||||
|
||||
if __name__ == "__main__":
|
||||
ragroleplay.create_table(config.memories_db_path, config.memories_vector_size)
|
||||
ragroleplay.create_table(config.ragroleplay_db_path, config.ragroleplay_vector_size)
|
||||
|
||||
@ -3,7 +3,7 @@ from datetime import datetime, timedelta
|
||||
import config, lib.ragroleplay as ragroleplay
|
||||
|
||||
def main():
|
||||
db = lancedb.connect(config.memories_db_path)
|
||||
db = lancedb.connect(config.ragroleplay_db_path)
|
||||
table = db.open_table("knowledge_memories")
|
||||
now = datetime.now()
|
||||
|
||||
@ -121,7 +121,7 @@ def main():
|
||||
"detail": mem["detail"],
|
||||
"physical": mem["physical"],
|
||||
"emotional": mem["emotional"],
|
||||
"vector_context": ragroleplay.embed_text(config.model_url, config.model_name, context_text),
|
||||
"vector_context": ragroleplay.embed_text(config.ragroleplay_model_url, config.ragroleplay_model_name, context_text),
|
||||
}
|
||||
table.add([row])
|
||||
print(f"Menambahkan memori: {mem['event']}")
|
||||
|
||||
@ -461,9 +461,9 @@ schema_todos_delete = {
|
||||
|
||||
def memories_check(prompt_text, search_limit):
|
||||
try:
|
||||
db = lancedb.connect(config.memories_db_path)
|
||||
db = lancedb.connect(config.ragroleplay_db_path)
|
||||
table = db.open_table("knowledge_memories")
|
||||
query_vector = ragroleplay_lib.embed_text(config.model_url, config.model_name, prompt_text)
|
||||
query_vector = ragroleplay_lib.embed_text(config.ragroleplay_model_url, config.ragroleplay_model_name, prompt_text)
|
||||
results = table.search(query_vector, vector_column_name="vector_context").limit(search_limit).to_list()
|
||||
|
||||
if not results:
|
||||
@ -498,9 +498,9 @@ def memories_check(prompt_text, search_limit):
|
||||
def memories_store(character, user, relative_time, event, category, detail, physical, emotional):
|
||||
try:
|
||||
success = ragroleplay_lib.memories_store(
|
||||
config.memories_db_path,
|
||||
config.model_url,
|
||||
config.model_name,
|
||||
config.ragroleplay_db_path,
|
||||
config.ragroleplay_model_url,
|
||||
config.ragroleplay_model_name,
|
||||
character,
|
||||
user,
|
||||
relative_time,
|
||||
@ -519,7 +519,7 @@ def memories_store(character, user, relative_time, event, category, detail, phys
|
||||
|
||||
def memories_filter(category=None, character=None, user=None):
|
||||
try:
|
||||
results = ragroleplay_lib.memories_filter(config.memories_db_path, category, character, user)
|
||||
results = ragroleplay_lib.memories_filter(config.ragroleplay_db_path, category, character, user)
|
||||
if not results:
|
||||
return "Tidak ada memori yang sesuai dengan filter tersebut."
|
||||
|
||||
@ -542,10 +542,10 @@ def memories_filter(category=None, character=None, user=None):
|
||||
def memories_summarize(prompt_text, search_limit=5):
|
||||
try:
|
||||
result = ragroleplay_lib.memories_summarize(
|
||||
config.memories_db_path,
|
||||
config.ragroleplay_db_path,
|
||||
prompt_text,
|
||||
config.model_url,
|
||||
config.model_name,
|
||||
config.ragroleplay_model_url,
|
||||
config.ragroleplay_model_name,
|
||||
search_limit
|
||||
)
|
||||
return result
|
||||
@ -555,9 +555,9 @@ def memories_summarize(prompt_text, search_limit=5):
|
||||
def memories_update(memory_id, **updates):
|
||||
try:
|
||||
success = ragroleplay_lib.memories_update(
|
||||
config.memories_db_path,
|
||||
config.model_url,
|
||||
config.model_name,
|
||||
config.ragroleplay_db_path,
|
||||
config.ragroleplay_model_url,
|
||||
config.ragroleplay_model_name,
|
||||
memory_id,
|
||||
**updates
|
||||
)
|
||||
@ -570,7 +570,7 @@ def memories_update(memory_id, **updates):
|
||||
|
||||
def memories_delete(memory_id):
|
||||
try:
|
||||
success = ragroleplay_lib.memories_delete(config.memories_db_path, memory_id)
|
||||
success = ragroleplay_lib.memories_delete(config.ragroleplay_db_path, memory_id)
|
||||
if success:
|
||||
return "Berhasil menghapus memori dari database."
|
||||
else:
|
||||
@ -581,9 +581,9 @@ def memories_delete(memory_id):
|
||||
def users_store(fullname, nickname, alias=None, persona=None, telegram_id=None, telegram_username=None, xampp_username=None):
|
||||
try:
|
||||
success = ragroleplay_lib.users_store(
|
||||
config.memories_db_path,
|
||||
config.model_url,
|
||||
config.model_name,
|
||||
config.ragroleplay_db_path,
|
||||
config.ragroleplay_model_url,
|
||||
config.ragroleplay_model_name,
|
||||
fullname,
|
||||
nickname,
|
||||
alias,
|
||||
@ -601,7 +601,7 @@ def users_store(fullname, nickname, alias=None, persona=None, telegram_id=None,
|
||||
|
||||
def users_filter(query_name=None, unique_id=None, persona_keyword=None, user_id=None):
|
||||
try:
|
||||
results = ragroleplay_lib.users_filter(config.memories_db_path, query_name, unique_id, persona_keyword, user_id)
|
||||
results = ragroleplay_lib.users_filter(config.ragroleplay_db_path, query_name, unique_id, persona_keyword, user_id)
|
||||
if not results:
|
||||
return "Tidak ada user yang sesuai dengan filter tersebut."
|
||||
|
||||
@ -623,9 +623,9 @@ def users_filter(query_name=None, unique_id=None, persona_keyword=None, user_id=
|
||||
def users_update(user_id, **updates):
|
||||
try:
|
||||
success = ragroleplay_lib.users_update(
|
||||
config.memories_db_path,
|
||||
config.model_url,
|
||||
config.model_name,
|
||||
config.ragroleplay_db_path,
|
||||
config.ragroleplay_model_url,
|
||||
config.ragroleplay_model_name,
|
||||
user_id,
|
||||
**updates
|
||||
)
|
||||
@ -638,7 +638,7 @@ def users_update(user_id, **updates):
|
||||
|
||||
def users_delete(user_id):
|
||||
try:
|
||||
success = ragroleplay_lib.users_delete(config.memories_db_path, user_id)
|
||||
success = ragroleplay_lib.users_delete(config.ragroleplay_db_path, user_id)
|
||||
if success:
|
||||
return "Berhasil menghapus profil user."
|
||||
else:
|
||||
@ -649,13 +649,13 @@ def users_delete(user_id):
|
||||
# --- OBJECTS IMPLEMENTATION ---
|
||||
def objects_store(keyword, when, where, name, description, shape, usage):
|
||||
try:
|
||||
success = ragroleplay_lib.objects_store(config.memories_db_path, config.model_url, config.model_name, keyword, when, where, name, description, shape, usage)
|
||||
success = ragroleplay_lib.objects_store(config.ragroleplay_db_path, config.ragroleplay_model_url, config.ragroleplay_model_name, keyword, when, where, name, description, shape, usage)
|
||||
return "Berhasil menyimpan objek baru." if success else "Gagal menyimpan objek."
|
||||
except Exception as e: return f"Error: {str(e)}"
|
||||
|
||||
def objects_filter(keyword=None, object_id=None):
|
||||
try:
|
||||
results = ragroleplay_lib.objects_filter(config.memories_db_path, keyword, object_id)
|
||||
results = ragroleplay_lib.objects_filter(config.ragroleplay_db_path, keyword, object_id)
|
||||
if not results: return "Tidak ada objek yang ditemukan."
|
||||
output = [f"Ditemukan {len(results)} objek:"]
|
||||
for i, row in enumerate(results, 1):
|
||||
@ -665,26 +665,26 @@ def objects_filter(keyword=None, object_id=None):
|
||||
|
||||
def objects_update(object_id, **updates):
|
||||
try:
|
||||
success = ragroleplay_lib.objects_update(config.memories_db_path, config.model_url, config.model_name, object_id, **updates)
|
||||
success = ragroleplay_lib.objects_update(config.ragroleplay_db_path, config.ragroleplay_model_url, config.ragroleplay_model_name, object_id, **updates)
|
||||
return "Berhasil memperbarui objek." if success else "Gagal memperbarui objek."
|
||||
except Exception as e: return f"Error: {str(e)}"
|
||||
|
||||
def objects_delete(object_id):
|
||||
try:
|
||||
success = ragroleplay_lib.objects_delete(config.memories_db_path, object_id)
|
||||
success = ragroleplay_lib.objects_delete(config.ragroleplay_db_path, object_id)
|
||||
return "Berhasil menghapus objek." if success else "Gagal menghapus objek."
|
||||
except Exception as e: return f"Error: {str(e)}"
|
||||
|
||||
# --- OUTFIT IMPLEMENTATION ---
|
||||
def outfits_store(keyword, when, outfit):
|
||||
try:
|
||||
success = ragroleplay_lib.outfits_store(config.memories_db_path, config.model_url, config.model_name, keyword, when, outfit)
|
||||
success = ragroleplay_lib.outfits_store(config.ragroleplay_db_path, config.ragroleplay_model_url, config.ragroleplay_model_name, keyword, when, outfit)
|
||||
return "Berhasil menyimpan outfit baru." if success else "Gagal menyimpan outfit."
|
||||
except Exception as e: return f"Error: {str(e)}"
|
||||
|
||||
def outfits_filter(keyword=None, outfit_id=None):
|
||||
try:
|
||||
results = ragroleplay_lib.outfits_filter(config.memories_db_path, keyword, outfit_id)
|
||||
results = ragroleplay_lib.outfits_filter(config.ragroleplay_db_path, keyword, outfit_id)
|
||||
if not results: return "Tidak ada outfit yang ditemukan."
|
||||
output = [f"Ditemukan {len(results)} outfit:"]
|
||||
for i, row in enumerate(results, 1):
|
||||
@ -694,26 +694,26 @@ def outfits_filter(keyword=None, outfit_id=None):
|
||||
|
||||
def outfits_update(outfit_id, **updates):
|
||||
try:
|
||||
success = ragroleplay_lib.outfits_update(config.memories_db_path, config.model_url, config.model_name, outfit_id, **updates)
|
||||
success = ragroleplay_lib.outfits_update(config.ragroleplay_db_path, config.ragroleplay_model_url, config.ragroleplay_model_name, outfit_id, **updates)
|
||||
return "Berhasil memperbarui outfit." if success else "Gagal memperbarui outfit."
|
||||
except Exception as e: return f"Error: {str(e)}"
|
||||
|
||||
def outfits_delete(outfit_id):
|
||||
try:
|
||||
success = ragroleplay_lib.outfits_delete(config.memories_db_path, outfit_id)
|
||||
success = ragroleplay_lib.outfits_delete(config.ragroleplay_db_path, outfit_id)
|
||||
return "Berhasil menghapus outfit." if success else "Gagal menghapus outfit."
|
||||
except Exception as e: return f"Error: {str(e)}"
|
||||
|
||||
# --- TODO IMPLEMENTATION ---
|
||||
def todos_store(keyword, when, do):
|
||||
try:
|
||||
success = ragroleplay_lib.todos_store(config.memories_db_path, config.model_url, config.model_name, keyword, when, do)
|
||||
success = ragroleplay_lib.todos_store(config.ragroleplay_db_path, config.ragroleplay_model_url, config.ragroleplay_model_name, keyword, when, do)
|
||||
return "Berhasil menyimpan to-do baru." if success else "Gagal menyimpan to-do."
|
||||
except Exception as e: return f"Error: {str(e)}"
|
||||
|
||||
def todos_filter(keyword=None, todo_id=None):
|
||||
try:
|
||||
results = ragroleplay_lib.todos_filter(config.memories_db_path, keyword, todo_id)
|
||||
results = ragroleplay_lib.todos_filter(config.ragroleplay_db_path, keyword, todo_id)
|
||||
if not results: return "Tidak ada to-do yang ditemukan."
|
||||
output = [f"Ditemukan {len(results)} to-do:"]
|
||||
for i, row in enumerate(results, 1):
|
||||
@ -723,26 +723,26 @@ def todos_filter(keyword=None, todo_id=None):
|
||||
|
||||
def todos_update(todo_id, **updates):
|
||||
try:
|
||||
success = ragroleplay_lib.todos_update(config.memories_db_path, config.model_url, config.model_name, todo_id, **updates)
|
||||
success = ragroleplay_lib.todos_update(config.ragroleplay_db_path, config.ragroleplay_model_url, config.ragroleplay_model_name, todo_id, **updates)
|
||||
return "Berhasil memperbarui to-do." if success else "Gagal memperbarui to-do."
|
||||
except Exception as e: return f"Error: {str(e)}"
|
||||
|
||||
def todos_delete(todo_id):
|
||||
try:
|
||||
success = ragroleplay_lib.todos_delete(config.memories_db_path, todo_id)
|
||||
success = ragroleplay_lib.todos_delete(config.ragroleplay_db_path, todo_id)
|
||||
return "Berhasil menghapus to-do." if success else "Gagal menghapus to-do."
|
||||
except Exception as e: return f"Error: {str(e)}"
|
||||
|
||||
# --- WORLD IMPLEMENTATION ---
|
||||
def worlds_store(category, location, description):
|
||||
try:
|
||||
success = ragroleplay_lib.worlds_store(config.memories_db_path, config.model_url, config.model_name, category, location, description)
|
||||
success = ragroleplay_lib.worlds_store(config.ragroleplay_db_path, config.ragroleplay_model_url, config.ragroleplay_model_name, category, location, description)
|
||||
return "Berhasil menyimpan lokasi dunia baru." if success else "Gagal menyimpan lokasi dunia."
|
||||
except Exception as e: return f"Error: {str(e)}"
|
||||
|
||||
def worlds_filter(category=None, location=None, world_id=None):
|
||||
try:
|
||||
results = ragroleplay_lib.worlds_filter(config.memories_db_path, category, location, world_id)
|
||||
results = ragroleplay_lib.worlds_filter(config.ragroleplay_db_path, category, location, world_id)
|
||||
if not results: return "Tidak ada lokasi dunia yang ditemukan."
|
||||
output = [f"Ditemukan {len(results)} lokasi:"]
|
||||
for i, row in enumerate(results, 1):
|
||||
@ -752,12 +752,12 @@ def worlds_filter(category=None, location=None, world_id=None):
|
||||
|
||||
def worlds_update(world_id, **updates):
|
||||
try:
|
||||
success = ragroleplay_lib.worlds_update(config.memories_db_path, config.model_url, config.model_name, world_id, **updates)
|
||||
success = ragroleplay_lib.worlds_update(config.ragroleplay_db_path, config.ragroleplay_model_url, config.ragroleplay_model_name, world_id, **updates)
|
||||
return "Berhasil memperbarui lokasi dunia." if success else "Gagal memperbarui lokasi dunia."
|
||||
except Exception as e: return f"Error: {str(e)}"
|
||||
|
||||
def worlds_delete(world_id):
|
||||
try:
|
||||
success = ragroleplay_lib.worlds_delete(config.memories_db_path, world_id)
|
||||
success = ragroleplay_lib.worlds_delete(config.ragroleplay_db_path, world_id)
|
||||
return "Berhasil menghapus lokasi dunia." if success else "Gagal menghapus lokasi dunia."
|
||||
except Exception as e: return f"Error: {str(e)}"
|
||||
|
||||
Loading…
Reference in New Issue
Block a user