prashantmatlani commited on
Commit
bd7c5b9
·
1 Parent(s): 5d2e348

better prompt, updated conversation history display

Browse files
Files changed (2) hide show
  1. app.py +23 -0
  2. core_logic.py +3 -5
app.py CHANGED
@@ -55,10 +55,21 @@ with gr.Blocks() as demo:
55
  history[-1]["content"] = partial_resp
56
  yield history
57
 
 
58
  def handle_save(history, chat_id):
59
  # Saves the chat and returns the updated list for the sidebar
60
  new_id = save_chat(chat_id, history)
61
  return new_id, load_history()
 
 
 
 
 
 
 
 
 
 
62
 
63
  def load_past_chat(selected_list):
64
  # selected_list comes as [ 'chat_id' ]
@@ -93,4 +104,16 @@ with gr.Blocks() as demo:
93
  [chatbot, chat_id_state, history_list]
94
  )
95
 
 
 
 
 
 
 
 
 
 
 
 
 
96
  demo.launch(theme=gr.themes.Soft(), css="styles.css")
 
55
  history[-1]["content"] = partial_resp
56
  yield history
57
 
58
+ """
59
  def handle_save(history, chat_id):
60
  # Saves the chat and returns the updated list for the sidebar
61
  new_id = save_chat(chat_id, history)
62
  return new_id, load_history()
63
+ """
64
+ def handle_save(history, chat_id):
65
+ # 1. Save the actual data
66
+ new_id = save_chat(chat_id, history)
67
+ # 2. Get the latest from hub
68
+ current_list = load_history()
69
+ # 3. Ensure the current one is definitely at the top
70
+ if [new_id] not in current_list:
71
+ current_list.insert(0, [new_id])
72
+ return new_id, gr.update(samples=current_list)
73
 
74
  def load_past_chat(selected_list):
75
  # selected_list comes as [ 'chat_id' ]
 
104
  [chatbot, chat_id_state, history_list]
105
  )
106
 
107
+ # 4. "Force Refresh"
108
+ # In Gradio, a component's samples are often cached at the moment of the initial load. To ensure the sidebar is truly dynamic, we need to update the gr.Dataset definition and the refresh logic
109
+ # To update history_list definition, we add samples_per_page explicitly, ensuring it's not cutting off the list early
110
+ history_list = gr.Dataset(
111
+ components=[gr.Textbox(visible=False)],
112
+ label="Recent Conversations",
113
+ samples=load_history(),
114
+ type="values",
115
+ samples_per_page=20 # Increase this to see more at once
116
+ )
117
+
118
+
119
  demo.launch(theme=gr.themes.Soft(), css="styles.css")
core_logic.py CHANGED
@@ -28,11 +28,9 @@ CORE DIRECTIVES:
28
  5. RESEARCH: If the user asks about new tech, use your Web Search capability to provide factual, up-to-date documentation.
29
 
30
  PERSONALITY:
31
- 1. "Act as a sarcastic technical editor. Summarize your response as cynical, funny, in few but highly-effective and precise words. No introductory filler. Example: "Explain NFTs." -> "It's a digital receipt for a JPG that tells the world you own the right to be ignored"
32
- 2. So, humor is your way without losing sight of the actual context, and apt responses to all the concerns and queries
33
- 3. FRANK/POLITE: Disagree with the user, if needed; never resort to sycophancy, and suggest better alternatives
34
- 4. HUMBLE: Apologize when mistaken
35
-
36
 
37
  When a user provides files, analyze the code structure and logic before proposing changes.
38
  """
 
28
  5. RESEARCH: If the user asks about new tech, use your Web Search capability to provide factual, up-to-date documentation.
29
 
30
  PERSONALITY:
31
+ 1. FRANK/POLITE: Disagree with the user, if needed; never resort to sycophancy, and suggest better alternatives
32
+ 2. HUMBLE: Apologize when mistaken
33
+ 3. FIRST PRINCIPLES: Base your responses and reasoning in Richard Feynman’s first principles thinking. Break down complex problems into fundamental truths and reason up from there
 
 
34
 
35
  When a user provides files, analyze the code structure and logic before proposing changes.
36
  """