jcrodriguez1989 / chatgpt

Interface to ChatGPT from R
GNU General Public License v3.0
311 stars 37 forks source link

Parameterise the tweaks within the commands #57

Open giuliogcantone opened 1 month ago

giuliogcantone commented 1 month ago

OPENAI_MODEL; defaults to "gpt-3.5-turbo" OPENAI_MAX_TOKENS; defaults to 256 OPENAI_TEMPERATURE; defaults to 1 OPENAI_TOP_P; defaults to 1 OPENAI_FREQUENCY_PENALTY; defaults to 0 OPENAI_PRESENCE_PENALTY; defaults to 0

Do you plan to parameterise this stuff directly as parameters of chatgpt::ask_chatgpt() ?

What should I do if I want to variate them (e.g. temperature) in a for cycle of prompts?

jcrodriguez1989 commented 1 month ago

Hi @giuliogcantone , at the moment I don't have enough time to dedicate to this repo. For now, if you are going to cycle parameters in a loop (sequential, non-parallel), you could just go setting the env variables in the loop, for example:

> lapply(c("gpt-3.5-turbo", "gpt-4", "FAKE_MODEL_TO_ERROR"), function(model_name) {
+   Sys.setenv(OPENAI_MODEL = model_name)
+   try(chatgpt::ask_chatgpt("Hi!"))
+ })
[[1]]
[1] "Hello! How can I assist you today?"

[[2]]
[1] "Hello! How can I assist you today?"

[[3]]
[1] "Error in gpt_get_completions(question, messages = chat_session_messages) : \n  list(message = \"The model `FAKE_MODEL_TO_ERROR` does not exist or you do not have access to it.\", type = \"invalid_request_error\", param = NULL, code = \"model_not_found\")\n"
attr(,"class")
[1] "try-error"
attr(,"condition")
<simpleError in gpt_get_completions(question, messages = chat_session_messages): list(message = "The model `FAKE_MODEL_TO_ERROR` does not exist or you do not have access to it.", type = "invalid_request_error", param = NULL, code = "model_not_found")>

I think the ideal scenario would be redefining the function as ask_chatgpt <- function(question, openai_parameters = list()) {. Would love if you could contribute with that PR 🙌 thanks!