mlverse / chattr

https://mlverse.github.io/chattr/
Other
185 stars 19 forks source link

Error when running as a background job #87

Closed jameson-c closed 4 months ago

jameson-c commented 5 months ago

When I run the following command chattr::chattr_app(as_job=TRUE) I without fail get the following error when I submit a query. The same error does not occur when I am running it in the foreground. I am running it out of Windows, using RStudio 2023.09.1 with R version 4.3.3. The chat feature responds with a reply, and sometimes even goes as far as allowing the 'copy code' function but it then shuts down with the following:



Listening on http://127.0.0.1:7788
Warning: Error in map: ℹ In index: 2.
Caused by error in `split_ch[2:(length(split_ch) - 1)]`:
! only 0's may be mixed with negative subscripts
  64: <Anonymous>
  63: signalCondition
  62: signal_abort
  61: rlang::abort
  60: cli::cli_abort
  59: h
  58: .handleSimpleError
  57: prep_entry
  56: .f
  52: map_
  51: map
  50: walk
  49: app_add_assistant
  48: observe
  47: <observer>
   4: shiny::runApp
   3: eval
   2: eval
   1: .rs.sourceWithProgress```
edgararuiz commented 5 months ago

Hi @jameson-c , what model are you interacting with?

jameson-c commented 5 months ago

I am doing chattr_use('copilot')

edgararuiz commented 5 months ago

Ok, I was able to recreate the error, but not the exact circumstances. Would you mind testing it from this branch?:

remotes::install_github("mlverse/chattr", ref = "updates")
jameson-c commented 5 months ago

Now when I submit a query from that branch I get:

<callr_error/rlib_error_3_0/rlib_error/error>
Error: 
! in callr subprocess.
Caused by error in `UseMethod("ch_submit")`:
! no applicable method for 'ch_submit' applied to an object of class "c('ch_', 'ch_model')"
---
Subprocess backtrace:
1. chattr::ch_submit(defaults = defaults, prompt = prompt, stream = stream, …
2. base::.handleSimpleError(function (e) …
3. global h(simpleError(msg, call))
Warning: Error in observe: Streaming returned error
  52: <Anonymous>
  51: signalCondition
  50: signal_abort
  49: abort
  48: observe
  47: <observer>
   4: shiny::runApp
   3: eval
   2: eval
   1: .rs.sourceWithProgress
edgararuiz commented 5 months ago

Hey, thanks for you patience. I was able to recreate, and just committed a change that addresses the new error, please reinstall and try again:

remotes::install_github("mlverse/chattr", ref = "updates")
jameson-c commented 5 months ago

Hi Edgar, sorry for the delay! Now I am getting the following error before the shiny app even launches.

Error: '\U' used without hex digits in character string (C:/Users/username/AppData/Local/Temp/RtmpiiD6ja/file73ec18e27a2:1:29)
Execution halted

From the following, after removing chattr from my packages:

> remotes::install_github("mlverse/chattr", ref = "updates")
Using GitHub PAT from the git credential store.
Downloading GitHub repo mlverse/chattr@updates
── R CMD build ────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
✔  checking for file 'C:\Users\username\AppData\Local\Temp\RtmpiiD6ja\remotes73ec5168353a\mlverse-chattr-1b43940/DESCRIPTION' (563ms)
─  preparing 'chattr':
✔  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
     NB: this package now depends on R (>= 3.5.0)
     WARNING: Added dependency on R >= 3.5.0 because serialized objects in
     serialize/load version 3 cannot be read in older versions of R.
     File(s) containing such objects:
       'chattr/inst/tests/rstudio-console.rds'
       'chattr/inst/tests/rstudio-quarto.rds'
       'chattr/inst/tests/rstudio-script.rds'
       'chattr/tests/testthat/data/gpt35-error.rds'
       'chattr/tests/testthat/data/gpt35-stream.rds'
─  building 'chattr_0.0.0.9012.tar.gz'

* installing *source* package 'chattr' ...
** using staged installation
** R
** inst
** byte-compile and prepare package for lazy loading
** help
*** installing help indices
*** copying figures
** building package indices
** installing vignettes
** 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 (chattr)
> library(chattr)
> chattr_use('copilot')

── chattr 
• Provider: OpenAI - GitHub Copilot Chat
• Path/URL: https://api.githubcopilot.com/chat/completions
• Model:
• Label: Copilot (GitHub)
> chattr::chattr_app(as_job=TRUE)
• Provider: OpenAI - GitHub Copilot Chat
• Path/URL: https://api.githubcopilot.com/chat/completions
• Model:
• Label: Copilot (GitHub)
[1] "Sys.setenv(CHATTR_USE = 'C:\\Users\\USERNAME~1\\AppData\\Local\\Temp\\RtmpiiD6ja\\file73ec78fae5d')"
[2] "print(chattr::chattr_defaults())"                                                                 
[3] "app <- chattr:::app_interactive(as_job = TRUE)"                                                   
[4] "rp <- list(ui = app$ui, server = app$server)"                                                     
[5] "shiny::runApp(rp, host = '127.0.0.1', port = 7788)"                                               
> chattr_app(as_job=TRUE)
• Provider: OpenAI - GitHub Copilot Chat
• Path/URL: https://api.githubcopilot.com/chat/completions
• Model:
• Label: Copilot (GitHub)
[1] "Sys.setenv(CHATTR_USE = 'C:\\Users\\USERNAME~1\\AppData\\Local\\Temp\\RtmpiiD6ja\\file73ec1e9d7ab6')"
[2] "print(chattr::chattr_defaults())"                                                                  
[3] "app <- chattr:::app_interactive(as_job = TRUE)"                                                    
[4] "rp <- list(ui = app$ui, server = app$server)"                                                      
[5] "shiny::runApp(rp, host = '127.0.0.1', port = 7788)" 
edgararuiz commented 5 months ago

Hey, thanks, I wasn't able to recreate, more likely because I'm not using Windows. But I think a modification I just made should work:

remotes::install_github("mlverse/chattr", ref = "updates")
jameson-c commented 4 months ago

Hi Edgar, thanks for making that fix!

chattr_app(as_job=TRUE) now works but doesn't automatically open a tab in Chrome- you have to go to the viewer pane and press 'Show in a new window'

So it does work but it's a bit counterintuitive for a user.