Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -53,6 +53,9 @@ with st.sidebar:
|
|
| 53 |
Enjoy chatting with Meta's Llama3 model!
|
| 54 |
""")
|
| 55 |
|
|
|
|
|
|
|
|
|
|
| 56 |
# Add a button to submit
|
| 57 |
submit_button = st.button("Submit")
|
| 58 |
|
|
@@ -76,24 +79,70 @@ for message in st.session_state.messages:
|
|
| 76 |
st.markdown(message["content"])
|
| 77 |
|
| 78 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 79 |
# React to user input
|
|
|
|
| 80 |
if submit_button:
|
| 81 |
|
| 82 |
# Initiatization
|
| 83 |
-
prompt = "Ask a
|
| 84 |
|
| 85 |
# Display user message in chat message container
|
| 86 |
st.chat_message("user").markdown(prompt)
|
| 87 |
-
|
| 88 |
-
# Add user message to chat history
|
| 89 |
st.session_state.messages.append({"role": "user", "content": prompt})
|
| 90 |
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 97 |
|
| 98 |
-
# Add assistant response to chat history
|
| 99 |
-
st.session_state.messages.append({"role": "assistant", "content": response})
|
|
|
|
| 53 |
Enjoy chatting with Meta's Llama3 model!
|
| 54 |
""")
|
| 55 |
|
| 56 |
+
# Text input
|
| 57 |
+
user_topic = st.text_input("Enter a topic", "Data Science")
|
| 58 |
+
|
| 59 |
# Add a button to submit
|
| 60 |
submit_button = st.button("Submit")
|
| 61 |
|
|
|
|
| 79 |
st.markdown(message["content"])
|
| 80 |
|
| 81 |
|
| 82 |
+
# Create agents
|
| 83 |
+
interviewer = call_llama
|
| 84 |
+
interviewee = call_llama
|
| 85 |
+
judge = call_llama
|
| 86 |
+
|
| 87 |
+
|
| 88 |
# React to user input
|
| 89 |
+
iter = 0
|
| 90 |
if submit_button:
|
| 91 |
|
| 92 |
# Initiatization
|
| 93 |
+
prompt = f"Ask a question about this topic: {user_topic}"
|
| 94 |
|
| 95 |
# Display user message in chat message container
|
| 96 |
st.chat_message("user").markdown(prompt)
|
|
|
|
|
|
|
| 97 |
st.session_state.messages.append({"role": "user", "content": prompt})
|
| 98 |
|
| 99 |
+
while True:
|
| 100 |
+
|
| 101 |
+
# Interview asks a question
|
| 102 |
+
question = interviewer(prompt)
|
| 103 |
+
|
| 104 |
+
# Display assistant response in chat message container
|
| 105 |
+
st.chat_message("assistant").markdown(question)
|
| 106 |
+
st.session_state.messages.append({"role": "assistant", "content": question})
|
| 107 |
+
|
| 108 |
+
# Interviewee attempts an answer
|
| 109 |
+
if iter < 5:
|
| 110 |
+
answer = interviewee(
|
| 111 |
+
f"""
|
| 112 |
+
Answer the question: {question} in a mediocre way
|
| 113 |
+
|
| 114 |
+
Because you are an inexperienced interviewee.
|
| 115 |
+
"""
|
| 116 |
+
)
|
| 117 |
+
st.chat_message("user").markdown(prompt)
|
| 118 |
+
st.session_state.messages.append({"role": "user", "content": prompt})
|
| 119 |
+
else:
|
| 120 |
+
answer = interviewee(
|
| 121 |
+
f"""
|
| 122 |
+
Answer the question: {question} in a mediocre way
|
| 123 |
+
|
| 124 |
+
Because you are an inexperienced interviewee but you really want to learn,
|
| 125 |
+
so you learn from the judge comments: {judge_comments}
|
| 126 |
+
"""
|
| 127 |
+
)
|
| 128 |
+
st.chat_message("user").markdown(prompt)
|
| 129 |
+
st.session_state.messages.append({"role": "user", "content": prompt})
|
| 130 |
+
|
| 131 |
+
# Judge thinks and advises but the thoughts are hidden
|
| 132 |
+
judge_comments = judge(
|
| 133 |
+
f"""
|
| 134 |
+
The question is: {question}
|
| 135 |
+
|
| 136 |
+
The answer is: {answer}
|
| 137 |
+
|
| 138 |
+
Provide feedback and rate the answer from 1 to 10 while 10 being the best and 1 is the worst.
|
| 139 |
+
"""
|
| 140 |
+
)
|
| 141 |
+
|
| 142 |
+
# Stopping rule
|
| 143 |
+
if '9' in judge_comments:
|
| 144 |
+
break
|
| 145 |
+
|
| 146 |
+
# Checkpoint
|
| 147 |
+
iter += 1
|
| 148 |
|
|
|
|
|
|