@@ -16,6 +16,7 @@ knitr::opts_chunk$set(
1616
1717``` {r setup}
1818library(scplotter)
19+ api_key_set <- !identical(Sys.getenv("OPENAI_API_KEY"), "")
1920```
2021
2122# Introduction
@@ -26,7 +27,7 @@ This vignette demonstrates how to use the `scplotter` package to visualize data
2627
2728` scplotter ` uses ` tidyprompt ` to provide a unified interface for different LLM providers. You can set up your preferred LLM provider using one of the [ wrappers] ( https://tjarkvandemerwe.github.io/tidyprompt/reference/index.html#llm-providers-chat-history ) provided by ` tidyprompt ` .
2829
29- ``` {r}
30+ ``` {r, eval = api_key_set }
3031# Set up LLM provider
3132provider <- tidyprompt::llm_provider_openai(
3233 parameters = list(model = "gpt-4o-mini", stream = getOption("tidyprompt.stream", TRUE)),
@@ -44,15 +45,15 @@ By default, `chat` will detects the data used for visualization from the `.Globa
4445
4546You can also ask to list the available data:
4647
47- ``` {r}
48+ ``` {r, eval = api_key_set }
4849chat$ask("List the available data that can be used for visualization.")
4950# or you can do it explicitly
5051# chat$list_data()
5152```
5253
5354To set up the data manually, you can use the ` set_data() ` method.
5455
55- ``` {r}
56+ ``` {r, eval = api_key_set }
5657chat$set_data(scplotter::cellphonedb_res)
5758# To let the LLM to detect the data from the prompt again:
5859chat$set_data(NULL)
@@ -64,7 +65,7 @@ To use your own data, you can either set the data manually or use the `set_data(
6465
6566You can list the available functions by using the ` list_tools() ` method.
6667
67- ``` {r}
68+ ``` {r, eval = api_key_set }
6869chat$list_tools()
6970# or you can ask the LLM to list the available functions
7071# chat$ask("List the available functions for visualizing data.")
@@ -75,20 +76,20 @@ The tool used for the visualization is determined by the LLM automatically from
7576# Visualize the data
7677You can visualize the data by using the ` ask() ` method. The LLM will automatically detect the data and the function to be used for visualization.
7778
78- ``` {r fig.width=7, fig.height=5}
79+ ``` {r, eval = api_key_set, fig.width=7, fig.height=5}
7980chat$ask("Generate a cell-cell communication plot for the cellphonedb_res data.")
8081```
8182
82- ``` {r fig.width=7, fig.height=6}
83+ ``` {r, eval = api_key_set, fig.width=7, fig.height=6}
8384# Previous conversation is memorized
8485chat$ask("Do a heatmap instead")
8586```
8687
87- ``` {r fig.width=7, fig.height=6}
88+ ``` {r, eval = api_key_set, fig.width=7, fig.height=6}
8889chat$ask("Add a title to the plot: 'Cell-Cell Communication Plot'")
8990```
9091
91- ``` {r}
92+ ``` {r, eval = api_key_set }
9293# To fetch the previous conversation
9394# Note that the response from the LLM is simplified in the history
9495chat$get_history()
@@ -101,7 +102,7 @@ chat$clear_history()
101102
102103You can set ` verbose ` to ` TRUE ` for all conversations when constructing the ` chat ` object. This will print the prompt and the response from the LLM.
103104
104- ``` {r fig.width=7, fig.height=5}
105+ ``` {r, eval = api_key_set, fig.width=7, fig.height=5}
105106chat <- SCPlotterChat$new(
106107 provider = provider,
107108 verbose = TRUE
@@ -111,7 +112,7 @@ chat$ask("Generate a cell-cell communication plot for the cellphonedb_res data."
111112
112113To only debug a single conversation, you can set ` verbose ` to ` TRUE ` in the ` ask() ` method.
113114
114- ``` {r fig.width=7, fig.height=5}
115+ ``` {r, eval = api_key_set, fig.width=7, fig.height=5}
115116chat <- SCPlotterChat$new(
116117 provider = provider,
117118 verbose = FALSE
0 commit comments