Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Saving / Loading of Conversations #3

Open
ricardobalk opened this issue Jul 27, 2023 · 0 comments
Open

Saving / Loading of Conversations #3

ricardobalk opened this issue Jul 27, 2023 · 0 comments
Assignees
Labels
enhancement New feature or request
Milestone

Comments

@ricardobalk
Copy link
Contributor

As part of enhancing our application's user experience and offering a basic solution for data persistence, we propose implementing the feature to save and load conversations using Streamlit's st.file_uploader and st.download_button functionalities. This will enable users to save ongoing conversations and reload them later for review, sharing, manipulation or continuation.


Feature Specification

  1. Save Conversation to JSON (Must Have):
    Introduce a "Save Conversation" option in the user interface that allows users to save the current conversation's raw JSON-based request data as a JSON file.

  2. Load Conversation from JSON (Must Have):
    Implement a "Load Conversation" feature that enables users to upload a previously saved JSON file containing conversation data. The application will parse and load the conversation for review, sharing, or continuation.

  3. Error Handling and Validation (Should Have):
    To ensure data integrity, the application will validate the loaded JSON files. Proper error handling mechanisms will be implemented to notify users of any issues with the loaded data, such as incorrect format or corrupted data.

  4. Conversations Management (Could Have):
    Add a convenient way for users to manage their saved conversations. This includes providing access to a list of saved conversations where users can view, delete, or load any conversation from the list.


Sample Code

Below is some sample code that shows how to download and upload JSON files to a Streamlit app.

import streamlit as st
import json

# Function to save conversation to JSON
def save_conversation_to_json(conversation_data):
    # Implementation to save the conversation data as a JSON file
    ...

# Function to load conversation from JSON
def load_conversation_from_json(file):
    # Implementation to load conversation data from a JSON file and validate the format
    conversation_data = None
    try:
        with open(file.name, 'r') as f:
            conversation_data = json.load(f)
    except:
        st.error("Error loading conversation. Please ensure the file is in valid JSON format.")
    return conversation_data

# Streamlit App
def main():
    st.title("Conversation Saving and Loading")
    
    # Display current conversation or load from file
    uploaded_file = st.file_uploader("Load Conversation from JSON file", type="json")
    
    if uploaded_file:
        conversation_data = load_conversation_from_json(uploaded_file)
        if conversation_data:
            st.success("Conversation loaded successfully!")
            st.json(conversation_data)
    
    st.header("Current Conversation")
    st.json(sample_conversation_data)  # Replace with your actual conversation data
    
    # Save conversation to JSON
    if st.button("Save Conversation to JSON"):
        save_conversation_to_json(sample_conversation_data)  # Replace with your actual conversation data
        st.success("Conversation saved successfully!")

    # Download button for the saved JSON file
    if st.button("Download Saved Conversation"):
        with open('saved_conversation.json', 'r') as f:
            file_content = f.read()
        st.download_button(label="Download Conversation", data=file_content, file_name='saved_conversation.json', mime='application/json')

if __name__ == "__main__":
    main()
@ricardobalk ricardobalk added the enhancement New feature or request label Jul 27, 2023
@ricardobalk ricardobalk added this to the 1.0.0-alpha.2 milestone Jul 27, 2023
@ricardobalk ricardobalk self-assigned this Jul 27, 2023
@ricardobalk ricardobalk changed the title Saving / Loading of Conversationa Saving / Loading of Conversations Jul 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: Todo
Development

No branches or pull requests

1 participant