This section shows how to extract webpage content, generate a draft using AI, and fine-tune it.
Step 3.1: Extract Main Content
First, copy the URL of the webpage you wish to analyze. Then, extract its main text content using an extraction function provided via an external source.
# Load the extraction script from the web
source("https://gist.githubusercontent.com/kumeS/f252b967f8060dcc56c7feb1e33c8b85/raw/617b25e2eaa0fdf581dbc1b77009b7bf068c8847/extract_and_decode_main_content.R")
# Example usage:
url <- "https://..."
# Alternatively, read the URL from the clipboard:
url <- clipr::read_clip()
# Uncomment the following line to open the URL in your browser:
# browseURL(url)
body_content <- extract_and_decode_main_content(url)
print(body_content)
# Pass URLs copied to the clipboard, extract the content, and write the result back to the clipboard:
library(magrittr)
clipr::read_clip() %>%
extract_and_decode_main_content() %>%
clipr::write_clip()
Step 3.2: Generate and Fine-Tune the Draft
Use the chat4R_streaming
function to generate a draft based on the extracted content. A system message (sourced from an external file) provides the context to guide the AI’s response.
# Define the system settings by sourcing the external file
source("https://gist.githubusercontent.com/kumeS/5452be22101600bee91d4153f1d82680/raw/cfd4da6fcd012e3544f3bc4d1a9ddb3854df6dfd/system_set.R")
res <- chat4R_streaming(
content = body_content,
Model = "gpt-4o-mini",
temperature = 1,
system_set = system_set
)
Step 3.3: Chain Functions Using Pipes
For a streamlined workflow, you can pipe the execution of multiple functions together using the magrittr
package. In this example, a URL is read from the clipboard, its content extracted, and then passed directly to chat4R_streaming
:
library(magrittr)
res <- clipr::read_clip() %>%
extract_and_decode_main_content() %>%
chat4R_streaming(
content = .,
Model = "gpt-4o-mini",
temperature = 1,
system_set = system_set
)