diff --git a/.gitignore b/.gitignore index f90f63a..fc70fb8 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1 @@ - -*.toml .streamlit/secrets.toml diff --git a/README.md b/README.md index 02e6a2c..60f58e3 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,6 @@ # chergpt-basic: custom chat assistant No login, vanilla ChatGPT-like interface with scaffolded code for immediate deployment - -image +Test deployment for IMH education office ## Features - [x] Set custom instructions to guide student interactions
diff --git a/main.py b/main.py index cd2b2b4..6e4f41d 100644 --- a/main.py +++ b/main.py @@ -5,6 +5,14 @@ st.title("CherGPT Basic") +# Initialize session state for admin +if "is_admin" not in st.session_state: + st.session_state["is_admin"] = False + +# Initialize variables for custom and existing instructions +custom_instructions = "" +existing_instructions = "" + client = OpenAI(api_key=st.secrets["OPENAI_API_KEY"]) with st.sidebar: @@ -63,9 +71,9 @@ def update_instructions(new_instructions): try: with conn.cursor() as cur: cur.execute(""" - INSERT INTO instructions (content) + INSERT INTO instructions (content) VALUES (%s) - ON CONFLICT (id) + ON CONFLICT (id) DO UPDATE SET content = EXCLUDED.content; """, (new_instructions,)) conn.commit() @@ -96,6 +104,7 @@ def get_latest_instructions(): existing_instructions = get_latest_instructions() +custom_instructions = existing_instructions custominstructions_area_height = 300 @@ -132,8 +141,11 @@ def get_latest_instructions(): st.markdown(prompt) # Prepend custom instructions to the conversation context for processing - conversation_context = [ - {"role": "system", "content": custom_instructions}] if existing_instructions else [] + conversation_context = [] + if existing_instructions: + conversation_context.append( + {"role": "system", "content": custom_instructions}) + conversation_context += [ {"role": m["role"], "content": m["content"]} for m in st.session_state.messages