-
Notifications
You must be signed in to change notification settings - Fork 1
Open
Description
I have rewrite the function, new function called reorder.
Keeping a record of reorder_3 here for now incase any issues.
# works for all
reorder_3 <- function(lvls, chat = NULL, ...) {
chat$clone()
chat$set_turns(list())
out <- chat$chat(paste0(
"Rank the sentiment scores for each level of the input: ",
paste(lvls, collapse = ", "), ". ",
"Positive connotations like satisfied or likely should have positive scores.
Negative connotations like unsatisfied or unlikely should have negative scores.
Satisfied should have a higher score than somewhat satisfied.
Agree should have a higher score than somewhat agree.
Neutral elements should have a score of 0.
Just give the scores. Return result only in JSON object.
Return a valid JSON object without any backticks around it.
No commentary. "))
out_json <- jsonlite::fromJSON(out)
vec <- unlist(out_json)
# break ties
if(any(duplicated(vec))) {
dups <- vec[duplicated(vec)]
out2 <- chat$chat(paste0(
"Rank the sentiment scores for each level of the input: ",
paste(lvls[vec %in% dups], collapse = ", "), ". ",
"Positive connotations like satisfied or likely should have positive scores.
Negative connotations like unsatisfied or unlikely should have negative scores.
Satisfied should have a higher score than somewhat satisfied.
Agree should have a higher score than somewhat agree.
Neutral elements should have a score of 0.
Just give the scores. Return result only in JSON object.
Return a valid JSON object without any backticks around it.
No commentary. ",
...
))
out2_json <- jsonlite::fromJSON(out2)
vec2 <- unlist(out2_json)
vec2 <- vec2 / sum(vec2)
vec[vec %in% dups] <- vec[vec %in% dups] + vec2
}
res <- names(sort(vec))
if(length(vec) != length(lvls)) {
cli::cli_warn("Could not reorder the levels meaningfully.")
return(lvls)
}
if(!all(res %in% lvls)) {
res <- names(sort(setNames(vec, lvls)))
}
res
}
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels