irudnyts / openai

An R package-wrapper around OpenAI API
https://irudnyts.github.io/openai/
Other
164 stars 28 forks source link

logprobs for chat completions only in python ver #56

Open csterbenz1 opened 7 months ago

csterbenz1 commented 7 months ago

API was recently updated to return logprobs for chat completions but the change appears to be only present in the python version and not the R version. Would really appreciate everything up to date and ported over!

irudnyts commented 7 months ago

Hi @csterbenz1, I totally agree! @openai should start contributing to this package and keep "everything up to date and ported over" 😂

Jokes aside, here is the feature you were looking for in the development version (do not forget to install it first):

remotes::install_github("irudnyts/openai", ref = "r6")
library(openai)

client <- OpenAI()
completion <- client$chat$completions$create(
    model = "gpt-3.5-turbo",
    messages = list(list("role" = "user", "content" = "What's up?")),
    logprobs = TRUE,
    top_logprobs = 2
)

completion$choices[[1]]$logprobs