adikwok commited on
Commit
bcd2917
Β·
verified Β·
1 Parent(s): e21021f

Update app.py

Browse files

chat. history. sum. journal marathon

Files changed (1) hide show
  1. app.py +27 -8
app.py CHANGED
@@ -35,14 +35,14 @@ def groq_with_memory(message: str, topic: str = "general") -> tuple:
35
  "timestamp": datetime.now().strftime("%Y-%m-%d %H:%M")
36
  })
37
 
38
- # Prepare messages for API call (last 10 messages)
39
- recent_history = chat_history[-10:]
40
  messages = [{"role": msg["role"], "content": msg["content"]} for msg in recent_history]
41
 
42
  payload = {
43
  "model": "gemma2-9b-it",
44
  "messages": messages,
45
- "max_tokens": 2000,
46
  "temperature": 0.7
47
  }
48
 
@@ -227,7 +227,7 @@ with gr.Blocks(
227
 
228
  with gr.Row():
229
  clear_response_btn = gr.Button("πŸ—‘οΈ Clear Response", variant="secondary")
230
- new_topic_btn = gr.Button("πŸ†• New Topic", variant="secondary")
231
 
232
  # HISTORY TAB
233
  with gr.Tab("πŸ“š Chat History"):
@@ -261,9 +261,28 @@ with gr.Blocks(
261
  response, cleared_input = groq_with_memory(message, topic)
262
  return response, cleared_input
263
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
264
  def refresh_topic_choices():
265
  return gr.Dropdown(choices=get_topics_list())
266
 
 
 
 
267
  def filter_and_show_history(topic_filter):
268
  filter_topic = None if topic_filter == "All Topics" else topic_filter
269
  return get_full_history(filter_topic)
@@ -286,13 +305,13 @@ with gr.Blocks(
286
  )
287
 
288
  clear_response_btn.click(
289
- lambda: "",
290
  outputs=[ai_response]
291
  )
292
 
293
- new_topic_btn.click(
294
- lambda: "",
295
- outputs=[topic_input]
296
  )
297
 
298
  refresh_topics_btn.click(
 
35
  "timestamp": datetime.now().strftime("%Y-%m-%d %H:%M")
36
  })
37
 
38
+ # Prepare messages for API call (last 50 messages for longer context)
39
+ recent_history = chat_history[-50:]
40
  messages = [{"role": msg["role"], "content": msg["content"]} for msg in recent_history]
41
 
42
  payload = {
43
  "model": "gemma2-9b-it",
44
  "messages": messages,
45
+ "max_tokens": 3000, # Increased for longer responses
46
  "temperature": 0.7
47
  }
48
 
 
227
 
228
  with gr.Row():
229
  clear_response_btn = gr.Button("πŸ—‘οΈ Clear Response", variant="secondary")
230
+ show_context_btn = gr.Button("πŸ“‹ Show Current Context", variant="secondary")
231
 
232
  # HISTORY TAB
233
  with gr.Tab("πŸ“š Chat History"):
 
261
  response, cleared_input = groq_with_memory(message, topic)
262
  return response, cleared_input
263
 
264
+ def show_current_context():
265
+ """Show current conversation context that AI can see"""
266
+ if not chat_history:
267
+ return "❌ No conversation context yet"
268
+
269
+ recent_history = chat_history[-50:] # Same as what AI sees
270
+ context_text = f"🧠 **Current AI Context** ({len(recent_history)} messages)\n\n"
271
+
272
+ for msg in recent_history:
273
+ role_icon = "πŸ‘€" if msg["role"] == "user" else "πŸ€–"
274
+ context_text += f"{role_icon} **{msg['timestamp']}** [{msg.get('topic', 'general')}]\n"
275
+ context_text += f"{msg['content'][:100]}{'...' if len(msg['content']) > 100 else ''}\n\n"
276
+
277
+ context_text += f"\nπŸ’‘ *AI can remember these {len(recent_history)} messages in current conversation*"
278
+ return context_text
279
+
280
  def refresh_topic_choices():
281
  return gr.Dropdown(choices=get_topics_list())
282
 
283
+ def clear_only_response():
284
+ return ""
285
+
286
  def filter_and_show_history(topic_filter):
287
  filter_topic = None if topic_filter == "All Topics" else topic_filter
288
  return get_full_history(filter_topic)
 
305
  )
306
 
307
  clear_response_btn.click(
308
+ clear_only_response,
309
  outputs=[ai_response]
310
  )
311
 
312
+ show_context_btn.click(
313
+ show_current_context,
314
+ outputs=[ai_response]
315
  )
316
 
317
  refresh_topics_btn.click(