repositories
loading repo index
repositories
loading repo index
repository
loading code, commits, and activity
public Clawd ADK gateway launch mirror
stars
latest
clone command
git clone gitlawb://did:key:z6Mkq5mY...iFZ5/my-project-publ...git clone gitlawb://did:key:z6Mkq5mY.../my-project-publ...2fa351d6docs: add automaton and perps launch sources16d ago| #1 | import argparse |
| #2 | import json |
| #3 | import os |
| #4 | |
| #5 | from dotenv import load_dotenv |
| #6 | from tqdm import tqdm |
| #7 | from zep_cloud import Message |
| #8 | from zep_cloud.client import Zep |
| #9 | |
| #10 | load_dotenv() |
| #11 | |
| #12 | |
| #13 | class ZepAdd: |
| #14 | def __init__(self, data_path=None): |
| #15 | self.zep_client = Zep(api_key=os.getenv("ZEP_API_KEY")) |
| #16 | self.data_path = data_path |
| #17 | self.data = None |
| #18 | if data_path: |
| #19 | self.load_data() |
| #20 | |
| #21 | def load_data(self): |
| #22 | with open(self.data_path, "r") as f: |
| #23 | self.data = json.load(f) |
| #24 | return self.data |
| #25 | |
| #26 | def process_conversation(self, run_id, item, idx): |
| #27 | conversation = item["conversation"] |
| #28 | |
| #29 | user_id = f"run_id_{run_id}_experiment_user_{idx}" |
| #30 | session_id = f"run_id_{run_id}_experiment_session_{idx}" |
| #31 | |
| #32 | # # delete all memories for the two users |
| #33 | # self.zep_client.user.delete(user_id=user_id) |
| #34 | # self.zep_client.memory.delete(session_id=session_id) |
| #35 | |
| #36 | self.zep_client.user.add(user_id=user_id) |
| #37 | self.zep_client.memory.add_session( |
| #38 | user_id=user_id, |
| #39 | session_id=session_id, |
| #40 | ) |
| #41 | |
| #42 | print("Starting to add memories... for user", user_id) |
| #43 | for key in tqdm(conversation.keys(), desc=f"Processing user {user_id}"): |
| #44 | if key in ["speaker_a", "speaker_b"] or "date" in key: |
| #45 | continue |
| #46 | |
| #47 | date_time_key = key + "_date_time" |
| #48 | timestamp = conversation[date_time_key] |
| #49 | chats = conversation[key] |
| #50 | |
| #51 | for chat in tqdm(chats, desc=f"Adding chats for {key}", leave=False): |
| #52 | self.zep_client.memory.add( |
| #53 | session_id=session_id, |
| #54 | messages=[ |
| #55 | Message( |
| #56 | role=chat["speaker"], |
| #57 | role_type="user", |
| #58 | content=f"{timestamp}: {chat['text']}", |
| #59 | ) |
| #60 | ], |
| #61 | ) |
| #62 | |
| #63 | def process_all_conversations(self, run_id): |
| #64 | if not self.data: |
| #65 | raise ValueError("No data loaded. Please set data_path and call load_data() first.") |
| #66 | for idx, item in tqdm(enumerate(self.data)): |
| #67 | if idx == 0: |
| #68 | self.process_conversation(run_id, item, idx) |
| #69 | |
| #70 | |
| #71 | if __name__ == "__main__": |
| #72 | parser = argparse.ArgumentParser() |
| #73 | parser.add_argument("--run_id", type=str, required=True) |
| #74 | args = parser.parse_args() |
| #75 | zep_add = ZepAdd(data_path="../../dataset/locomo10.json") |
| #76 | zep_add.process_all_conversations(args.run_id) |
| #77 |