ndurner commited on
Commit
4a50ff1
·
1 Parent(s): 247508e

add system prompt to history export

Browse files
Files changed (1) hide show
  1. app.py +15 -11
app.py CHANGED
@@ -177,10 +177,13 @@ def import_history(history, file):
177
  else:
178
  content = str(content)
179
 
180
- # Deserialize the JSON content to history
181
- history = json.loads(content)
182
- # The history is returned and will be set to the chatbot component
183
- return history
 
 
 
184
 
185
  with gr.Blocks() as demo:
186
  gr.Markdown("# Anthropic™️ Claude™️ Chat (Nils' Version™️)")
@@ -279,13 +282,14 @@ with gr.Blocks() as demo:
279
  with gr.Accordion("Import/Export", open = False):
280
  import_button = gr.UploadButton("History Import")
281
  export_button = gr.Button("History Export")
282
- export_button.click(lambda: None, [chatbot], js="""
283
- (chat_history) => {
284
- // Convert the chat history to a JSON string
285
- const history_json = JSON.stringify(chat_history);
286
- // Create a Blob from the JSON string
 
 
287
  const blob = new Blob([history_json], {type: 'application/json'});
288
- // Create a download link
289
  const url = URL.createObjectURL(blob);
290
  const a = document.createElement('a');
291
  a.href = url;
@@ -325,6 +329,6 @@ with gr.Blocks() as demo:
325
  }
326
  }
327
  """)
328
- import_button.upload(import_history, inputs=[chatbot, import_button], outputs=[chatbot])
329
 
330
  demo.queue().launch()
 
177
  else:
178
  content = str(content)
179
 
180
+ # Deserialize the JSON content
181
+ import_data = json.loads(content)
182
+
183
+ new_history = import_data.get('history', history) # Use existing history if not provided
184
+ new_system_prompt = import_data.get('system_prompt', '') # Default to empty if not provided
185
+
186
+ return new_history, new_system_prompt
187
 
188
  with gr.Blocks() as demo:
189
  gr.Markdown("# Anthropic™️ Claude™️ Chat (Nils' Version™️)")
 
282
  with gr.Accordion("Import/Export", open = False):
283
  import_button = gr.UploadButton("History Import")
284
  export_button = gr.Button("History Export")
285
+ export_button.click(lambda: None, [chatbot, system_prompt], js="""
286
+ (chat_history, system_prompt) => {
287
+ const export_data = {
288
+ history: chat_history,
289
+ system_prompt: system_prompt
290
+ };
291
+ const history_json = JSON.stringify(export_data);
292
  const blob = new Blob([history_json], {type: 'application/json'});
 
293
  const url = URL.createObjectURL(blob);
294
  const a = document.createElement('a');
295
  a.href = url;
 
329
  }
330
  }
331
  """)
332
+ import_button.upload(import_history, inputs=[chatbot, import_button], outputs=[chatbot, system_prompt])
333
 
334
  demo.queue().launch()