AnirudhEsthuri-MV commited on
Commit
e4f4760
·
unverified ·
1 Parent(s): 8bccf3c

Sync all code from test-playground - complete codebase match

Browse files
Files changed (3) hide show
  1. app.py +2 -2
  2. gateway_client.py +66 -0
  3. styles.css +1 -1
app.py CHANGED
@@ -7,7 +7,7 @@ from urllib.parse import urlencode
7
  import requests
8
  import streamlit as st
9
 
10
- from gateway_client import delete_profile, ingest_and_rewrite, get_memories, ingest_memories
11
  from llm import chat, set_model
12
  from model_config import MODEL_CHOICES, MODEL_TO_PROVIDER, MODEL_DISPLAY_NAMES
13
 
@@ -896,4 +896,4 @@ for turn in st.session_state.history:
896
  )
897
  # Mark as no longer new
898
  if is_new:
899
- turn["is_new"] = False
 
7
  import requests
8
  import streamlit as st
9
 
10
+ from gateway_client import delete_profile, ingest_and_rewrite, ingest_memories
11
  from llm import chat, set_model
12
  from model_config import MODEL_CHOICES, MODEL_TO_PROVIDER, MODEL_DISPLAY_NAMES
13
 
 
896
  )
897
  # Mark as no longer new
898
  if is_new:
899
+ turn["is_new"] = False
gateway_client.py CHANGED
@@ -64,6 +64,72 @@ def ingest_and_rewrite(user_id: str, query: str) -> str:
64
  return PROMPT + "\n\n" + resp.text + "\n\n" + "User Query: " + query
65
 
66
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
67
  def delete_profile(user_id: str) -> bool:
68
  """Delete the session for the given user_id"""
69
  headers = {
 
64
  return PROMPT + "\n\n" + resp.text + "\n\n" + "User Query: " + query
65
 
66
 
67
+ def get_memories(user_id: str) -> dict:
68
+ """Fetch all memories for a given user_id"""
69
+ headers = {
70
+ "user-id": user_id,
71
+ "group-id": user_id,
72
+ "session-id": user_id,
73
+ "agent-id": "agent",
74
+ }
75
+
76
+ # Add API key if configured
77
+ if BACKEND_API_KEY:
78
+ headers["x-api-key"] = BACKEND_API_KEY
79
+
80
+ try:
81
+ resp = requests.get(
82
+ f"{MEMMACHINE_PORT}/v1/memories",
83
+ headers=headers,
84
+ timeout=10,
85
+ )
86
+ resp.raise_for_status()
87
+ return resp.json()
88
+ except requests.exceptions.RequestException as e:
89
+ print(f"Error fetching memories: {e}")
90
+ return {}
91
+
92
+
93
+ def ingest_memories(user_id: str, memories_text: str) -> bool:
94
+ """Ingest imported memories into MemMachine system.
95
+
96
+ Args:
97
+ user_id: The user identifier
98
+ memories_text: Text containing memories/conversations to ingest
99
+
100
+ Returns:
101
+ True if successful, False otherwise
102
+ """
103
+ headers = {
104
+ "user-id": user_id,
105
+ "group-id": user_id,
106
+ "session-id": user_id,
107
+ "agent-id": "agent",
108
+ }
109
+
110
+ # Add API key if configured
111
+ if BACKEND_API_KEY:
112
+ headers["x-api-key"] = BACKEND_API_KEY
113
+
114
+ try:
115
+ # Ingest the memories as an episode
116
+ resp = requests.post(
117
+ f"{MEMMACHINE_PORT}/v1/memories",
118
+ json={
119
+ "producer": user_id,
120
+ "produced_for": "agent",
121
+ "episode_content": memories_text
122
+ },
123
+ headers=headers,
124
+ timeout=10,
125
+ )
126
+ resp.raise_for_status()
127
+ return True
128
+ except requests.exceptions.RequestException as e:
129
+ print(f"Error ingesting memories: {e}")
130
+ return False
131
+
132
+
133
  def delete_profile(user_id: str) -> bool:
134
  """Delete the session for the given user_id"""
135
  headers = {
styles.css CHANGED
@@ -68,4 +68,4 @@ div[data-testid="column"] {
68
 
69
  div[data-testid="stSuccess"] > div {
70
  color: #667eea !important;
71
- }
 
68
 
69
  div[data-testid="stSuccess"] > div {
70
  color: #667eea !important;
71
+ }