Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions pkg-py/src/commons/_provenance.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ class Tag(enum.StrEnum):

@dataclass(frozen=True)
class ProvenanceDisplay:
"""The words and styling one tag's pill renders with."""
"""The words and styling one tag's provenance marker renders with."""

label: str
icon: str | None
body: str
pill_class: str
dot_class: str | None


PROVENANCE_DISPLAY: dict[Tag, ProvenanceDisplay] = {
Expand All @@ -47,13 +47,13 @@ class ProvenanceDisplay:
body=(
"This answer comes from a governed calculation defined by your data team."
),
pill_class="trusted",
dot_class="verified",
),
Tag.B: ProvenanceDisplay(
label="Cited",
icon=None,
body="This answer includes supporting text verified against a trusted source.",
pill_class="cited",
dot_class=None,
),
Tag.C: ProvenanceDisplay(
label="Untrusted",
Expand All @@ -62,7 +62,7 @@ class ProvenanceDisplay:
"This answer was not produced by a governed calculation and has "
"no verified supporting citation. AI can be wrong."
),
pill_class="caution",
dot_class="untrusted",
),
}

Expand All @@ -72,7 +72,7 @@ def derive_provenance_tag(tags: Sequence[Tag], verified: bool) -> Tag | None:

A fallback claim remains fallback even when its answer also uses a governed
calculation, so its citation verdict takes precedence ("B beats A").
Returns ``None`` when no data tool ran, which shows no pill at all.
Returns ``None`` when no data tool ran, which shows no provenance marker.
"""
if Tag.B in tags:
return Tag.B if verified else Tag.C
Expand Down
4 changes: 2 additions & 2 deletions pkg-py/tests/test_provenance.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ def test_display_copy_matches_the_shared_fixture(name: str) -> None:
assert entry.label == expected["label"]
assert entry.body == expected["body"]
assert entry.icon == expected["icon"]
assert entry.pill_class == expected["pill_class"]
assert entry.dot_class == expected["dot_class"]


def test_every_tag_has_display_copy() -> None:
# A new Tag member without copy would render a pill with no words in it.
# A new Tag member without copy would render a marker with no words in it.
assert set(PROVENANCE_DISPLAY) == set(Tag)


Expand Down
6 changes: 3 additions & 3 deletions pkg-r/R/provenance.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ provenance_display <- list(
"This answer comes from a governed calculation defined by",
"your data team."
),
pill_class = "trusted"
dot_class = "verified"
),
B = list(
label = "Cited",
icon = NULL,
body = "This answer includes supporting text verified against a trusted source.",
pill_class = "cited"
dot_class = NULL
),
C = list(
label = "Untrusted",
Expand All @@ -21,7 +21,7 @@ provenance_display <- list(
"This answer was not produced by a governed calculation and has",
"no verified supporting citation. AI can be wrong."
),
pill_class = "caution"
dot_class = "untrusted"
)
)

Expand Down
51 changes: 24 additions & 27 deletions pkg-r/R/trajectory-review.R
Original file line number Diff line number Diff line change
Expand Up @@ -295,8 +295,8 @@ add_message_provenance <- function(messages, provenance) {
} else {
record$provenance_tag %||% NA_character_
}
pill <- commons_answer_pill(tag)
if (is.null(pill)) {
dot <- commons_answer_dot(tag)
if (is.null(dot)) {
next
}
candidates <- which(vapply(
Expand All @@ -311,60 +311,57 @@ add_message_provenance <- function(messages, provenance) {
next
}
index <- candidates[[length(candidates)]]
messages[[index]]$content <- append_provenance_pill(
messages[[index]]$content <- append_provenance_dot(
messages[[index]]$content,
pill
dot
)
}
messages
}

append_provenance_pill <- function(content, pill) {
append_provenance_dot <- function(content, dot) {
if (is.character(content)) {
return(list(content, pill))
return(list(content, dot))
}
c(content, list(pill))
c(content, list(dot))
}

commons_answer_pill <- function(tag) {
commons_answer_dot <- function(tag) {
entry <- provenance_display[[tag]]
if (is.null(entry)) {
if (is.null(entry) || is.null(entry$dot_class)) {
return(NULL)
}
htmltools::tags$span(
htmltools::tags$sup(
class = paste0(
"commons-answer-pill commons-answer-pill-",
entry$pill_class
"commons-answer-dot commons-answer-dot-",
entry$dot_class
),
title = entry$body,
`aria-label` = paste0(entry$label, ". ", entry$body),
role = "img",
tabindex = "0",
commons_pill_icon(entry$icon, entry$label),
htmltools::tags$span(entry$label),
commons_pill_tooltip(entry$body)
commons_dot_icon(entry$icon),
commons_dot_tooltip(entry$body)
)
}

commons_pill_tooltip <- function(text) {
htmltools::tags$span(class = "commons-tooltip", role = "tooltip", text)
}

commons_pill_icon <- function(file, alt) {
if (is.null(file)) {
return(NULL)
}
commons_dot_icon <- function(file) {
src <- commons_icon_url(file)
if (is.null(src)) {
return(NULL)
}

htmltools::tags$img(
src = src,
alt = alt,
class = "commons-answer-pill-icon"
alt = "",
class = "commons-answer-dot-mark"
)
}

commons_dot_tooltip <- function(text) {
htmltools::tags$span(class = "commons-tooltip", role = "tooltip", text)
}

seed_transcript_decorations <- function(
session,
id,
Expand Down Expand Up @@ -734,7 +731,7 @@ viewer_server <- function(
)
})

# A fresh id prevents stale pill timers from targeting a new transcript.
# A fresh id prevents stale decoration timers from targeting a new transcript.
output$transcript <- shiny::renderUI({
conversation <- selected_conversation()
if (is.null(conversation)) {
Expand Down Expand Up @@ -908,7 +905,7 @@ question_entry <- function(
htmltools::div(
class = "commons-viewer-entry-meta",
flag_marker(flagged),
commons_answer_pill(record$tag)
commons_answer_dot(record$tag)
)
)
)
Expand Down
4 changes: 2 additions & 2 deletions pkg-r/inst/figs/warning-icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions pkg-r/inst/www/commons-chat/citation-mark.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading