From dbd326504c356e691f8cf34ee6ce697d504c5216 Mon Sep 17 00:00:00 2001 From: Sapan Shah Date: Sun, 13 Oct 2024 18:56:31 +0530 Subject: [PATCH 1/2] fix: response not showing in logs --- main.py | 79 +++++++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 63 insertions(+), 16 deletions(-) diff --git a/main.py b/main.py index 7f1e4af..607aa59 100644 --- a/main.py +++ b/main.py @@ -1,33 +1,80 @@ import streamlit as st import requests +# Initialize session state for prompt history if "history" not in st.session_state: st.session_state.history = [] +# Function to send POST request to a local server def send_post_request(prompt): - url = "http://localhost:19194/" + url = "http://localhost:19194/" # Update this to your actual server URL payload = prompt.title() response = requests.post(url, json=payload) - return response.text -st.title("Prompt History and Post Request App") +# Custom CSS to fix the input box at the bottom of the page +st.markdown( + """ + + """, + unsafe_allow_html=True +) -prompt = st.text_input("Enter your prompt:") +st.title('Ask maargdarshak') -if st.button("Submit"): - if prompt: - st.session_state.history.append(prompt) - response = send_post_request(prompt) +if 'messages' not in st.session_state: + st.session_state.messages = [] + +for message in st.session_state.messages: + st.chat_message(message['role']).markdown(message['content']) + +prompt = st.chat_input("Ask your question here") + +if prompt: + st.chat_message('user').markdown(prompt) + st.session_state.messages.append({'role': 'user', 'content': prompt}) + + response = send_post_request(prompt) + print(response) + st.chat_message('bot').markdown(response) + st.session_state.messages.append({'role': 'bot', 'content': response}) + # st.session_state.history.append((prompt, response)) + # st.experimental_rerun() - st.success(f"Response: {response}") - else: - st.error("Please enter a prompt") -# Display history of prompts -if st.session_state.history: - st.write("### Prompt History") - for i, p in enumerate(st.session_state.history, 1): - st.write(f"{i}. {p}") -- 2.45.2 From fc357d17f21c9aa1f1fe9ce87f3b4ef91288be42 Mon Sep 17 00:00:00 2001 From: Sandipsinh Rathod Date: Sun, 13 Oct 2024 10:25:06 -0400 Subject: [PATCH 2/2] chore: make it compatible with chatgpt --- main.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/main.py b/main.py index 607aa59..8037dee 100644 --- a/main.py +++ b/main.py @@ -11,7 +11,11 @@ def send_post_request(prompt): url = "http://localhost:19194/" # Update this to your actual server URL payload = prompt.title() response = requests.post(url, json=payload) - return response.text + json = response.json() + if "response" in json: + return json["response"] + else: + return json # Custom CSS to fix the input box at the bottom of the page -- 2.45.2