michelnivard / gptstudio Goto Github PK
View Code? Open in Web Editor NEWGPT RStudio addins that enable GPT assisted coding, writing & analysis
Home Page: https://michelnivard.github.io/gptstudio/
License: Other
GPT RStudio addins that enable GPT assisted coding, writing & analysis
Home Page: https://michelnivard.github.io/gptstudio/
License: Other
Suggested change(s) to privacy description, Ill prob implement these for studio later today:
from: "These functions work by taking the text or code you have highlighted/selected with the cursor and send these to OpenAI as part of a prompt, they fall under their privacy notice/rules/exceptions you agreed to with OpenAI when making an account. I do not know how secure these are when sent to OpenAI, I also don’t know what OpenAI does with them. The code is designed to ONLY share the highlighted/selected text and no other elements of your R environment (i.e. data) unless you have highlighted it when running the addin. This may limit usability for now, but I do not want people to accidentally share sensitive data with OpenAI."
To: "These functions work by taking the text or code you have highlighted/selected with the cursor, or your prompt if you use one of the built-in apps, and send these to OpenAI as part of a prompt; they fall under their privacy notice/rules/exceptions you agreed to with OpenAI when making an account. We can't tell you or guarantee how secure these prompts are when sent to OpenAI. We don’t know what OpenAI does with your prompts, but OpenAI is clear that they use prompts and results to improve their model (see: their terms of use) unless you opt-out explicitly by contacting them. The code is designed to ONLY share the highlighted/selected text, or a prompt you build with the help of one of our apps and no other elements of your R environment. Make sure you are aware of what you send to OpenAI and do not accidentally share sensitive data with OpenAI."
Tools that support only English can be intimidating for non-native English speakers. I've encountered numerous students who gave up on using R and RStudio because of this language barrier (I'm from Peru, where Spanish is predominantly spoken). While chat/completions
already understands multiple languages, it would be more helpful (and obvious) if the instructions were available in different languages.
The shiny.i18n
📦 provides infrastructure for internationalization.
Implementing this feature could also serve as a great starting point for collaborating with this repository, making it a suitable candidate for a good first issue
.
Hi, Thank you for making this package available.
I'm having an issue with the Write/code from prompt function. When I apply the comment below to the write/code function, it produces the following, partial code.
# Write R code to make a scatterplot with ggplot2 make the points blue
> library(ggplot2)
>
> ggplot(data = mtc
However, when I apply the "Comment your code" function, it seems to work fine.
> library(ggplot2) #load ggplot2 package
>
> ggplot(data = mtcars, aes(x = wt, y = mpg)) + #create a scatterplot of mpg vs wt
> geom_point(color = "blue") #make the points blue
>
> mean(mtcars$mpg) #calculate the mean of mpg
I attempted to apply the comments provided here to the Write/code function, but the function seems to be running into the same issue.
First attempt (direct copy/paste of comments above)
# create a scatterplot of mpg vs wt make the points blue
>
> plt.scatter(df['wt'], df['mp
Second attempt (specifying ggplot2)
# create a scatterplot using ggplot2 of mpg vs wt make the points blue
>
> ggplot(data = mtcars, aes(x =
Might this be a problem with my working environment? I've tried to search for an issue that might be causing this, but apologies if I'm missing something that should be obvious.
There is a list of different models available for the chat completions endpoint. Currently there is no "click and choose" way to do it inside the chat app.
Thanks for this package, it looks amazing. I am trying to test it but run into the following error.
After installing it, when I click on one of its functions (e.g., "Spelling and Grammar"), I receive an "R code execution error" which says:
Error: Function selectionGet not found in RStudio
Error: no more error handlers available (recursive errors?); invoking 'abort' restart
I believe the package was correctly installed.
My code was:
require(devtools)
install_github("MichelNivard/GPTstudio")
── R CMD build ────────────────────────────────────────────────────────────────────────
✔ checking for file ‘/private/var/folders/31/l2wz6r3n4mb_x0kk3fphh4940000gn/T/RtmplSidbA/remotesb4cd5c47a004/MichelNivard-GPTstudio-f4b4638/DESCRIPTION’ ...
─ preparing ‘GPTstudio’:
✔ checking DESCRIPTION meta-information
─ checking for LF line-endings in source and make files and shell scripts
─ checking for empty or unneeded directories
Omitted ‘LazyData’ from DESCRIPTION
─ building ‘GPTstudio_0.1.0.tar.gz’
* installing *source* package ‘GPTstudio’ ...
** using staged installation
** R
** inst
** byte-compile and prepare package for lazy loading
** help
*** installing help indices
** building package indices
** testing if installed package can be loaded from temporary location
** testing if installed package can be loaded from final location
** testing if installed package keeps a record of temporary installation path
* DONE (GPTstudio)
If you have any advice on how to resolve this error, I'd really appreciate it. Thanks so much again!
Time to get this thing on CRAN? With so much interest (350 ⭐️s!!!), seems like we need to get this thing onto CRAN for broader distribution. If you agree @MichelNivard, I'd like to do some upkeep prior to the submission.
Although the main use for the RStudio IDE (home of the addin) is programming in R, the chat app could be used for all kinds of tasks. Having the option to set custom system prompts would help with this.
Hello,
I'm trying to set the API Key, but I retrieved this error in R studio's console.
"API key not found or is not formatted correctly"
R studio is up to date, but I can't figure out.
Can you help me please?
Thanks
Mattia
Error: 'card' is not an exported object from 'namespace:bslib'
I saw this error after I choose gptstudio:::addin_chatgpt()
I saw on OpenAI's documentation that they recommend setting temperature
or top_p
but not both. Think we should remove top_p
from the add-ins? I already did it for {gpttools}
but thought I'd ask before doing it here.
Is there a way to change the default settings for gptstudio.code_style
and gptstudio.skill
? Thanks!
I am working on RStudio Workbench and was not able to lunch the addin with the following error:
> gptstudio:::addin_chatgpt()
Loading required package: shiny
Error: 'card' is not an exported object from 'namespace:bslib'
It looks to me like it's a communication problem with bslib. I have updated gptstudio, bslib and shiny, but the problem still remains.
Hi,
thank you very much for the package. So far, I could install it and tried to use it with a valid API key. The problem is that I get errors, which I think are connected to my specific RStudio configuration. I am using rstudio-server 1.3.959 with R version 4.0.0.
The problem is that I cannot install a newer version of R or rstudio-server because my linux server on which I am running my system is old and currently can't be updated.
Do you know of any way I can run your package on a bit older version like mine? Or maybe the versions aren't the issues and I am missing something else?
Thanks!
P.S. here are some of the errors I am getting:
GPT Chat: Error: Function documentPath not found in RStudio
Freeform editor: Error in withr::local_options(shiny.launch.browser = .rs.invokeShinyPaneViewer) :
unused argument (shiny.launch.browser = .rs.invokeShinyPaneViewer)
Spelling and Grammar: Error: Function selectionGet not found in RStudio
Comment your code: Error: Function selectionGet not found in RStudio
First release:
usethis::use_cran_comments()
Title:
and Description:
@return
and @examples
Authors@R:
includes a copyright holder (role 'cph')Prepare for release:
git pull
devtools::build_readme()
urlchecker::url_check()
devtools::check(remote = TRUE, manual = TRUE)
devtools::check_win_devel()
rhub::check_for_cran()
git push
Submit to CRAN:
usethis::use_version('minor')
devtools::submit_cran()
Wait for CRAN...
git push
usethis::use_github_release()
usethis::use_dev_version()
usethis::use_news_md()
git push
@JamesHWade new way of handling the API ingestion (great!) doesn't work for the model builder it seems and 2 I tried and failed to open a chat in quarto and now RStudio can't in any way open a new Quarto doc anymore (even in other projects) and gives an error that says "state is unrecoverable". So maybe we should move the chat to a dev branch? I think Aden brake is a good idea anyway as we won't have time to respond quickly to breaks once our full time jobs pick up steam... how about we move chat to a dev and keep the relatively stable pieces on main?
when I click the ChatGPT from Addins, it says
gptstudio:::addin_chatgpt()
Error: 'card' is not an exported object from 'namespace:bslib'
Following is my interaction. How can I fix it. Thanx
gptstudio:::chat_gpt_addin()
✔ API already validated in this session.
Error: 'card' is not an exported object from 'namespace:bslib'
I'll begin designing a custom css for the Q&A, which is feasible if we wrap it into a Shiny app I think.
At the end of the installation, the console is returning me :
ERROR: dependency 'openai' is not available for package 'aptstudio'
and In i.p(…) : installation of package '/tmp/RtmpMbf9UM/file4d275cf47c55/gptstudio_0.1.0.tar.qz' had non-zero exit status
My R version is 4.0.5
Thank you for your help
Users of the chat app can benefit from taking a look to older messages, just like they can do in the original ChatGPT. It would be nice to have an option to store the chat history.
An interesting project that has already implemeted this in JS is chatbot-ui. The chat app addin can benefit from using the same format to store the chat history.
Hello, thank you very much for providing this useful tool. Everything was normal when I used it according to your tutorial. Today when I used it, it prompted me that the connection timed out, but I can use it normally when I connect to the API in other software. [I don’t know if there is a problem with the tool itself or my network]
Here is my error message:
✔ API key found and matches the expected format.
Error in curl::curl_fetch_memory(url, handle = handle) :
Timeout was reached: [api.openai.com] Connection timeout after 10003 ms
thanks very much for this package Michel. Tried to install with the below error log. Maybe you have an idea how to fix it. Many thanks - Stephan
require(devtools)
install_github("MichelNivard/GPTstudio")
Downloading GitHub repo MichelNivard/GPTstudio@HEAD
✔ checking for file ‘/private/var/folders/fg/96hc1rp50bn9zl8xbdg15yp40000gn/T/RtmpHHm4N7/remotes675e6dfc4aad/MichelNivard-GPTstudio-f4b4638/DESCRIPTION’ ...
─ preparing ‘GPTstudio’:
✔ checking DESCRIPTION meta-information ...
─ checking for LF line-endings in source and make files and shell scripts
─ checking for empty or unneeded directories
Omitted ‘LazyData’ from DESCRIPTION
─ building ‘GPTstudio_0.1.0.tar.gz’
Error in parse(outFile) :
C:/Users/Administrator/AppData/Local/Temp/Rtmp6jo3Hc/R.INSTALL9784bfb21b8/gptstudio/R/openai_api_calls.R:206:6: unexpected'>'
205: )
206: ) |>
^
According to the manual, I have tried installing it many times, but both failed. maybe the compilation failed with the pipe character.
devtools::check()
.....
ERROR: unable to collate and parse R files for package 'gptstudio'
....
Exited with status 1.
This works in terms of OpenAi playing ball, we just need to figure out whether we can get the document context out of the rstudioapi and on click present the entire doc and, when it is returned, restore the convo, or only add the new text, and the Q: prompt to the bottom of the doc...
Thanks for this library, looks very interesting.
I installed the library but "Start GPT Chat" is not there under "Addins", all other functions are there....am i missing something?
Error in curl::curl_fetch_memory(url, handle = handle) :
Timeout was reached: [api.openai.com] Failed to connect to api.openai.com port 443 after 5221 ms: Timed out
Brief description of the problem
Rstudio show it when i click chatgpt
This is because the request waits for the whole response. The chat completion endpoint has an stream
parameter that can allow to get deltas of the response, which also gives the typewriting effect for new messages.
The httr package (the current backbone of the requests) has a write_stream()
function that maybe can be used for this. However, the httr2 package also has req_stream()
function that looks very clean.
I found that gptstudio can only set the API key, and we can only go to OpenAI to search for this key. Can we add a function to set the URL
1st bug I didnt notice, because I rarely use it, but the API ingestino menu fails for me, do we really need it? setting an environmental variable isn't such a major hassle right?
Screenshot of it failing:
2nd bug is it intentional that the chat screen opens in a popup and not the viewer pane? It default toa windowed view for me, perhaps thats a preference you had, maybe we could make it a variable (I could do that if you agree its valuable).
{usethis}
is needed only for asking to setup the api key but brings a lot of dependencies. Here you can see that it brings 13 dependencies that only 1 of the {gptstudio}
dependencies, usethis itself, imports.
library(tidyverse)
usethis_deps <- pak::pkg_deps("usethis", dependencies = "Imports") |>
select(package)
pkg_deps <- pak::pkg_deps("calderonsamuel/gptstudio", dependencies = "Imports") |>
select(orig_pkg = package, deps)
pkg_deps |>
unnest(deps) |>
filter(package != "R", type %in% c("Imports", "imports")) |>
count(package, sort = TRUE) |>
semi_join(usethis_deps) |>
filter(n == 1)
#> Joining with `by = join_by(package)`
#> # A tibble: 13 × 2
#> package n
#> <chr> <int>
#> 1 clipr 1
#> 2 credentials 1
#> 3 desc 1
#> 4 gert 1
#> 5 gh 1
#> 6 gitcreds 1
#> 7 httr2 1
#> 8 ini 1
#> 9 usethis 1
#> 10 vctrs 1
#> 11 whisker 1
#> 12 yaml 1
#> 13 zip 1
Created on 2023-04-23 with reprex v2.0.2
We could have the same logic as usethis::ui_yeah()
by some smart wrapping of base::readline()
and utils::menu()
(which is essentially what ui_yeah() does). But is it worth the effort? 🤔
@JamesHWade let me know what you think. If you agree, ill remove it tomorrow.
Sys.setenv(OPENAI_API_KEY = "<my_API>")
plot(cars)
then I block the text of plot(cars)
, then go to Addins > GPTStudio > Comment your code
The result as shown in the terminal is..
Asking GPT for help...
! OpenAI API request failed [404].Error message: The model: `code-davinci-edit-001` does not exist
$error
$error$message
[1] "The model: `code-davinci-edit-001` does not exist"
$error$type
[1] "invalid_request_error"
$error$param
NULL
$error$code
[1] "model_not_found"
Inserting text from GPT...
My computer configuration:
R 4.2.3
gptstudio 0.1.0
RStudio 2023.03.0 Build 386
MXLinux 19.4 KDE based from Debian 10
I installed the library without any issues. When I test the gptstudio:::openai_chat()
functionality, the answer I get through the API does not make sense. For example, reproducing the readme example gives me the following:
Question: what are your top 3 tips for learning R?
The answer to your question depends on the specific context in which it is asked. Without more information, it is difficult to provide an accurate answer.
I can reproduce the behaviour with other questions:
Question: who's the current Canadian prime minister?
There is no single answer to this question as it depends on the specific context and situation. Generally speaking, the best way to handle a difficult situation is to remain calm, listen to all parties involved, and find a solution that is acceptable to everyone. It is also important to be respectful and open-minded when discussing the issue. Additionally, it is important to consider the long-term consequences of any decision that is made.
Am I missing something?
R version 4.2.1 (2022-06-23 ucrt)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19044)
gptstudio_0.1.2
Hello~
Whenever I excute create_gpt_chat() function I see an error message as such:
gptstudio:::create_gpt_chat()
Error inEncoding<-
(*tmp*
, value = "UTF-8") :
a character vector argument expected
Could you please let me know how I can resolve this issue? Thanks!
Best,
Hwanggyu
I am experiencing the following problem:
" v API already validated in this session.
v API key is valid.
i Setting OPENAI_API_KEY environment variable.
i You can set this variable in your .Renviron file.
Error: 'card' is not an exported object from 'namespace:bslib' "
The API key is currently validated:
" > gptstudio:::addin_chatgpt()
v API already validated in this session. "
Also I can't see the "Start GPT Chat" in the addins menu:
Any suggestion?
@JamesHWade I think we should switch over asap? See for description: https://openai.com/blog/introducing-chatgpt-and-whisper-apis
The function in chat_gpt.R
are tedious to test since they depend on {rstudioapi}
. Nonetheless, we need some unit tests for this code since it is likely to be a popular feature of the package.
I confirmed that the GPT-3 released in 2020 is used. Is there any way to connect to GPT-3.5-turbo?
When I select the ChatGPT addin, it launches the shiny app in my main session. I'm not certain how to do this, but it would be preferable if the shiny app could run in the "Background Jobs" tab of RStudio.
Testing out Bard has made me even more interested in the GPT models (I thought sure Google would be at least close if not ahead, but they clearly aren't), so I expect to have more requests and hopefully PRs coming soon for you!
@JamesHWade, I was thinking could we re-use your "datasummary" input from gpttools and prompt davinci-003 with both:
"the summary"
the users specific analysis question about their own data (example "Can you regress BMI on age, sex, exercise and use a mixed model with a random intercept for zipcode use lme4")
I think this would likely lead to a higher likelihood gpt gets the variable names etc right?
Use whisper to incorporate voice commands.
h/t @jwijffels
See: https://twitter.com/jwijffels1/status/1638650905636618241?s=20
@JamesHWade These are some ideas for ways we can go forward with this project, prompted by your new addin.
so it occurred to me the list of potential addins could quickly escalate (in a good way). One way to go about managing this is a coordinated split:
gptstudio general set of addins for coding/writing in Rstudio. Spelling, generate text/code from prompt, comment code, etc.
gpttools addins meant to help package/function development in r. The exciting part hee is that it would be relatively easy (I think) to tune OpenAI models to specific task like writing a manual page, making a script into a function. For me it would be exciting to see if I could tune model for this.
gptmodels this is still a vague notion but a set of addins to help people 1. Suggest models to analyze data 2. Explain existing models to them 3. List assumptions of highlighted models etc… this has huge “helping people get in way over their heads” potential…
all three could share a common free form editor, basics usage, but allow for user opt-in for bunched of 3-6 addins to avoid addin menu clutter. Maybe downstream this structure also allows for easy experimenting with custom tuned versions of the GPT models these use. Reason I opens this for discussion is that this split would require you to take the lead on some of this, because how would I know what addins work well for developers right?
When I try to use the package I get the following error. Do you need a paid version?
OpenAI API request failed [429].Error message: You exceeded your current quota, please check your plan and billing details. Warning: Error in purrr::map: ℹ In index: 3. Caused by error in
if (.x$role == "system") ...: ! argument is of length zero 95: <Anonymous> 94: signalCondition 93: signal_abort 92: rlang::abort 91: cli::cli_abort 90: h 89: .handleSimpleError 82: vctrs_vec_compat 81: map_ 80: where_if 79: discard 78: purrr::compact 76: make_chat_history 75: :: shiny observe [/Library/Frameworks/R.framework/Versions/4.1-arm64/Resources/library/gptstudio/shiny/app.R#82] 74: <observer> 3: runApp 2: print.shiny.appobj 1: <Anonymous>
Hi Michel,
Great package - I was planning to start using gptstudio but openai does not seem to be available for R version 3.6.3. Here is the output when I try installing the package:
ERROR: dependency ‘openai’ is not available for package ‘gptstudio’
* removing ‘/Library/Frameworks/R.framework/Versions/3.6/Resources/library/gptstudio’
Warning messages:
1: package ‘openai’ is not available (for R version 3.6.3)
2: In i.p(...) :
installation of package ‘/var/folders/n7/k_dfmxgn3k79tvpfzffhhpqw0000gn/T//Rtmp47QzCe/filef90b37cad5dc/gptstudio_0.1.0.tar.gz’ had non-zero exit status
Any plans to release version compatible with R 3.6.3?
There seems to be an issue in open_bg_shinyapp()
. The translated URL sometimes works fine and sometimes opens an external browser with an unexpected URL that leads nowhere. This was tried multiple times in different blank posit cloud projects.
I successfully downloaded everything and set up the API key. However, when I used the Chat in Source function, no codes appeared either on my R script or Console. I wonder what is the problem with my gptstudio or R studio?
The chat window shows a welcome message that ends up in the api call. This consumes unnecessary tokens per request and will slowly
I've added the package but the 'write/code from prompt' option is nowhere to be found. How do I fix it?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.