Skip to contents

execute_workflow_on_df executes an AI workflow by applying a workflow object on an input dataframe (or tibble).

Usage

execute_workflow_on_df(
  df,
  prompt_column_name = "prompt",
  image_column_name = NA_character_,
  workflow_obj,
  result_column_name = "result",
  auto_use_df_variables = F
)

Arguments

df

The source dataframe or tibble to use as input for the workflow to execute.

prompt_column_name

A vector for the name of the column that corresponds to the prompts to send to the workflow. Defaults to "prompt"

image_column_name

An optional vector (defaults to NA) that corresponds to the images to be sent to the workflow. It can only work if you use a model with Vision capabilities and which such capability turned on.

workflow_obj

A workflow object containing all parameters describing the flow required for execution

result_column_name

A vector for the name of the column that corresponds to the outcome of the workflow. Defaults to "result". This is a new column that will be created.

auto_use_df_variables

A boolean value (defaults to FALSE). If TRUE, it will attempt to find column names that corresponds to parameters that can be used to modify the workflow, such as temperature, n_ctx, etc...

Value

the original df with the new column corresponding to the results of the workflow.

Details

This function executes an AI workflow by combining prompt vectors and a workflow object. If auto_use_df_variables is set to TRUE and you have the right columns to tweak the model for every line, you will end up with different parameters applied to the workflow for every line. The parameters recognized currently as columns are:

  • "temperature"

  • "n_predict"

  • "seed"

  • "num_ctx"

  • "model"

  • "overall_background"

  • "system_prompt"

  • "style_of_voice"

  • "frequency_penalty"

  • "presence_penalty"

  • "repeat_penalty"

  • "n_predict"

Examples

myflow <- ai_workflow() |> 
  set_connector("ollama")  |>
  set_model(model_name= "llama3.2:3b-instruct-q5_K_M") |> 
  set_n_predict(3000) |> 
  set_temperature(0.8) |>
  set_seed(seed = 13) |> 
  set_num_ctx(num_ctx = 5000) 
#> → Default IP address has been set to 127.0.0.1.
#> → Default port has been set to 11434.
  
df_test <- tibble::tribble(~prompt,~temperature,~seed,~system_prompt,~style_of_voice,
"why is the sky blue?", 0.8,13123,NA_character_,"Yoda",
"why is the sky blue?", 0.6,12321255,NA_character_,"Tolkien",
"why is the sky blue?", 0.2,12,"You are a expert in colorimetry.","George R Martin",
"why is the sky blue?", 0,11111111,NA_character_,"CS Lewis",
"what is 2+2 ??", 0.8,124,NA_character_,"Hemingway",
"what is 2+2 ??", 0,34343,NA_character_,"Gandalf",
"what is tequila made of?",0,34343,NA_character_,"Obama")

df_test <- df_test |> 
execute_workflow_on_df(workflow_obj = myflow, auto_use_df_variables=T)
#> → Will be using the following variables from the dataframe to supplement the workflow: temperature, seed, system_prompt, style_of_voice
#> → Frequency Penalty was not specified and given a default value of 1.
#> → Presence Penalty was not specified and given a default value of 1.5.
#> → Repeat Penalty was not specified and given a default value of 1.2.
#> → Mode was not specified and 'chat' was selected by default.
#> → Chat mode
#> → Frequency Penalty was not specified and given a default value of 1.
#> → Presence Penalty was not specified and given a default value of 1.5.
#> → Repeat Penalty was not specified and given a default value of 1.2.
#> → Mode was not specified and 'chat' was selected by default.
#> → Chat mode
#> → Frequency Penalty was not specified and given a default value of 1.
#> → Presence Penalty was not specified and given a default value of 1.5.
#> → Repeat Penalty was not specified and given a default value of 1.2.
#> → Mode was not specified and 'chat' was selected by default.
#> → Chat mode
#> → Frequency Penalty was not specified and given a default value of 1.
#> → Presence Penalty was not specified and given a default value of 1.5.
#> → Repeat Penalty was not specified and given a default value of 1.2.
#> → Mode was not specified and 'chat' was selected by default.
#> → Chat mode
#> → Frequency Penalty was not specified and given a default value of 1.
#> → Presence Penalty was not specified and given a default value of 1.5.
#> → Repeat Penalty was not specified and given a default value of 1.2.
#> → Mode was not specified and 'chat' was selected by default.
#> → Chat mode
#> → Frequency Penalty was not specified and given a default value of 1.
#> → Presence Penalty was not specified and given a default value of 1.5.
#> → Repeat Penalty was not specified and given a default value of 1.2.
#> → Mode was not specified and 'chat' was selected by default.
#> → Chat mode
#> → Frequency Penalty was not specified and given a default value of 1.
#> → Presence Penalty was not specified and given a default value of 1.5.
#> → Repeat Penalty was not specified and given a default value of 1.2.
#> → Mode was not specified and 'chat' was selected by default.
#> → Chat mode