Update app.py
Browse files
app.py
CHANGED
|
@@ -11,8 +11,8 @@ load_dotenv()
|
|
| 11 |
|
| 12 |
# Initialize the client
|
| 13 |
client = OpenAI(
|
| 14 |
-
base_url=os.environ.get('BASE_URL'),
|
| 15 |
-
api_key=os.environ.get('API_KEY')
|
| 16 |
)
|
| 17 |
|
| 18 |
# Create supported models
|
|
@@ -44,23 +44,19 @@ def get_session_id():
|
|
| 44 |
return st.session_state.session_id
|
| 45 |
|
| 46 |
def load_history():
|
| 47 |
-
"""Load chat history from
|
| 48 |
session_id = get_session_id()
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
except json.JSONDecodeError:
|
| 53 |
-
return {}
|
| 54 |
|
| 55 |
def save_history(histories):
|
| 56 |
-
"""Save chat history to
|
| 57 |
-
|
| 58 |
-
history_json = json.dumps(histories)
|
| 59 |
-
st.experimental_set_query_params(history=history_json)
|
| 60 |
|
| 61 |
def clear_history():
|
| 62 |
-
"""Clear chat history from
|
| 63 |
-
st.
|
| 64 |
|
| 65 |
def reset_conversation():
|
| 66 |
"""Reset the conversation."""
|
|
@@ -200,4 +196,4 @@ st.sidebar.markdown("\n[GPT-CHATBOT.ru](https://gpt-chatbot.ru).")
|
|
| 200 |
# Display this only on initial load or reset
|
| 201 |
if not st.session_state.get("has_interacted", False):
|
| 202 |
st.subheader(f'[GPT-CHATBOT.ru](https://gpt-chatbot.ru) with AI model {selected_model}')
|
| 203 |
-
st.session_state
|
|
|
|
| 11 |
|
| 12 |
# Initialize the client
|
| 13 |
client = OpenAI(
|
| 14 |
+
base_url=os.environ.get('BASE_URL'),
|
| 15 |
+
api_key=os.environ.get('API_KEY')
|
| 16 |
)
|
| 17 |
|
| 18 |
# Create supported models
|
|
|
|
| 44 |
return st.session_state.session_id
|
| 45 |
|
| 46 |
def load_history():
|
| 47 |
+
"""Load chat history from session state."""
|
| 48 |
session_id = get_session_id()
|
| 49 |
+
if 'chat_histories' not in st.session_state:
|
| 50 |
+
st.session_state.chat_histories = {}
|
| 51 |
+
return st.session_state.chat_histories
|
|
|
|
|
|
|
| 52 |
|
| 53 |
def save_history(histories):
|
| 54 |
+
"""Save chat history to session state."""
|
| 55 |
+
st.session_state.chat_histories = histories
|
|
|
|
|
|
|
| 56 |
|
| 57 |
def clear_history():
|
| 58 |
+
"""Clear chat history from session state."""
|
| 59 |
+
st.session_state.chat_histories = {}
|
| 60 |
|
| 61 |
def reset_conversation():
|
| 62 |
"""Reset the conversation."""
|
|
|
|
| 196 |
# Display this only on initial load or reset
|
| 197 |
if not st.session_state.get("has_interacted", False):
|
| 198 |
st.subheader(f'[GPT-CHATBOT.ru](https://gpt-chatbot.ru) with AI model {selected_model}')
|
| 199 |
+
st.session_state.has_interacted = True
|