jcrodriguez1989/chatgpt

Write function

nicholas-masel opened this issue ยท 3 comments

Cool stuff, thanks for putting this together!

How about a write function like:

write_code <- function(description) {
  prompt <- paste0('Write R code that: "', description, '"')
  trimws(sapply(chatgpt:::gpt_get_completions(prompt)$choices, function(x) x$text))
}

cat(write_code("produces a bar plot using ggplot"))

Which returned:

# Create data frame
d <- data.frame(
  place = c("USA", "UK", "Canada", "Australia"),
  values = c(25, 18, 8, 7)
)

# Create bar plot
ggplot(d, aes(x = place, y = values)) + 
  geom_col()

I'm happy to put in a PR if you like the recommendation, but I did almost nothing :) Just a copy and paste of your function with a new name and request.

Hi @nicholas-masel , yes, this would be awesome, could you create a PR?
But, as another contributor mentioned, could it be something more general? I think a function named ask_chatgpt(message) would be awesome.
We have the Ask ChatGPT addin but not the exported function.
It would be great if you take a look on how the rest of the functions are built.
thanks for your contribution!

Hey @jcrodriguez1989! I reviewed your code. Is the idea that ask_chatgpt() would cover all queries, and the only other functions exported are to support the addins that help pass code to and from chatgpt completions?

If that's true, what about if the write_code() was an addin that would take your request and write it to a script for you?

I love your package is focused on helping people with R, and feel it will be useful for new and advanced R users. I see functions supporting everything related to coding, with the exception of write, which is a cool feature. I know ask_chatgpt() would cover this, technically it covers all of them ๐Ÿ˜ƒ , but even if redundant, it makes it feel complete. Probably some OCD thing I should get checked out ๐Ÿ˜† That is my last pitch for a stand along write_code() ๐Ÿ˜ƒ

I'll go ahead an surface your internal completion function as ask_chatgpt() and hold off on a standalone write_code().

Closed by #4