Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
justinjm committed Feb 21, 2024
1 parent 1fba50d commit 8e72d9b
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions R/gemini.R
Original file line number Diff line number Diff line change
Expand Up @@ -115,12 +115,9 @@ gcva_gemini_text <- function(projectId = gcva_project_get(),

response <- f(the_body = requestBody)

# response

# save candidates object from response to make parsing easier
candidates <- response$candidates

n <- length(candidates)

# Define a function to safely extract the text
extract_text <- function(candidate) {
if (!is.null(candidate[["content"]]) &&
Expand All @@ -133,10 +130,10 @@ gcva_gemini_text <- function(projectId = gcva_project_get(),
}
}

# Use lapply to apply the function to each element of rg_candidates
# Use lapply to apply the function to each element of candidates
texts <- lapply(candidates, extract_text)

# Concatenate all texts into a single string
# Concatenate all texts into a single string for output
all_texts <- paste(unlist(texts), collapse = " ")

all_texts
Expand Down

0 comments on commit 8e72d9b

Please sign in to comment.