-
Notifications
You must be signed in to change notification settings - Fork 0
Add trajectory reviewer #80
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+2,918
−77
Merged
Changes from all commits
Commits
Show all changes
42 commits
Select commit
Hold shift + click to select a range
8664f85
Add basic trajectory viewer
skaltman 8ef4287
Add tests for side conversation filtering and viewer interactions
skaltman b18623e
Add review functionality to trajectory viewer with flagging and annot…
skaltman 7ed5e88
Use commons colors for conversation
skaltman 522932d
Simplify notes label and redesign note styling
skaltman 49dcabd
Replace value boxes with interactive trust plot
skaltman 2c0306b
Add review files to gitignore
skaltman d9ae2f7
Replace client-side SVG timeline chart with plotly widget
skaltman 8fa65b9
Add plotly as a dependency
skaltman ed4cc72
Add resizable notes pane and allow conversation-level annotations
skaltman c5e1faa
Increase border-radius of exchange message boxes from 0.5rem to 1rem
skaltman a92b3bb
Implement adaptive time binning for timeline chart
skaltman 143e08a
Refactor timeline tooltip to render as per-bin card instead of unifie…
skaltman 32e8fc4
Auto-scroll to selected exchange when opening conversation
skaltman 0de211a
Simplify trajectory transcript handling and improve timeline binning …
skaltman cdd3bea
Add keyboard shortcut to save note with Enter key
skaltman 8d4371a
Add tooltip to flag button
skaltman abf4a52
Fix stylesheet load order and hover behavior in timeline chart
skaltman 5c89ce5
Add tool display reconstruction
skaltman 9d78a3c
Add review log reading and schema versioning for trajectory reviews
skaltman 152299d
Rename trajectory review functions to trajectory_*():
skaltman b64d8fe
Fix plotly hover text rendering for single-bin timelines
skaltman c8bdf77
Merge remote-tracking branch 'origin/main' into view-trajectories-53
skaltman 80c5280
Remove trust pills from conversation entries
skaltman cb1b93b
Update messaging in trajectory review prompt for clarity
skaltman 4df1abc
Refactor timeline code into separate file and simplify review validation
skaltman 16532b4
Make review flags and notes app-level
skaltman 7774abb
Improve exchange field validation
skaltman 0ddfdd2
Simplify comments
skaltman c25938e
Remove another comment
skaltman ff314ea
Replace custom resizable pane with bslib's layout_sidebar component
skaltman 4f71dc6
Replace custom textarea + button with `bslib::input_submit_textarea` …
skaltman 7df40ba
Replace shinyWidgets::airDatepickerInput with shiny::dateRangeInput
skaltman b66b3be
Remove shinyWidgets from dependencies
skaltman 838de7b
Remove exported `trajectory_reviews_read()` function
skaltman 9b39803
Use barplots for sparse data and right-align dates
skaltman ccee795
Add tests for timeline_plot sparse parameter and bin labels
skaltman 1f25c92
Trim more comments and tests
skaltman 785742f
Prepopulate trajectory transcripts with shinychat
skaltman 3aa0dba
`read_trajectories()` -> `trajectory_read()`
simonpcouch d857cb3
merge main into trajectory reviewer
simonpcouch 3b524d1
add Sara Altman as an author
simonpcouch File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,4 +14,5 @@ CLAUDE.md | |
| ^pkgdown$ | ||
| ^\.github$ | ||
| inst/hex/ | ||
| ^commons-review\.jsonl$ | ||
| inst/manifest.json | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,3 +14,4 @@ CLAUDE.local.md | |
| AGENTS.override.md | ||
| inst/hex/output | ||
| .shinychat/ | ||
| commons-review.jsonl | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,166 @@ | ||
| new_review_event <- function( | ||
| trajectories, | ||
| key, | ||
| action, | ||
| user, | ||
| source = trajectory_source(trajectories), | ||
| note = NULL | ||
| ) { | ||
| exchange <- key$exchange | ||
| record <- list( | ||
| schema_version = 1L, | ||
| event_id = new_review_event_id(), | ||
| time = review_timestamp(), | ||
| user = user, | ||
| source = source, | ||
| conversation = names(trajectories)[[key$conversation]], | ||
| exchange = exchange, | ||
| action = action, | ||
| note = note | ||
| ) | ||
|
|
||
| if (!is.null(exchange)) { | ||
| turns <- split_exchanges(trajectories[[key$conversation]])[[exchange]] | ||
| provenance <- exchange_provenance(turns) | ||
| record$question <- turns[[1]]@text | ||
| record$tag <- if (is.na(provenance$tag)) "none" else provenance$tag | ||
| } | ||
|
|
||
| record | ||
| } | ||
|
|
||
| new_review_event_id <- function() { | ||
| suffix <- paste(sample(c(letters, 0:9), 12, replace = TRUE), collapse = "") | ||
| paste0(format(Sys.time(), "%Y%m%dt%H%M%OS6", tz = "UTC"), "-", suffix) | ||
| } | ||
|
|
||
| review_timestamp <- function() { | ||
| format(Sys.time(), "%Y-%m-%dT%H:%M:%SZ", tz = "UTC") | ||
| } | ||
|
|
||
| review_user <- function(session) { | ||
| user <- session$user | ||
| if (!rlang::is_string(user) || !nzchar(user)) { | ||
| return("unknown") | ||
| } | ||
| user | ||
| } | ||
|
|
||
| trajectory_source <- function(trajectories) { | ||
| attr(trajectories, "source") %||% list(kind = "unknown") | ||
| } | ||
|
|
||
| append_review_record <- function(file, record) { | ||
| line <- jsonlite::toJSON(drop_nulls(record), auto_unbox = TRUE) | ||
| cat(line, "\n", file = file, sep = "", append = TRUE) | ||
| } | ||
|
|
||
| read_review_records <- function(file) { | ||
| if (!file.exists(file)) { | ||
| return(list()) | ||
| } | ||
|
|
||
| records <- list() | ||
| invalid <- integer() | ||
| lines <- readLines(file, warn = FALSE) | ||
| for (i in seq_along(lines)) { | ||
| record <- tryCatch( | ||
| jsonlite::fromJSON(lines[[i]], simplifyVector = FALSE), | ||
| error = function(err) NULL | ||
| ) | ||
| if (!is_review_record(record)) { | ||
| invalid <- c(invalid, i) | ||
| next | ||
| } | ||
| records[[length(records) + 1]] <- record | ||
| } | ||
|
|
||
| if (length(invalid) > 0) { | ||
| cli::cli_warn( | ||
| "Ignoring {cli::qty(invalid)}invalid review record{?s} on line{?s} | ||
| {invalid} of {.file {file}}." | ||
| ) | ||
| } | ||
| records | ||
| } | ||
|
|
||
| is_review_record <- function(record) { | ||
| if ( | ||
| !is.list(record) || | ||
| !rlang::is_string(record$conversation) || | ||
| !rlang::is_string(record$action) || | ||
| !record$action %in% c("flag", "unflag", "note") | ||
| ) { | ||
| return(FALSE) | ||
| } | ||
| exchange <- record$exchange | ||
| if ( | ||
| !is.null(exchange) && | ||
| (!is.numeric(exchange) || | ||
| length(exchange) != 1 || | ||
| !is.finite(exchange) || | ||
| exchange < 1 || | ||
| exchange != trunc(exchange)) | ||
| ) { | ||
| return(FALSE) | ||
| } | ||
| !identical(record$action, "note") || rlang::is_string(record$note) | ||
| } | ||
|
|
||
| actionable_review_records <- function(records) { | ||
| note_indices <- integer() | ||
| latest_flag_indices <- integer() | ||
|
|
||
| for (i in seq_along(records)) { | ||
| record <- records[[i]] | ||
| if (identical(record$action, "note")) { | ||
| note_indices <- c(note_indices, i) | ||
| } else { | ||
| key <- review_key(record$conversation, record$exchange) | ||
| latest_flag_indices[[key]] <- i | ||
| } | ||
| } | ||
|
|
||
| active_flag_indices <- unname(latest_flag_indices) | ||
| active_flag_indices <- active_flag_indices[vapply( | ||
| records[active_flag_indices], | ||
| function(record) identical(record$action, "flag"), | ||
| logical(1) | ||
| )] | ||
| records[sort(c(note_indices, active_flag_indices))] | ||
| } | ||
|
|
||
| review_flags <- function(records) { | ||
| active <- Filter( | ||
| function(record) identical(record$action, "flag"), | ||
| actionable_review_records(records) | ||
| ) | ||
| vapply( | ||
| active, | ||
| function(record) review_key(record$conversation, record$exchange), | ||
| character(1) | ||
| ) | ||
| } | ||
|
|
||
| review_notes <- function(records) { | ||
| Filter( | ||
| function(record) identical(record$action, "note"), | ||
| records | ||
| ) | ||
| } | ||
|
|
||
| review_key <- function(id, exchange = NULL) { | ||
| paste(c(id, exchange), collapse = "#") | ||
| } | ||
|
|
||
| parse_review_time <- function(x) { | ||
| time <- as.POSIXct( | ||
| x, | ||
| format = "%Y-%m-%dT%H:%M:%SZ", | ||
| tz = "UTC" | ||
| ) | ||
| if (!is.na(time)) { | ||
| return(time) | ||
| } | ||
| as.POSIXct(x, format = "%Y-%m-%dT%H:%M:%S%z") | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.