# Define a custom codebook
my_codebook <- qlm_codebook(
name = "Sentiment",
instructions = "Rate the sentiment from -1 (negative) to 1 (positive).",
schema = type_object(
score = type_number("Sentiment score from -1 to 1"),
explanation = type_string("Brief explanation")
)
)
# With a role
my_codebook_role <- qlm_codebook(
name = "Sentiment",
instructions = "Rate the sentiment from -1 (negative) to 1 (positive).",
schema = type_object(
score = type_number("Sentiment score from -1 to 1"),
explanation = type_string("Brief explanation")
),
role = "You are an expert sentiment analyst."
)
# With explicit measurement levels
my_codebook_levels <- qlm_codebook(
name = "Sentiment",
instructions = "Rate the sentiment from -1 (negative) to 1 (positive).",
schema = type_object(
score = type_number("Sentiment score from -1 to 1"),
explanation = type_string("Brief explanation")
),
levels = list(score = "interval", explanation = "nominal")
)
# \donttest{
# Use with qlm_code() (requires API key)
texts <- c("I love this!", "This is terrible.")
coded <- qlm_code(texts, my_codebook, model = "openai/gpt-4o-mini")
coded
# }
Run the code above in your browser using DataLab