Skip to contents

Convenience wrapper for generate_topic_content with content_type = "survey_item". Generates Likert-scale survey items for scale development.

Usage

generate_survey_items(
  topic_terms_df,
  topic_var = "topic",
  term_var = "term",
  weight_var = "beta",
  provider = c("openai", "ollama"),
  model = "gpt-3.5-turbo",
  temperature = 0,
  system_prompt = NULL,
  user_prompt_template = NULL,
  max_tokens = 150,
  api_key = NULL,
  verbose = TRUE
)

Arguments

topic_terms_df

A data frame with topic terms, containing columns for topic identifier, term, and optionally term weight (beta).

topic_var

Name of the column containing topic identifiers (default: "topic").

term_var

Name of the column containing terms (default: "term").

weight_var

Name of the column containing term weights (default: "beta").

provider

LLM provider: "openai" or "ollama" (default: "openai").

model

Model name. For OpenAI: "gpt-3.5-turbo", "gpt-4", etc. For Ollama: "llama3", "mistral", etc.

temperature

Sampling temperature (0-2). Lower = more deterministic (default: 0).

system_prompt

Custom system prompt. If NULL, uses default for content_type.

user_prompt_template

Custom user prompt template with {terms} placeholder. If NULL, uses default for content_type.

max_tokens

Maximum tokens for response (default: 150).

api_key

OpenAI API key. If NULL, reads from OPENAI_API_KEY environment variable.

verbose

Logical, if TRUE, prints progress messages.

Value

A data frame with generated survey items joined to original topic terms.

Examples

if (FALSE) { # \dontrun{
survey_items <- generate_survey_items(
  topic_terms_df = top_terms,
  provider = "openai",
  model = "gpt-3.5-turbo"
)
} # }