sa_services() lists the external text services the application can ask for a longer written
interpretation, and sa_ask() sends one request to such a service and returns its text. Using a service is
optional: the application always shows the interpretation of stability::stab_interpret(), which is
computed from the results and needs no connection.
Usage
sa_services()
sa_ask(
service,
prompt,
model = NULL,
key = "",
max_tokens = 1500,
timeout = 90
)Arguments
- service
identifier of a service (column
idofsa_services()).- prompt
a list with elements
systemanduser(as returned bysa_prompt()), or a single character string.- model
model name (default: the one of
sa_services()).- key
the user's key for the service;
""(default) uses the environment variable of the service.- max_tokens
largest length of the answer, in tokens (default
1500).- timeout
seconds to wait (default
90).
Value
sa_services(): a data frame of the services. sa_ask(): the text of the answer (character),
or an error with the message of the service.
Details
The services are read from the file services.csv of the package (columns id, label,
format, url, model, key_env, and header, an extra header name=value).
Three request formats are supported:
"messages", "chat" and "generate", the formats of the three services in the file. The key is
taken from the argument key or, when it is empty, from the environment variable named in key_env,
so that it need not be typed into the application. The request is sent over HTTPS to the service's own address;
the key is never stored by the package.
What is sent is the text built by sa_prompt(): the name of the analysis, the trait, the size of the
trial, the interpretation of stab_interpret(), its facts and the first rows of the main table. No data file
is sent.
Author
Muhammad Yaseen (myaseen208@gmail.com)
Examples
sa_services()[, c("id", "format", "model")]
#> id format model
#> 1 anthropic messages claude-haiku-4-5
#> 2 openai chat gpt-4o-mini
#> 3 gemini generate gemini-2.5-flash
if (FALSE) { # \dontrun{
fit <-
stability::stab_reg(
.data = stability::ge_data
, .y = Yield
, .rep = Rep
, .gen = Gen
, .env = Env
)
p <-
sa_prompt(
x = fit
, higher_better = TRUE
, trait = NULL
, rows = 15L
)
sa_ask(
service = sa_services()$id[1]
, prompt = p
, model = sa_services()$model[1]
, key = ""
, max_tokens = 1500
, timeout = 90
)
} # }