Skip to contents

This function is a wrapper around ai_text to compute scores for documents using a chat function.

Usage

ai_score(.data, prompt, chat_fn, ..., verbose = TRUE)

Arguments

.data

a character or quanteda::corpus object containing the documents to be summarized

prompt

character; a prompt that defines the scoring criteria

chat_fn

function; a chat function from ellmer

...

additional arguments passed to chat_fn

verbose

logical; output a progress indicator if TRUE

Value

character; the response from the LLM with a length equal to the number of input documents, with the elements named with the input element names

Examples

if (FALSE) { # \dontrun{
library(quanteda)
library(ellmer)
# define a prompt for scoring documents
prompt <- "Score the following document on a scale of how much it aligns
with the political left. The political left is defined as groups which
advocate for social equality, government intervention in the economy,
and progressive policies. Use the following metrics:
SCORING METRIC:
3 : extremely left
2 : very left
1 : slightly left
0 : not at all left"
# compute scores for documents in the inaugural corpus
scores <- ai_score(data_corpus_inaugural[57:59], prompt,
                   chat_fn = chat_openai, model = "gpt-4o",
                   api_args = list(temperature = 0, seed = 42))
} # }