Ashhar commited on
Commit
e20d9c0
1 Parent(s): e99e506

add prompt caching for system prompt

Browse files
Files changed (2) hide show
  1. app.py +10 -1
  2. helpers/sidebar.py +8 -4
app.py CHANGED
@@ -242,7 +242,16 @@ def __predict():
242
  with client.messages.stream(
243
  model=MODEL,
244
  messages=messagesFormatted,
245
- system=C.SYSTEM_MSG,
 
 
 
 
 
 
 
 
 
246
  temperature=0.9,
247
  max_tokens=4000,
248
  ) as stream:
 
242
  with client.messages.stream(
243
  model=MODEL,
244
  messages=messagesFormatted,
245
+ extra_headers={
246
+ "anthropic-beta": "prompt-caching-2024-07-31"
247
+ },
248
+ system=[
249
+ {
250
+ "type": "text",
251
+ "text": C.SYSTEM_MSG,
252
+ "cache_control": {"type": "ephemeral"}
253
+ },
254
+ ],
255
  temperature=0.9,
256
  max_tokens=4000,
257
  ) as stream:
helpers/sidebar.py CHANGED
@@ -14,6 +14,13 @@ def __fixTimestamp(timestamp: str):
14
  return fixedTimestamp
15
 
16
 
 
 
 
 
 
 
 
17
  def showSidebar():
18
  with st.sidebar:
19
  if not ("user" in st.session_state and "token" in st.session_state):
@@ -93,10 +100,7 @@ def showSidebar():
93
  """)
94
  with st.container(height=300, border=False):
95
  for log in userActivityLogs:
96
- updatedAt = DT.datetime.fromisoformat(__fixTimestamp(
97
- log["updated_at"].replace("Z", "+00:00")
98
- ))
99
- localTime = updatedAt.astimezone(ZoneInfo("Asia/Kolkata")).strftime("%b %d, %I:%M %p IST")
100
  activityId = log["id"]
101
  if st.button(f"Saved ⏱ {localTime}", key=f"activity_{activityId}", use_container_width=True):
102
  restoreUserActivity(log["id"])
 
14
  return fixedTimestamp
15
 
16
 
17
+ def __getInLocalTime(timestamp: str):
18
+ fixedTimestamp = DT.datetime.fromisoformat(__fixTimestamp(
19
+ timestamp.replace("Z", "+00:00")
20
+ ))
21
+ return fixedTimestamp.astimezone(ZoneInfo("Asia/Kolkata")).strftime("%b %d, %I:%M %p IST")
22
+
23
+
24
  def showSidebar():
25
  with st.sidebar:
26
  if not ("user" in st.session_state and "token" in st.session_state):
 
100
  """)
101
  with st.container(height=300, border=False):
102
  for log in userActivityLogs:
103
+ localTime = __getInLocalTime(log["updated_at"])
 
 
 
104
  activityId = log["id"]
105
  if st.button(f"Saved ⏱ {localTime}", key=f"activity_{activityId}", use_container_width=True):
106
  restoreUserActivity(log["id"])