verbessertes Feedback

This commit is contained in:
Lars 2025-12-09 22:43:38 +01:00
parent 2d0913cf3b
commit ec33163d98

View File

@ -107,7 +107,7 @@ def render_intent_badge(intent, source):
def render_sources(sources, query_id):
"""
Rendert Quellen inklusive granularem Feedback-Mechanismus.
Rendert Quellen inklusive granularem Feedback-Mechanismus (1-5 via Faces).
"""
if not sources:
return
@ -136,22 +136,25 @@ def render_sources(sources, query_id):
for r in hit['explanation'].get('reasons', []):
st.caption(f"- {r.get('message')}")
# 3. Granulares Feedback (Source Level)
# 3. Granulares Feedback (Source Level) - JETZT MIT NUANCEN
st.markdown("---")
c1, c2 = st.columns([3, 1])
c1, c2 = st.columns([2, 2])
with c1:
st.caption("War diese Quelle hilfreich für die Antwort?")
st.caption("Relevanz dieser Quelle:")
with c2:
# Callback Wrapper für Source-Feedback
def on_source_fb(qid=query_id, nid=node_id, k=f"fb_src_{node_id}"):
val = st.session_state.get(k)
# Mapping: Thumbs Up (1) -> Score 5, Thumbs Down (0) -> Score 1
mapped_score = 5 if val == 1 else 1
submit_feedback(qid, nid, mapped_score, comment="Source Feedback via UI")
# Mapping:
# Faces liefert 0 (😞) bis 4 (😀).
# Wir mappen das auf 1-5 für das Backend.
if val is not None:
submit_feedback(qid, nid, val + 1, comment="Source Feedback (Faces)")
# 'faces' bietet 5 Stufen: 😞(1) 🙁(2) 😐(3) 🙂(4) 😀(5)
st.feedback(
"thumbs",
key=f"fb_src_{query_id}_{node_id}", # Unique Key pro Query/Node
"faces",
key=f"fb_src_{query_id}_{node_id}",
on_change=on_source_fb,
kwargs={"qid": query_id, "nid": node_id, "k": f"fb_src_{query_id}_{node_id}"}
)