Skip to content

Commit f4beb00

Browse files
committed
ai_text for ollama, small fix ai_validate
1 parent de7ed6d commit f4beb00

File tree

5 files changed

+25
-21
lines changed

5 files changed

+25
-21
lines changed

R/ai_salience.R

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
#' }
2525
#' @export
2626
ai_salience <- function(.data, topics, chat_fn, ..., verbose = TRUE) {
27-
27+
2828
# Predefine the type_object for salience classification
2929
predefined_type_object <- type_array(
3030
"Array of classification results. The scores should sum to 1.",
@@ -33,13 +33,13 @@ ai_salience <- function(.data, topics, chat_fn, ..., verbose = TRUE) {
3333
score = type_number("The classification score for the category, ranging from 0.0 to 1.0")
3434
)
3535
)
36-
36+
3737
# Call ai_text with pre-set type_object and flexible arguments
3838
ai_text(
39-
.data = .data,
40-
chat_fn = chat_fn,
41-
type_object = predefined_type_object,
42-
verbose = verbose,
43-
...
39+
.data = .data,
40+
chat_fn = chat_fn,
41+
type_object = predefined_type_object,
42+
verbose = verbose,
43+
...
4444
)
4545
}

R/ai_text.R

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#' Structured AI analysis texts
1+
#' Structured AI analysis of texts
22
#'
33
#' This function applies AI-assisted analysis to each document in a character
44
#' vector or a docvar in a [corpus][quanteda::corpus()], using a structured
@@ -37,7 +37,7 @@ ai_text <- function(.data, chat_fn, ..., type_object, few_shot_examples = NULL,
3737
if (!is.character(.data))
3838
stop("Unsupported data type for ai_text")
3939

40-
args <- rlang::list2()
40+
args <- rlang::list2(...)
4141

4242
if (is.null(names(.data))) names(.data) <- as.character(seq_along(.data))
4343

@@ -65,10 +65,6 @@ ai_text <- function(.data, chat_fn, ..., type_object, few_shot_examples = NULL,
6565
}
6666
}
6767

68-
if (!"model" %in% names(args) && identical(chat_fn, chat_openai)) {
69-
args <- c(args, list(model = "gpt-4o"))
70-
}
71-
7268
chat <- suppressMessages(do.call(chat_fn, args))
7369
model <- chat$get_model()
7470

@@ -92,7 +88,9 @@ ai_text <- function(.data, chat_fn, ..., type_object, few_shot_examples = NULL,
9288
})
9389
}
9490

95-
df_results <- dplyr::bind_rows(as.list(result_env), .id = "id")
91+
df_list <- lapply(names(.data), function(doc_id) result_env[[doc_id]])
92+
names(df_list) <- names(.data)
93+
df_results <- dplyr::bind_rows(df_list, .id = "id")
9694
rownames(df_results) <- NULL
9795
if (verbose) cat("Finished.\n")
9896

R/ai_validate.R

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
1-
#' Starts an interactive app to manually validate the documents in a corpus
2-
#' which were summarized, labelled, or scored by an LLM.
1+
#' Starts an interactive app to manually validate the output of an LLM
2+
#' stored in a character vector
33
#'
4+
#' This function launches a Shiny app that allows users to manually validate
5+
#' the output of a LLM analysis, such as ai_score
46
#' The comments from manual validation for each text are added as an additional
57
#' docvar to the input data with all texts not yet validated as `NA`.
68
#' @param text a character or [quanteda::corpus] object containing the
79
#' documents to be manually validated
810
#' @param llm_output a character string; the name of the LLM output column which
911
#' contains the summaries, labels, or scores to be validated
10-
#' @param llm_evidence **to be documented**
12+
#' @param llm_evidence a character vector; the name of an additional LLM output
13+
#' such as evidence or justifications provided by the LLM
1114
#' @param verbose logical; output a progress indicator if `TRUE`
1215
#' @inheritParams ai_text
1316
#' @return character; the response from the manual validation with a length

man/ai_text.Rd

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/ai_validate.Rd

Lines changed: 6 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)