Skip to contents

This function takes the statistics generated from analyse_gpx() and creates a prompt that can be sent to a large language model (LLM) using the ellmer package. The prompt includes a default string of text with the statistics appended to it, asking the LLM to generate a title and description for the GPX route.

Usage

gen_description(stats, platform, api_key, model, prompt = NULL, ...)

Arguments

stats

A named list of route statistics generated by analyse_gpx().

platform

Character string. This maps onto the chat_*() functions available in the ellmer package. (See https://ellmer.tidyverse.org/reference/index.html) Examples include:

  • "openai" - for chat_openai()

  • "azure" - for chat_azure()

  • "gemini" - for chat_gemini(), and so on.

api_key

Character string. The API key for the LLM service.

model

Character string. The model to use for the LLM (e.g., "gpt-3.5-turbo").

prompt

Character string. A custom prompt to use for generating the title and description. If set to NULL (default), the function uses the default prompt stored in the package.

...

Additional arguments passed to the ellmer::chat_completion() function.

Value

A character string containing the response from the LLM, including the title and description.

Details

The function constructs a prompt that describes the route based on the provided statistics. It then sends the prompt to the LLM using the ellmer package and returns the generated response.

Examples

if (FALSE) { # \dontrun{
gpx_path <- system.file("extdata", "icc_intro_ride.gpx", package = "gpxtoolbox")
gpx_path %>%
  analyse_gpx(return = "data") %>%
  calculate_route_stats() %>%
  gen_description(
    platform = "azure",
    api_key = Sys.getenv("AZURE_OPENAI_API_KEY"),
    deployment_id = "gpt-4o-mini"
  )
} # }