Spaces:
Sleeping
Sleeping
added spinners
Browse files
app.py
CHANGED
@@ -42,14 +42,20 @@ for msg in st.session_state.langchain_messages:
|
|
42 |
with st.chat_message(msg.type, avatar=avatar):
|
43 |
st.markdown(msg.content)
|
44 |
|
45 |
-
|
46 |
-
|
|
|
|
|
|
|
|
|
|
|
47 |
with st.chat_message("assistant", avatar="🦜"):
|
48 |
message_placeholder = st.empty()
|
49 |
full_response = ""
|
50 |
# Define the basic input structure for the chains
|
51 |
input_dict = {"input": prompt}
|
52 |
|
|
|
53 |
with collect_runs() as cb:
|
54 |
for chunk in chain.stream(input_dict, config={"tags": ["SUP'ASSISTANT"]}):
|
55 |
full_response += chunk.content
|
@@ -58,23 +64,24 @@ if prompt := st.chat_input(placeholder="What do you need to know about SUP'COM ?
|
|
58 |
st.session_state.run_id = cb.traced_runs[0].id
|
59 |
message_placeholder.markdown(full_response)
|
60 |
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
|
|
78 |
|
79 |
|
80 |
|
@@ -106,35 +113,37 @@ if st.session_state.get("run_id"):
|
|
106 |
|
107 |
# Record the feedback with the formulated feedback type string
|
108 |
# and optional comment
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
|
|
119 |
else:
|
120 |
st.warning("Invalid feedback score.")
|
121 |
-
if feedback.get("text"):
|
122 |
-
comment = feedback.get("text")
|
123 |
-
feedback_embedding = get_embeddings(comment)
|
124 |
-
else:
|
125 |
-
comment = "no comment"
|
126 |
-
feedback_embedding = get_embeddings(comment)
|
127 |
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
],
|
137 |
-
parallel=4,
|
138 |
-
max_retries=3,
|
139 |
-
)
|
140 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
42 |
with st.chat_message(msg.type, avatar=avatar):
|
43 |
st.markdown(msg.content)
|
44 |
|
45 |
+
|
46 |
+
prompt = st.chat_input(placeholder="What do you need to know about SUP'COM ?")
|
47 |
+
|
48 |
+
if prompt :
|
49 |
+
with st.chat_message("user"):
|
50 |
+
st.write(prompt)
|
51 |
+
|
52 |
with st.chat_message("assistant", avatar="🦜"):
|
53 |
message_placeholder = st.empty()
|
54 |
full_response = ""
|
55 |
# Define the basic input structure for the chains
|
56 |
input_dict = {"input": prompt}
|
57 |
|
58 |
+
|
59 |
with collect_runs() as cb:
|
60 |
for chunk in chain.stream(input_dict, config={"tags": ["SUP'ASSISTANT"]}):
|
61 |
full_response += chunk.content
|
|
|
64 |
st.session_state.run_id = cb.traced_runs[0].id
|
65 |
message_placeholder.markdown(full_response)
|
66 |
|
67 |
+
with st.spinner("Just a sec! Dont enter prompts while loading pelase!"):
|
68 |
+
run_id = st.session_state.run_id
|
69 |
+
question_embedding = get_embeddings(prompt)
|
70 |
+
answer_embedding = get_embeddings(full_response)
|
71 |
+
# Add question and answer to Qdrant
|
72 |
+
qdrant_client.upload_collection(
|
73 |
+
collection_name="chat-history",
|
74 |
+
payload=[
|
75 |
+
{"text": prompt, "type": "question", "question_ID": run_id},
|
76 |
+
{"text": full_response, "type": "answer", "question_ID": run_id}
|
77 |
+
],
|
78 |
+
vectors=[
|
79 |
+
question_embedding,
|
80 |
+
answer_embedding,
|
81 |
+
],
|
82 |
+
parallel=4,
|
83 |
+
max_retries=3,
|
84 |
+
)
|
85 |
|
86 |
|
87 |
|
|
|
113 |
|
114 |
# Record the feedback with the formulated feedback type string
|
115 |
# and optional comment
|
116 |
+
with st.spinner("Just a sec! Dont enter prompts while loading pelase!"):
|
117 |
+
feedback_record = client.create_feedback(
|
118 |
+
run_id,
|
119 |
+
feedback_type_str,
|
120 |
+
score=score,
|
121 |
+
comment=feedback.get("text"),
|
122 |
+
)
|
123 |
+
st.session_state.feedback = {
|
124 |
+
"feedback_id": str(feedback_record.id),
|
125 |
+
"score": score,
|
126 |
+
}
|
127 |
else:
|
128 |
st.warning("Invalid feedback score.")
|
|
|
|
|
|
|
|
|
|
|
|
|
129 |
|
130 |
+
with st.spinner("Just a sec! Dont enter prompts while loading pelase!"):
|
131 |
+
if feedback.get("text"):
|
132 |
+
comment = feedback.get("text")
|
133 |
+
feedback_embedding = get_embeddings(comment)
|
134 |
+
else:
|
135 |
+
comment = "no comment"
|
136 |
+
feedback_embedding = get_embeddings(comment)
|
137 |
+
|
|
|
|
|
|
|
|
|
138 |
|
139 |
+
qdrant_client.upload_collection(
|
140 |
+
collection_name="chat-history",
|
141 |
+
payload=[
|
142 |
+
{"text": comment,"Score:":score, "type": "feedback", "question_ID": run_id}
|
143 |
+
],
|
144 |
+
vectors=[
|
145 |
+
feedback_embedding
|
146 |
+
],
|
147 |
+
parallel=4,
|
148 |
+
max_retries=3,
|
149 |
+
)
|