MichelNivard / gptstudio

GPT RStudio addins that enable GPT assisted coding, writing & analysis
https://michelnivard.github.io/gptstudio/
Other
906 stars 109 forks source link

[Bug]: Calls to `gptstudio_chat_in_source()` attempt to evaluate R code #203

Closed calderonsamuel closed 6 months ago

calderonsamuel commented 6 months ago

Confirm setup

What happened?

While trying the "Comment your code" addin in the following selected text:

plot_filtered <- function(min_mpg) {
  mtcars |> 
    filter(mpg >= min_mpg) |> 
    ggplot(aes(cyl)) +
    geom_()
}

I got the error:

Error in `lapply(text, glue_cmd, .envir = .envir)`:
! Could not evaluate cli `{}` expression: ` mtcars |> f…`.
Caused by error in `ggplot(filter(mtcars, mpg >= min_mpg), aes(cyl))`:
! could not find function "ggplot"
Type .Last.error to see the more details.

I think this might be related of the use of {glue} in the following line in "R/service-openai_gpt_queries.R":

instructions <- glue::glue("{task}: {selection$value}")

Looks like glue() is evaluating "{selection$value}". This might me related to the second problem present in #199

Relevant log output

No response

Session info

gptstudio::gptstudio_sitrep()
#> 
#> ── Configuration for gptstudio ─────────────────────────────────────────────────
#> Using user configuration file at
#> 'C:\Users\samue\AppData\Roaming/R/config/R/gptstudio/config.yml'
#> 
#> 
#> ── Current Settings ──
#> 
#> 
#> 
#> - Model: gpt-4
#> 
#> - Task: coding
#> 
#> - Language: en
#> 
#> - Service: openai
#> 
#> - Custom prompt:
#> 
#> - Stream: TRUE
#> 
#> - Code style: tidyverse
#> 
#> - Skill: beginner
#> 
#> 
#> 
#> ── Checking API connections ──
#> 
#> 
#> 
#> ── Checking OpenAI API connection 
#> 
#> ✔ Successfully connected to the OpenAI API service.
#> 
#> 
#> 
#> ── Checking HuggingFace API connection 
#> 
#> ✖ API key is not set or invalid for HuggingFace service.
#> 
#> 
#> 
#> ── Checking Anthropic API connection 
#> 
#> ✖ API key is not set or invalid for Anthropic service.
#> 
#> 
#> 
#> ── Checking Google AI Studio API connection 
#> 
#> ✖ API key is not set or invalid for Google AI Studio service.
#> 
#> 
#> 
#> ── Checking Azure OpenAI API connection 
#> 
#> ✖ API key is not set or invalid for Azure OpenAI service.
#> 
#> 
#> 
#> ── Checking Perplexity API connection 
#> 
#> ✖ API key is not set or invalid for Perplexity service.
#> 
#> 
#> 
#> ── Checking Cohere API connection 
#> 
#> ✖ API key is not set or invalid for Cohere service.
#> 
#> 
#> 
#> ── Check Ollama for Local API connection 
#> 
#> ✖ Couldn't connect to Ollama in <http://localhost:11434>. Is it running there?
#> 
#> 
#> 
#> ── Getting help ──
#> 
#> 
#> 
#> See the gptstudio homepage (<https://michelnivard.github.io/gptstudio/>) for
#> getting started guides and package documentation. File an issue or contribute
#> to the package at the GitHub repo
#> (<https://github.com/MichelNivard/gptstudio>).
#> ── End of gptstudio configuration ──────────────────────────────────────────────

sessioninfo::session_info()
#> ─ Session info ───────────────────────────────────────────────────────────────
#>  setting  value
#>  version  R version 4.3.3 (2024-02-29 ucrt)
#>  os       Windows 11 x64 (build 22631)
#>  system   x86_64, mingw32
#>  ui       RTerm
#>  language (EN)
#>  collate  English_United States.utf8
#>  ctype    English_United States.utf8
#>  tz       America/Lima
#>  date     2024-05-09
#>  pandoc   3.1.11 @ C:/Program Files/RStudio/resources/app/bin/quarto/bin/tools/ (via rmarkdown)
#> 
#> ─ Packages ───────────────────────────────────────────────────────────────────
#>  package     * version    date (UTC) lib source
#>  assertthat    0.2.1      2019-03-21 [1] RSPM
#>  cli           3.6.2      2023-12-11 [1] RSPM
#>  curl          5.2.1      2024-03-01 [1] RSPM
#>  digest        0.6.35     2024-03-11 [1] RSPM
#>  ellipsis      0.3.2      2021-04-29 [1] RSPM
#>  evaluate      0.23       2023-11-01 [1] RSPM
#>  fansi         1.0.6      2023-12-08 [1] RSPM
#>  fastmap       1.1.1      2023-02-24 [1] RSPM
#>  fs            1.6.3      2023-07-20 [1] RSPM
#>  glue          1.7.0      2024-01-09 [1] RSPM
#>  gptstudio     0.3.1.9009 2024-05-09 [1] Github (MichelNivard/gptstudio@55dea07)
#>  htmltools     0.5.7      2023-11-03 [1] RSPM
#>  htmlwidgets   1.6.4      2023-12-06 [1] RSPM
#>  httpuv        1.6.14     2024-01-26 [1] RSPM
#>  httr2         1.0.0      2023-11-14 [1] RSPM
#>  jsonlite      1.8.8      2023-12-04 [1] RSPM
#>  knitr         1.45       2023-10-30 [1] RSPM
#>  later         1.3.2      2023-12-06 [1] RSPM
#>  lifecycle     1.0.4      2023-11-07 [1] RSPM
#>  magrittr      2.0.3      2022-03-30 [1] RSPM
#>  mime          0.12       2021-09-28 [1] RSPM
#>  pillar        1.9.0      2023-03-22 [1] RSPM
#>  promises      1.2.1      2023-08-10 [1] RSPM
#>  purrr         1.0.2      2023-08-10 [1] RSPM
#>  R.cache       0.16.0     2022-07-21 [1] RSPM
#>  R.methodsS3   1.8.2      2022-06-13 [1] RSPM
#>  R.oo          1.26.0     2024-01-24 [1] RSPM
#>  R.utils       2.12.3     2023-11-18 [1] RSPM
#>  R6            2.5.1      2021-08-19 [1] RSPM
#>  rappdirs      0.3.3      2021-01-31 [1] RSPM
#>  Rcpp          1.0.12     2024-01-09 [1] RSPM
#>  reprex        2.1.0      2024-01-11 [1] RSPM
#>  rlang         1.1.3      2024-01-10 [1] RSPM
#>  rmarkdown     2.26       2024-03-05 [1] RSPM
#>  rstudioapi    0.15.0     2023-07-07 [1] RSPM
#>  sessioninfo   1.2.2      2021-12-06 [1] RSPM
#>  shiny         1.8.0      2023-11-17 [1] RSPM
#>  styler        1.10.3     2024-04-07 [1] RSPM
#>  utf8          1.2.4      2023-10-22 [1] RSPM
#>  vctrs         0.6.5      2023-12-01 [1] RSPM
#>  withr         3.0.0      2024-01-16 [1] RSPM
#>  xfun          0.42       2024-02-08 [1] RSPM
#>  xtable        1.8-4      2019-04-21 [1] RSPM
#>  yaml          2.3.8      2023-12-11 [1] RSPM
#> 
#>  [1] C:/Users/samue/AppData/Local/R/win-library/4.3
#>  [2] C:/Program Files/R/R-4.3.3/library
#> 
#> ──────────────────────────────────────────────────────────────────────────────

Code of Conduct