I am trying to use counter
variable that gives the user a message after reaching a certain threshold, lets say 3
.
Please help me edit the code
if prompt := st.chat_input("What is up?"):
counter=0
st.session_state.messages.append({"role": "user", "content": prompt})
with st.chat_message("user"):
st.markdown(prompt)
with st.chat_message("assistant"):
message_placeholder = st.empty()
full_response = ""
response_openai=openai.ChatCompletion.create(
model=st.session_state["openai_model"],
messages=[
{"role": m["role"], "content": m["content"]}
for m in st.session_state.messages
],
temperature=0,
stream=True,
)
for response in response_openai:
full_response += response.choices[0].delta.get("content", "")
message_placeholder.markdown(full_response + "▌")
if counter>=2:
st.warning("completed 3 respones")
st.stop()
message_placeholder.markdown(full_response)
st.session_state.messages.append({"role": "assistant", "content": full_response})