From 0ed90cd542e6c319a9cfd63de0534c13de5d3432 Mon Sep 17 00:00:00 2001
From: Kahhow Lee <44336310+ghostleek@users.noreply.github.com>
Date: Thu, 11 Jan 2024 22:20:43 +0800
Subject: [PATCH 1/2] Update README.md
---
README.md | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
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
-
-
+Test deployment for IMH education office
## Features
- [x] Set custom instructions to guide student interactions
From d9c45263ffc11f83b81a9beab14f48997fde6f10 Mon Sep 17 00:00:00 2001
From: Kahhow Lee
Date: Thu, 11 Jan 2024 23:15:38 +0800
Subject: [PATCH 2/2] fix: custom instructions immediately set
---
.gitignore | 2 --
main.py | 20 ++++++++++++++++----
2 files changed, 16 insertions(+), 6 deletions(-)
diff --git a/.gitignore b/.gitignore
index f90f63a..fc70fb8 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,3 +1 @@
-
-*.toml
.streamlit/secrets.toml
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