Anirudh Esthuri commited on
Commit
7d97a41
·
1 Parent(s): 0c5da84

Add API key header support for backend authentication

Browse files
Files changed (1) hide show
  1. gateway_client.py +12 -2
gateway_client.py CHANGED
@@ -4,6 +4,7 @@ from datetime import datetime
4
 
5
 
6
  MEMMACHINE_PORT = os.getenv("MEMORY_SERVER_URL")
 
7
  PROMPT = """You are a helpful AI assistant. Use the provided context and profile information to answer the user's question accurately and helpfully.
8
 
9
  <CURRENT_DATE>
@@ -38,9 +39,13 @@ def ingest_and_rewrite(user_id: str, query: str) -> str:
38
  "user-id": user_id,
39
  "group-id": user_id,
40
  "session-id": user_id,
41
- "agent-id": "agent",
42
  }
43
 
 
 
 
 
44
  requests.post(
45
  f"{MEMMACHINE_PORT}/v1/memories",
46
  json={"producer": user_id, "produced_for": "agent", "episode_content": query},
@@ -65,7 +70,12 @@ def delete_profile(user_id: str) -> bool:
65
  "user-id": user_id,
66
  "group-id": user_id,
67
  "session-id": user_id,
68
- "agent-id": "agent",
69
  }
 
 
 
 
 
70
  requests.delete(f"{MEMMACHINE_PORT}/v1/memories", headers=headers, json={})
71
  return True
 
4
 
5
 
6
  MEMMACHINE_PORT = os.getenv("MEMORY_SERVER_URL")
7
+ BACKEND_API_KEY = os.getenv("BACKEND_API_KEY")
8
  PROMPT = """You are a helpful AI assistant. Use the provided context and profile information to answer the user's question accurately and helpfully.
9
 
10
  <CURRENT_DATE>
 
39
  "user-id": user_id,
40
  "group-id": user_id,
41
  "session-id": user_id,
42
+ "agent-id": "agent",
43
  }
44
 
45
+ # Add API key if configured
46
+ if BACKEND_API_KEY:
47
+ headers["x-api-key"] = BACKEND_API_KEY
48
+
49
  requests.post(
50
  f"{MEMMACHINE_PORT}/v1/memories",
51
  json={"producer": user_id, "produced_for": "agent", "episode_content": query},
 
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
  requests.delete(f"{MEMMACHINE_PORT}/v1/memories", headers=headers, json={})
81
  return True