Closed gusl closed 10 months ago
Could you try reinstalling the package? I do think this was a bug in a previous iteration that has since been addressed. If that doesn't work, can you make sure to clear all objects from your workspace and try again? If those don't work, we can keep digging in. I can't reproduce the error, but I have seen it before, which makes me think it was a previous bug.
Sam
Original install was yesterday, but I forced a fresh install just now. This did not fix the error.
After clearing the workspace with rm(list = ls())
, I get:
Okay, I'm ready to assist you with R coding. What do you need help with? Error: unexpected ',' in "Okay,"
And then the original error again.
I'm pretty sure there's some confusion re: the input that gets sent to GPT.
Do I write the input (comment or incomplete code) at the end of .R file? Does it matter where my cursor is at, or what I'm highlighting?
Ah, perfect. Sounds like it's working albeit in a non-ideal way sometimes. The way it currently works is that anything written in the console (not a .R file) is submitted to the API with this prompt prepended, "You are an R coding assistant. For the rest of this conversation, return R code only. Do not include anything else such as extra characters or comments. DO NOT install any packages but assume I already have them installed." This way ideally it returns runnable code and it can autoexecute the code. This means you want to have it return runnable code or a comment.
The conversation is lazily stored in a global variable called openai_completions. This is added to each time you call the add-in so that the model knows the full context of the entire conversation you've been having. I am definitely planning on making that more invisible and user friendly, but for the time being, deleting the global variables openai_completions and openai_completions_usage will reset the conversation. Again, this is really experimental so I'm sorry for the clunkiness.
Feel free to try out the two other addins as well which recognize your voice. I'd be happy to get feedback there too as local testing has worked great for me, but sometimes it's different on different operating systems and machines.
Thanks!
So I wrote a comment in the shell:
pressed Enter
... hoping that it would create the function for me.
But instead I get:
Error in (function (prompt = rstudioapi::getConsoleEditorContext()$contents, :
list(message = "[3985, 3996.25] is not of type 'integer' - 'max_tokens'", type = "invalid_request_error", param = NULL, code = NULL)
What am I doing wrong?
–G
On Sun, Apr 9, 2023, 1:18 PM Sam Terfa @.***> wrote:
Ah, perfect. Sounds like it's working albeit in a non-ideal way sometimes. The way it currently works is that anything written in the console (not a .R file) is submitted to the API with this prompt prepended, "You are an R coding assistant. For the rest of this conversation, return R code only. Do not include anything else such as extra characters or comments. DO NOT install any packages but assume I already have them installed." This way ideally it returns runnable code and it can autoexecute the code. This means you want to have it return runnable code or a comment.
The conversation is lazily stored in a global variable called openai_completions. This is added to each time you call the add-in so that the model knows the full context of the entire conversation you've been having. I am definitely planning on making that more invisible and user friendly, but for the time being, deleting the global variables openai_completions and openai_completions_usage will reset the conversation. Again, this is really experimental so I'm sorry for the clunkiness.
Feel free to try out the two other addins as well which recognize your voice. I'd be happy to get feedback there too as local testing has worked great for me, but sometimes it's different on different operating systems and machines.
— Reply to this email directly, view it on GitHub https://github.com/samterfa/openai/issues/6#issuecomment-1501174245, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAA7K7FJJ2GMCO2Z7B4EIX3XALVO5ANCNFSM6AAAAAAWXR3PIA . You are receiving this because you authored the thread.Message ID: @.***>
This is so bizarre. The error message sounds like that old bug I had and fixed, so I'm confused as to why it still seems like it's there. I ran your same request using the latest version, and got something reasonable.
add_numbers <- function(a, b) {
return(a + b)
}
Can you please run remotes::install_github('samterfa/openai', force = TRUE)
, restart your R session, and look at what package version number is listed next to openai under Packages? It should now be 0.0.1.
Thanks!
Reinstalled:
* DONE (openai)
Restarting R session...
> Sys.setenv(openai_organization_id = "org-[CENSORED]")
> Sys.setenv(openai_secret_key = "sk-[CENSORED]")
> # This function adds two numbers
(Click on add-in)
Error in (function (prompt = rstudioapi::getConsoleEditorContext()$contents, :
list(message = "[3985, 3996.25] is not of type 'integer' - 'max_tokens'", type = "invalid_request_error", param = NULL, code = NULL)
Would you please take a screenshot of the package version, like this one?
[image: Screenshot 2023-04-09 at 9.54.38 PM.png]
On Sun, Apr 9, 2023 at 9:52 PM Sam Terfa @.***> wrote:
Would you please take a screenshot of the package version, like this one? [image: image] https://user-images.githubusercontent.com/16829133/230809699-3d96be48-1b08-4531-879e-b7af12f67161.png
— Reply to this email directly, view it on GitHub https://github.com/samterfa/openai/issues/6#issuecomment-1501292790, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAA7K7FJDUHKO5R2XMCBXX3XANRXLANCNFSM6AAAAAAWXR3PIA . You are receiving this because you authored the thread.Message ID: @.***>
That didn't come through. Can you paste the screenshot right in the issue?
I'm sorry it's still not working for you! Can you confirm the name of the addin you're running and how you're getting it to run? Pressing Enter won't run the addin, unless you set that as the shortcut key, which is what your previous comment indicated you were doing. I'm very much scratching my head.
I enter the comment (GPT input) into the R terminal. Then I click "Addins", then "GPT Text Command Auto-Execute"
I did not change any shortcuts.
On Mon, Apr 10, 2023, 5:44 PM Sam Terfa @.***> wrote:
I'm sorry it's still not working for you! Can you confirm the name of the addin you're running and how you're getting it to run? Pressing Enter won't run the addin, unless you set that as the shortcut key, which is what your previous comment indicated you were doing. I'm very much scratching my head.
[image: image] https://user-images.githubusercontent.com/16829133/231004817-d8210909-c473-4cb9-a335-4de0b0fd4479.png
— Reply to this email directly, view it on GitHub https://github.com/samterfa/openai/issues/6#issuecomment-1502367977, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAA7K7HRN6A6HS5TMJI2723XAR5MHANCNFSM6AAAAAAWXR3PIA . You are receiving this because you authored the thread.Message ID: @.***>
Can you uninstall the package, then restart your R session, then quit RStudio, then start it up, and try again? I cannot reproduce the issue. I've tried a fresh install and there are no issues. If you have another error, can you copy and paste it again? Thanks for hanging in there!
Did all the above, and see some progress!
After I click the add-in, it enters English text into the R terminal.
Got it. Let's get started! Error: unexpected symbol in "Got it."
Oh sweet!
Can you try clearing your environment, and then your original one? # This function adds two numbers
?
# This function adds two numbers
(Click on addin)
OK, that's reasonable output. The addin forces the console to execute whatever is returned from the model. Since "Understood. How may I assist you today?" isn't valid R code, it returns that error. Try clearing the environment, and then enter something like: "# Write a function that adds two numbers." I'm considering changing the initial prompt I mentioned earlier to explicitly say, "Make sure that everything you return is code that can execute successfully in an R session.".
I've updated the autocomplete function so this should now work no matter if the model replies as it's supposed to or not. If you try this and it's not working for you, feel free to reopen.
I get the following error, both as a dialog and on the shell.
Error in (function (prompt = rstudioapi::getConsoleEditorContext()$contents, : list(message = "This model's maximum context length is 4097 tokens. However, you requested 4105 tokens (101 in the messages, 4004 in the completion). Please reduce the length of the messages or completion.", type = "invalid_request_error", param = "messages", code = "context_length_exceeded")