Giter Site home page Giter Site logo

michelnivard / gptstudio Goto Github PK

View Code? Open in Web Editor NEW
882.0 882.0 103.0 56.86 MB

GPT RStudio addins that enable GPT assisted coding, writing & analysis

Home Page: https://michelnivard.github.io/gptstudio/

License: Other

R 83.47% CSS 2.17% JavaScript 6.36% HTML 8.00%
chatgpt gpt-3 r rstats rstats-package rstudio rstudio-addin

gptstudio's Introduction

Hi there 👋

gptstudio's People

Contributors

calderonsamuel avatar idavydov avatar jameshwade avatar josefoviedo avatar m-colley avatar michelnivard avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

gptstudio's Issues

suggested change to privacy warning text

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."

FR: Add suport for internationalization

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.

Write/code from prompt -- producing incomplete code

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.

Error: Function selectionGet not found in RStudio

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!

CRAN Submission?

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.

  • Convert all model usage over to gpt-3.5-turbo
  • Reduce number of plugins
  • Tweak ChatGPT app based on initial user feedback
  • Reach minimum threshold for testing (80%?)
  • Update documentation (especially readme)

FR: Custom system prompts for the chat app

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.

"API key not found or is not formatted correctly" Error

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

Refactor to remove top_p?

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.

Error: 'card' is not an exported object from 'namespace:bslib'

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.

Doesnt work for my specific RStudio configuration

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

Release gptstudio 0.1.0

First release:

Prepare for release:

  • git pull
  • Check if any deprecation processes should be advanced, as described in Gradual deprecation
  • devtools::build_readme()
  • urlchecker::url_check()
  • devtools::check(remote = TRUE, manual = TRUE)
  • devtools::check_win_devel()
  • rhub::check_for_cran()
  • git push
  • Draft blog post

Submit to CRAN:

  • usethis::use_version('minor')
  • devtools::submit_cran()
  • Approve email

Wait for CRAN...

  • Accepted 🎉
  • git push
  • usethis::use_github_release()
  • usethis::use_dev_version()
  • usethis::use_news_md()
  • git push
  • Finish blog post
  • Tweet
  • Add link to blog post in pkgdown news menu

bugs and strategy?

@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?

Error in export(card)

when I click the ChatGPT from Addins, it says

gptstudio:::addin_chatgpt()
Error: 'card' is not an exported object from 'namespace:bslib'

No "Write/code from prompt" addin

Hi there
Great package - just installed gptstudio, have the addin working for e.g., spelling and commenting, but I don't have the "write/code from prompt" option.
Any suggestion on why this is?
Thanks!
image

Error for gptstudio in Rstudio

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'

Problem in the installation of the addin

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

FR: Import and export chat history

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.

Cannot connect to open ai

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

Installation error

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’

  • installing source package ‘GPTstudio’ ...
    ** using staged installation
    ** R
    ** inst
    ** byte-compile and prepare package for lazy loading
    Error in loadNamespace(i, c(lib.loc, .libPaths()), versionCheck = vI[[i]]) :
    there is no package called ‘openai’
    Calls: ... loadNamespace -> withRestarts -> withOneRestart -> doWithOneRestart
    Execution halted
    ERROR: lazy loading failed for package ‘GPTstudio’
  • removing ‘/Library/Frameworks/R.framework/Versions/4.1/Resources/library/GPTstudio’
    Warning message:
    In i.p(...) :
    installation of package ‘/var/folders/fg/96hc1rp50bn9zl8xbdg15yp40000gn/T//RtmpHHm4N7/file675e4e8adc44/GPTstudio_0.1.0.tar.gz’ had non-zero exit status

error with intall gptstudio

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.

Dialog in a quarto doc?

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...

Screen.Recording.2022-12-31.at.00.23.24.mov

Start GPT Chat Missing

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

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

Response in the chat app takes a very long time

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.

httr: https://httr.r-lib.org/reference/write_stream.html

httr2: https://httr2.r-lib.org/reference/req_stream.html

The API ingestion menu fails for me and the chat opens in a window not the viewer pane

@JamesHWade

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:

bug

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).

Remove usethis dependency maybe?

{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? 🤔

"The model: `code-davinci-edit-001` does not exist"

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

openai_chat() not producing expected behaviour

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

Error message with "create_gpt_chat()"

Hello~

Whenever I excute create_gpt_chat() function I see an error message as such:

gptstudio:::create_gpt_chat()
Error in Encoding<-(*tmp*, value = "UTF-8") :
a character vector argument expected

Could you please let me know how I can resolve this issue? Thanks!

Best,
Hwanggyu

Chat GPT not working, problem with bslib

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:

image

Any suggestion?

Add tests for GPT chat functions

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.

Run Shiny App in Background

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!

gptstudio "analysis" shiny pane?

@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?

Coordination

@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?

Request Failed

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 inif (.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>

openai for R version 3.6.3

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?

app doesn't work in posit cloud

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.

No codes generated on my R script

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?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.