From 25d9e4aaadb5b4b2000b684d2945faa8065964f1 Mon Sep 17 00:00:00 2001 From: "Thomas A. Christensen II" <25492070+MillironX@users.noreply.github.com> Date: Wed, 4 Sep 2024 17:12:54 -0500 Subject: [PATCH] feat: Add question-by-question theme analysis --- main.jl | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/main.jl b/main.jl index fb1146d..46eceec 100755 --- a/main.jl +++ b/main.jl @@ -41,7 +41,10 @@ function logged_prompt(prompt) return response end #function +question_dict = Dict() + for q in questions + # Summarize the major themes among all answers analysis_prompt = """ The following is a list of answers to a survey with one response per paragraph: @@ -63,9 +66,61 @@ for q in questions analysis_response = logged_prompt(analysis_prompt) + + # Compile all themes that Llama3 identified. + # Llama3 tends to summarize each theme with a bolded statement. + # We will extract the bolded statements to compile themes + themes = String[] + for l in eachline(IOBuffer(analysis_response)) + m = match(r"^[1-9]+\. \*\*(.+)\*\*:", l) + isnothing(m) || push!(themes, first(m)) + end #for + @info "Found themes $themes" + + answer_dict = Dict() + + # Now go back through each answer and check if it is addressing the theme noted + for (i, a) in enumerate(skipmissing(survey_data[!, q])) + i == 1 && continue #first "answer" is the question + + theme_dict = Dict{String,Union{Bool,Missing}}() + + for t in themes + theme_prompt = """ + The following was answered as a free-response answer on a survey: + + $a + + --- + + Does this answer deal with the theme of $t? Answer yes or no. + """ + + theme_response = logged_prompt(theme_prompt) + + if startswith(lowercase(theme_response), "yes") + theme_dict[t] = true + elseif startswith(lowercase(theme_response), "no") + theme_dict[t] = false + else + theme_dict[t] = missing + end #if + end #for + + answer_dict[a] = theme_dict + + end #for + + question_dict[q] = answer_dict + end #for +open("results.json", "w") do io + JSON3.write(io, question_dict) +end + + # Compile comments from all requested questions for q in questions open("$q.md", "w") do f