Rapihin pelan-pelan sambil kasih catatan
This commit is contained in:
parent
dba98e6fd8
commit
41669d4909
79
hendrik.py
79
hendrik.py
@ -19,45 +19,54 @@ from interfaces.tui import HendrikTUI
|
|||||||
tools_definition = [
|
tools_definition = [
|
||||||
|
|
||||||
# Coder Tools
|
# Coder Tools
|
||||||
gadget.tools_mapping( schema = coder.schema_read_file, handler = coder.read_file ),
|
gadget.tools_mapping( schema = coder.schema_read_file, handler = coder.read_file ),
|
||||||
gadget.tools_mapping( schema = coder.schema_write_file, handler = coder.write_file ),
|
gadget.tools_mapping( schema = coder.schema_write_file, handler = coder.write_file ),
|
||||||
gadget.tools_mapping( schema = coder.schema_edit_file, handler = coder.edit_file ),
|
gadget.tools_mapping( schema = coder.schema_edit_file, handler = coder.edit_file ),
|
||||||
gadget.tools_mapping( schema = coder.schema_run_bash, handler = coder.run_bash ),
|
|
||||||
gadget.tools_mapping( schema = coder.schema_search_code, handler = coder.search_code ),
|
gadget.tools_mapping( schema = coder.schema_run_bash, handler = coder.run_bash ),
|
||||||
gadget.tools_mapping( schema = coder.schema_git_operation, handler = coder.git_operation ),
|
|
||||||
|
gadget.tools_mapping( schema = coder.schema_search_code, handler = coder.search_code ),
|
||||||
|
|
||||||
|
gadget.tools_mapping( schema = coder.schema_git_operation, handler = coder.git_operation ),
|
||||||
|
|
||||||
# Carrack Tools
|
# Carrack Tools
|
||||||
gadget.tools_mapping( schema = carrack.schema_sendhttprequest, handler = carrack.sendhttprequest ),
|
gadget.tools_mapping( schema = carrack.schema_sendhttprequest, handler = carrack.sendhttprequest ),
|
||||||
|
|
||||||
# Rag Roleplay Tools
|
# Rag Roleplay Tools
|
||||||
gadget.tools_mapping( schema = ragroleplay.schema_users_store, handler = ragroleplay.users_store ),
|
gadget.tools_mapping( schema = ragroleplay.schema_users_store, handler = ragroleplay.users_store ),
|
||||||
gadget.tools_mapping( schema = ragroleplay.schema_user_load, handler = ragroleplay.user_load ),
|
gadget.tools_mapping( schema = ragroleplay.schema_user_load, handler = ragroleplay.user_load ), # s_load
|
||||||
gadget.tools_mapping( schema = ragroleplay.schema_users_update, handler = ragroleplay.users_update ),
|
gadget.tools_mapping( schema = ragroleplay.schema_users_update, handler = ragroleplay.users_update ),
|
||||||
gadget.tools_mapping( schema = ragroleplay.schema_users_delete, handler = ragroleplay.users_delete ),
|
gadget.tools_mapping( schema = ragroleplay.schema_users_delete, handler = ragroleplay.users_delete ),
|
||||||
gadget.tools_mapping( schema = ragroleplay.schema_memories_check, handler = ragroleplay.memories_check ),
|
|
||||||
gadget.tools_mapping( schema = ragroleplay.schema_memories_store, handler = ragroleplay.memories_store ),
|
gadget.tools_mapping( schema = ragroleplay.schema_memories_summarize, handler = ragroleplay.memories_summarize ),
|
||||||
gadget.tools_mapping( schema = ragroleplay.schema_memories_filter, handler = ragroleplay.memories_filter ),
|
gadget.tools_mapping( schema = ragroleplay.schema_memories_store, handler = ragroleplay.memories_store ),
|
||||||
gadget.tools_mapping( schema = ragroleplay.schema_memories_summarize, handler = ragroleplay.memories_summarize ),
|
gadget.tools_mapping( schema = ragroleplay.schema_memories_latest, handler = ragroleplay.memories_latest ), # _load_latest
|
||||||
gadget.tools_mapping( schema = ragroleplay.schema_memories_latest, handler = ragroleplay.memories_latest ),
|
gadget.tools_mapping( schema = ragroleplay.schema_memories_filter, handler = ragroleplay.memories_filter ), # _load
|
||||||
gadget.tools_mapping( schema = ragroleplay.schema_memories_update, handler = ragroleplay.memories_update ),
|
gadget.tools_mapping( schema = ragroleplay.schema_memories_check, handler = ragroleplay.memories_check ), # ?
|
||||||
gadget.tools_mapping( schema = ragroleplay.schema_memories_delete, handler = ragroleplay.memories_delete ),
|
gadget.tools_mapping( schema = ragroleplay.schema_memories_update, handler = ragroleplay.memories_update ),
|
||||||
gadget.tools_mapping( schema = ragroleplay.schema_worlds_store, handler = ragroleplay.worlds_store ),
|
gadget.tools_mapping( schema = ragroleplay.schema_memories_delete, handler = ragroleplay.memories_delete ),
|
||||||
gadget.tools_mapping( schema = ragroleplay.schema_worlds_filter, handler = ragroleplay.worlds_filter ),
|
|
||||||
gadget.tools_mapping( schema = ragroleplay.schema_worlds_update, handler = ragroleplay.worlds_update ),
|
gadget.tools_mapping( schema = ragroleplay.schema_worlds_store, handler = ragroleplay.worlds_store ),
|
||||||
gadget.tools_mapping( schema = ragroleplay.schema_worlds_delete, handler = ragroleplay.worlds_delete ),
|
gadget.tools_mapping( schema = ragroleplay.schema_worlds_filter, handler = ragroleplay.worlds_filter ),
|
||||||
gadget.tools_mapping( schema = ragroleplay.schema_objects_store, handler = ragroleplay.objects_store ),
|
gadget.tools_mapping( schema = ragroleplay.schema_worlds_update, handler = ragroleplay.worlds_update ),
|
||||||
gadget.tools_mapping( schema = ragroleplay.schema_objects_filter, handler = ragroleplay.objects_filter ),
|
gadget.tools_mapping( schema = ragroleplay.schema_worlds_delete, handler = ragroleplay.worlds_delete ),
|
||||||
gadget.tools_mapping( schema = ragroleplay.schema_objects_update, handler = ragroleplay.objects_update ),
|
|
||||||
gadget.tools_mapping( schema = ragroleplay.schema_objects_delete, handler = ragroleplay.objects_delete ),
|
gadget.tools_mapping( schema = ragroleplay.schema_objects_store, handler = ragroleplay.objects_store ),
|
||||||
gadget.tools_mapping( schema = ragroleplay.schema_outfits_store, handler = ragroleplay.outfits_store ),
|
gadget.tools_mapping( schema = ragroleplay.schema_objects_filter, handler = ragroleplay.objects_filter ),
|
||||||
gadget.tools_mapping( schema = ragroleplay.schema_outfits_filter, handler = ragroleplay.outfits_filter ),
|
gadget.tools_mapping( schema = ragroleplay.schema_objects_update, handler = ragroleplay.objects_update ),
|
||||||
gadget.tools_mapping( schema = ragroleplay.schema_outfits_update, handler = ragroleplay.outfits_update ),
|
gadget.tools_mapping( schema = ragroleplay.schema_objects_delete, handler = ragroleplay.objects_delete ),
|
||||||
gadget.tools_mapping( schema = ragroleplay.schema_outfits_delete, handler = ragroleplay.outfits_delete ),
|
|
||||||
gadget.tools_mapping( schema = ragroleplay.schema_todos_store, handler = ragroleplay.todos_store ),
|
gadget.tools_mapping( schema = ragroleplay.schema_outfits_store, handler = ragroleplay.outfits_store ),
|
||||||
gadget.tools_mapping( schema = ragroleplay.schema_todos_filter, handler = ragroleplay.todos_filter ),
|
gadget.tools_mapping( schema = ragroleplay.schema_outfits_filter, handler = ragroleplay.outfits_filter ),
|
||||||
gadget.tools_mapping( schema = ragroleplay.schema_todos_update, handler = ragroleplay.todos_update ),
|
gadget.tools_mapping( schema = ragroleplay.schema_outfits_update, handler = ragroleplay.outfits_update ),
|
||||||
gadget.tools_mapping( schema = ragroleplay.schema_todos_delete, handler = ragroleplay.todos_delete ),
|
gadget.tools_mapping( schema = ragroleplay.schema_outfits_delete, handler = ragroleplay.outfits_delete ),
|
||||||
gadget.tools_mapping( schema = ragroleplay.schema_end_session, handler = ragroleplay.end_session ),
|
|
||||||
|
gadget.tools_mapping( schema = ragroleplay.schema_todos_store, handler = ragroleplay.todos_store ),
|
||||||
|
gadget.tools_mapping( schema = ragroleplay.schema_todos_filter, handler = ragroleplay.todos_filter ),
|
||||||
|
gadget.tools_mapping( schema = ragroleplay.schema_todos_update, handler = ragroleplay.todos_update ),
|
||||||
|
gadget.tools_mapping( schema = ragroleplay.schema_todos_delete, handler = ragroleplay.todos_delete ),
|
||||||
|
|
||||||
|
gadget.tools_mapping( schema = ragroleplay.schema_end_session, handler = ragroleplay.end_session ),
|
||||||
|
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|||||||
@ -5,7 +5,7 @@ def _schema_user(vector_size):
|
|||||||
return pyarrow.schema([
|
return pyarrow.schema([
|
||||||
pyarrow.field('id', pyarrow.uuid(), metadata={'description': 'Unique identifier (UUID)'}),
|
pyarrow.field('id', pyarrow.uuid(), metadata={'description': 'Unique identifier (UUID)'}),
|
||||||
pyarrow.field('timestamp', pyarrow.timestamp('ms'), metadata={'description': 'When record created'}),
|
pyarrow.field('timestamp', pyarrow.timestamp('ms'), metadata={'description': 'When record created'}),
|
||||||
pyarrow.field('character', pyarrow.string(), nullable=True, metadata={'description': 'Active Character'}),
|
pyarrow.field('character', pyarrow.string(), nullable=True, metadata={'description': 'Active Character'}), # Seharusnya WAJIB, GAK BOLEH NULL
|
||||||
pyarrow.field('fullname', pyarrow.string(), metadata={'description': 'Fullname'}),
|
pyarrow.field('fullname', pyarrow.string(), metadata={'description': 'Fullname'}),
|
||||||
pyarrow.field('nickname', pyarrow.string(), metadata={'description': 'Nickname'}),
|
pyarrow.field('nickname', pyarrow.string(), metadata={'description': 'Nickname'}),
|
||||||
pyarrow.field('familyname', pyarrow.string(), nullable=True, metadata={'description': 'Family/clan name'}),
|
pyarrow.field('familyname', pyarrow.string(), nullable=True, metadata={'description': 'Family/clan name'}),
|
||||||
@ -96,24 +96,18 @@ _TABLE_SCHEMAS = {
|
|||||||
'knowledge_world': _schema_world,
|
'knowledge_world': _schema_world,
|
||||||
'knowledge_object': _schema_object,
|
'knowledge_object': _schema_object,
|
||||||
}
|
}
|
||||||
|
def init_db(db_path, vector_size): # db_init seharusnya
|
||||||
|
db = lancedb.connect(db_path)
|
||||||
# ─── Table Management ─────────────────────────────────────────────────────────
|
existing = db.table_names()
|
||||||
|
|
||||||
def init_db(db_path, vector_size):
|
|
||||||
db = lancedb.connect(db_path)
|
|
||||||
existing = db.table_names()
|
|
||||||
for name, schema_fn in _TABLE_SCHEMAS.items():
|
for name, schema_fn in _TABLE_SCHEMAS.items():
|
||||||
if name not in existing:
|
if name not in existing:
|
||||||
db.create_table(name, schema=schema_fn(vector_size))
|
db.create_table(name, schema=schema_fn(vector_size))
|
||||||
print(f"[ragroleplay] Created table: {name}", flush=True)
|
print(f"[ragroleplay] Created table: {name}", flush=True)
|
||||||
del db
|
del db
|
||||||
gc.collect()
|
gc.collect()
|
||||||
|
def ensure_table(db_path, table_name, vector_size): # table_ensure seharusnya
|
||||||
|
db = lancedb.connect(db_path)
|
||||||
def ensure_table(db_path, table_name, vector_size):
|
existing = db.table_names()
|
||||||
db = lancedb.connect(db_path)
|
|
||||||
existing = db.table_names()
|
|
||||||
if table_name not in existing:
|
if table_name not in existing:
|
||||||
schema_fn = _TABLE_SCHEMAS.get(table_name)
|
schema_fn = _TABLE_SCHEMAS.get(table_name)
|
||||||
if schema_fn:
|
if schema_fn:
|
||||||
|
|||||||
@ -2,12 +2,61 @@ import gc, sys, uuid, lancedb
|
|||||||
import config, lib.ragroleplay as ragroleplay_lib
|
import config, lib.ragroleplay as ragroleplay_lib
|
||||||
from lib import personality
|
from lib import personality
|
||||||
|
|
||||||
|
|
||||||
def _uuid(val):
|
def _uuid(val):
|
||||||
if isinstance(val, str):
|
if isinstance(val, str):
|
||||||
return uuid.UUID(val)
|
return uuid.UUID(val)
|
||||||
return val
|
return val
|
||||||
|
|
||||||
|
schema_users_store = {
|
||||||
|
"type" : "function",
|
||||||
|
"function" : {
|
||||||
|
"name" : "users_store",
|
||||||
|
"description" : "Create and store a new user profile in the knowledge database.",
|
||||||
|
"parameters" : {
|
||||||
|
"type" : "object",
|
||||||
|
"properties" : {
|
||||||
|
"fullname" : {"type": "string", "description": "Full name of the user"},
|
||||||
|
"nickname" : {"type": "string", "description": "Nickname of the user"},
|
||||||
|
"familyname" : {"type": "string", "description": "Family/clan name"},
|
||||||
|
"alias" : {"type": "string", "description": "Alias of the user"},
|
||||||
|
"salutation" : {"type": "string", "description": "How to address/greet the user (e.g., Mr, Mrs, Mas, Mbak, Kak)"},
|
||||||
|
"character" : {"type": "string", "description": "Active character interacting with this user"},
|
||||||
|
"persona" : {"type": "string", "description": "Detailed persona or description of the user"},
|
||||||
|
"telegram_id" : {"type": "string", "description": "Telegram user ID"},
|
||||||
|
"telegram_username" : {"type": "string", "description": "Telegram username"},
|
||||||
|
"xampp_username" : {"type": "string", "description": "XAMPP username"}
|
||||||
|
},
|
||||||
|
"required": ["fullname", "nickname", "character", "telegram_id"]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
def users_store(fullname, nickname, alias=None, salutation=None, persona=None, telegram_id=None, telegram_username=None, xampp_username=None, familyname=None, character=None):
|
||||||
|
if not character:
|
||||||
|
character = personality.PERSONALITY.name
|
||||||
|
try:
|
||||||
|
success = ragroleplay_lib.users_store(
|
||||||
|
config.ragroleplay_db_path,
|
||||||
|
config.ragroleplay_model_url,
|
||||||
|
config.ragroleplay_model_name,
|
||||||
|
fullname,
|
||||||
|
nickname,
|
||||||
|
alias,
|
||||||
|
salutation,
|
||||||
|
persona,
|
||||||
|
telegram_id,
|
||||||
|
telegram_username,
|
||||||
|
xampp_username,
|
||||||
|
familyname,
|
||||||
|
character
|
||||||
|
)
|
||||||
|
if success:
|
||||||
|
return "Berhasil menyimpan profil user baru."
|
||||||
|
else:
|
||||||
|
return "Gagal menyimpan profil user."
|
||||||
|
except Exception as e:
|
||||||
|
return f"Error while storing user: {str(e)}"
|
||||||
|
|
||||||
# --- SESSION TOOLS ---
|
# --- SESSION TOOLS ---
|
||||||
schema_end_session = {
|
schema_end_session = {
|
||||||
"type": "function",
|
"type": "function",
|
||||||
@ -22,30 +71,7 @@ schema_end_session = {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
# --- USER TOOLS ---
|
|
||||||
schema_users_store = {
|
|
||||||
"type": "function",
|
|
||||||
"function": {
|
|
||||||
"name": "users_store",
|
|
||||||
"description": "Create and store a new user profile in the knowledge database.",
|
|
||||||
"parameters": {
|
|
||||||
"type": "object",
|
|
||||||
"properties": {
|
|
||||||
"fullname": {"type": "string", "description": "Full name of the user"},
|
|
||||||
"nickname": {"type": "string", "description": "Nickname of the user"},
|
|
||||||
"familyname": {"type": "string", "description": "Family/clan name"},
|
|
||||||
"alias": {"type": "string", "description": "Alias of the user"},
|
|
||||||
"salutation": {"type": "string", "description": "How to address/greet the user (e.g., Mas, Mbak, Kak)"},
|
|
||||||
"character": {"type": "string", "description": "Active character interacting with this user"},
|
|
||||||
"persona": {"type": "string", "description": "Detailed persona or description of the user"},
|
|
||||||
"telegram_id": {"type": "string", "description": "Telegram user ID"},
|
|
||||||
"telegram_username": {"type": "string", "description": "Telegram username"},
|
|
||||||
"xampp_username": {"type": "string", "description": "XAMPP username"}
|
|
||||||
},
|
|
||||||
"required": ["fullname", "nickname", "telegram_id"]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
schema_user_load = {
|
schema_user_load = {
|
||||||
"type": "function",
|
"type": "function",
|
||||||
@ -639,31 +665,7 @@ def memories_delete(memory_id):
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
return f"Error while deleting memory: {str(e)}"
|
return f"Error while deleting memory: {str(e)}"
|
||||||
|
|
||||||
def users_store(fullname, nickname, alias=None, salutation=None, persona=None, telegram_id=None, telegram_username=None, xampp_username=None, familyname=None, character=None):
|
|
||||||
if not character:
|
|
||||||
character = personality.PERSONALITY.name
|
|
||||||
try:
|
|
||||||
success = ragroleplay_lib.users_store(
|
|
||||||
config.ragroleplay_db_path,
|
|
||||||
config.ragroleplay_model_url,
|
|
||||||
config.ragroleplay_model_name,
|
|
||||||
fullname,
|
|
||||||
nickname,
|
|
||||||
alias,
|
|
||||||
salutation,
|
|
||||||
persona,
|
|
||||||
telegram_id,
|
|
||||||
telegram_username,
|
|
||||||
xampp_username,
|
|
||||||
familyname,
|
|
||||||
character
|
|
||||||
)
|
|
||||||
if success:
|
|
||||||
return "Berhasil menyimpan profil user baru."
|
|
||||||
else:
|
|
||||||
return "Gagal menyimpan profil user."
|
|
||||||
except Exception as e:
|
|
||||||
return f"Error while storing user: {str(e)}"
|
|
||||||
|
|
||||||
def user_load(query_name=None, unique_id=None, persona_keyword=None, user_id=None, character=None):
|
def user_load(query_name=None, unique_id=None, persona_keyword=None, user_id=None, character=None):
|
||||||
try:
|
try:
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user