
Make a single GPT request
gpt_req.RdForm a request to the OpenAI API, execute the request, and format the response as a tibble.
Usage
gpt_req(
messages,
model = "gpt-3.5-turbo",
temperature = 0,
max_tokens = NULL,
logit_bias = NULL,
api_key = get_api_key()
)Arguments
- messages
A dataframe with "role" and "content" columns.
- model
The GPT model to use, "gpt-3.5-turbo" is default
- temperature
The temperature parameter, default 0
- max_tokens
The max_tokens parameter, default 1
- logit_bias
The logit_bias parameter.
- api_key
The OpenAI API key. Will be retrieved automatically if set with set_api_key() or if GPTSALDANA_KEY is set in .Renviron
Value
A tibble with one row containing gpt_response, gpt_model, gpt_finish_reason, gpt_prompt_tokens, gpt_completion_tokens
Examples
gpt_req(messages = data.frame(role = c("system","user"),
content = c("Your job is to answer with the word class of the word the user submits.","quickly")
)
)
#> # A tibble: 1 × 10
#> gpt_response gpt_request gpt_model gpt_finish_reason gpt_prompt_tokens
#> <chr> <named list> <chr> <chr> <int>
#> 1 Adverb <df [2 × 2]> gpt-3.5-turbo-0… stop 29
#> # ℹ 5 more variables: gpt_completion_tokens <int>, gpt_total_tokens <int>,
#> # gpt_id <chr>, gpt_created <int>, gpt_system_fingerprint <chr>