New fields
This commit is contained in:
parent
2da4fe26c4
commit
96993adaee
@ -1,15 +1,14 @@
|
||||
import requests, gc, lancedb, pyarrow, uuid
|
||||
from datetime import datetime
|
||||
|
||||
|
||||
# ─── Table Schemas ────────────────────────────────────────────────────────────
|
||||
|
||||
def _schema_user(vector_size):
|
||||
return pyarrow.schema([
|
||||
pyarrow.field('id', pyarrow.uuid(), metadata={'description': 'Unique identifier (UUID)'}),
|
||||
pyarrow.field('timestamp', pyarrow.timestamp('ms'), metadata={'description': 'When record created'}),
|
||||
pyarrow.field('character', pyarrow.string(), nullable=True, metadata={'description': 'Active Character'}),
|
||||
pyarrow.field('fullname', pyarrow.string(), metadata={'description': 'Fullname'}),
|
||||
pyarrow.field('nickname', pyarrow.string(), metadata={'description': 'Nickname'}),
|
||||
pyarrow.field('familyname', pyarrow.string(), nullable=True, metadata={'description': 'Family/clan name'}),
|
||||
pyarrow.field('alias', pyarrow.string(), nullable=True, metadata={'description': 'Another call name'}),
|
||||
pyarrow.field('salutation', pyarrow.string(), nullable=True, metadata={'description': 'Salutation/greeting for the user'}),
|
||||
pyarrow.field('persona', pyarrow.string(), nullable=True, metadata={'description': 'Persona'}),
|
||||
@ -133,7 +132,7 @@ def embed_text(url, model, text):
|
||||
data = response.json()
|
||||
return data["embeddings"][0]
|
||||
|
||||
def users_store(db_path, model_url, model_name, fullname, nickname, alias, salutation, persona, telegram_id, telegram_username, xampp_username):
|
||||
def users_store(db_path, model_url, model_name, fullname, nickname, alias, salutation, persona, telegram_id, telegram_username, xampp_username, familyname=None, character=None):
|
||||
try:
|
||||
db = lancedb.connect(db_path)
|
||||
table = db.open_table("knowledge_user")
|
||||
@ -141,8 +140,10 @@ def users_store(db_path, model_url, model_name, fullname, nickname, alias, salut
|
||||
record = {
|
||||
"id": uuid.uuid4(),
|
||||
"timestamp": datetime.now(),
|
||||
"character": character,
|
||||
"fullname": fullname,
|
||||
"nickname": nickname,
|
||||
"familyname": familyname,
|
||||
"alias": alias,
|
||||
"salutation": salutation,
|
||||
"persona": persona,
|
||||
@ -171,7 +172,7 @@ def users_filter(db_path, query_name=None, unique_id=None, persona_keyword=None,
|
||||
if unique_id:
|
||||
filters.append(f"(telegram_id = '{unique_id}' OR telegram_username = '{unique_id}' OR xampp_username = '{unique_id}')")
|
||||
if query_name:
|
||||
filters.append(f"(fullname = '{query_name}' OR nickname = '{query_name}' OR alias = '{query_name}')")
|
||||
filters.append(f"(fullname = '{query_name}' OR nickname = '{query_name}' OR alias = '{query_name}' OR familyname = '{query_name}')")
|
||||
if persona_keyword:
|
||||
filters.append(f"persona LIKE '%{persona_keyword}%'")
|
||||
|
||||
|
||||
@ -202,6 +202,8 @@ class TelegramClient:
|
||||
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'
|
||||
|
||||
@ -306,6 +306,8 @@ class XMPPClient(ClientXMPP):
|
||||
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'
|
||||
|
||||
@ -32,8 +32,10 @@ schema_users_store = {
|
||||
"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"},
|
||||
@ -72,8 +74,10 @@ schema_users_update = {
|
||||
"user_id": {"type": "string", "description": "The unique UUID of the user to update"},
|
||||
"fullname": {"type": "string", "description": "Updated full name"},
|
||||
"nickname": {"type": "string", "description": "Updated nickname"},
|
||||
"familyname": {"type": "string", "description": "Updated family/clan name"},
|
||||
"alias": {"type": "string", "description": "Updated alias"},
|
||||
"salutation": {"type": "string", "description": "Updated salutation"},
|
||||
"character": {"type": "string", "description": "Updated active character"},
|
||||
"persona": {"type": "string", "description": "Updated persona description"},
|
||||
"telegram_id": {"type": "string", "description": "Updated telegram ID"},
|
||||
"telegram_username": {"type": "string", "description": "Updated telegram username"},
|
||||
@ -633,7 +637,7 @@ def memories_delete(memory_id):
|
||||
except Exception as 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):
|
||||
def users_store(fullname, nickname, alias=None, salutation=None, persona=None, telegram_id=None, telegram_username=None, xampp_username=None, familyname=None, character=None):
|
||||
try:
|
||||
success = ragroleplay_lib.users_store(
|
||||
config.ragroleplay_db_path,
|
||||
@ -646,7 +650,9 @@ def users_store(fullname, nickname, alias=None, salutation=None, persona=None, t
|
||||
persona,
|
||||
telegram_id,
|
||||
telegram_username,
|
||||
xampp_username
|
||||
xampp_username,
|
||||
familyname,
|
||||
character
|
||||
)
|
||||
if success:
|
||||
return "Berhasil menyimpan profil user baru."
|
||||
@ -668,6 +674,8 @@ def users_filter(query_name=None, unique_id=None, persona_keyword=None, user_id=
|
||||
f"User #{i}\n"
|
||||
f"ID: {row['id']}\n"
|
||||
f"Nama: {row['fullname']} ({row['nickname']})\n"
|
||||
f"Family: {row.get('familyname', '-') or '-'}\n"
|
||||
f"Character: {row.get('character', '-') or '-'}\n"
|
||||
f"Salutation: {row.get('salutation', '-') or '-'}\n"
|
||||
f"Persona: {row['persona']}\n"
|
||||
)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user