Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: Unable to use Ollama models: Error in validate_skeleton: api_key is not a valid character scalar. It is a <character>. #230

Closed
3 tasks done
indykpol opened this issue Oct 14, 2024 · 5 comments · Fixed by #233
Labels
bug an unexpected problem or unintended behavior

Comments

@indykpol
Copy link

Confirm setup

  • I have installed the development version of {gptstudio} (pak::pak("MichelNivard/gptstudio")) and tested if the problem remains.
  • I have installed the {reprex} and {sessioninfo} packages to be able to run this issue's code snippet pak::pak(c("reprex", "sessioninfo")).

What happened?

This issue looks a bit different on the Github dev version from the CRAN version.

image

When I try to use chat with local Ollama host I get the following upon sending anything to the chat (after configuring the app to use local Ollama and selecting one of the available models):
Error in validate_skeleton: api_key is not a valid character scalar. It is a .
4: shiny::runApp
3: eval
2: eval
1: .rs.sourceWithProgress

I believe it pertains to the fact that:

  1. new_gpstudio_request_skeleton has a validate_skeleton(url, api_key, model, prompt, history, stream) call
  2. new_gptstudio_request_skeleton_ollama instantiates with api_key = "JUST A PLACEHOLDER"
  3. It results wrong validation, despite a fact that vanilla Ollama doesn't use API keys at all

Relevant log output

Ładowanie wymaganego pakietu: shiny
Ostrzeżenie: pakiet 'shiny' został zbudowany w wersji R 4.4.1

Listening on http://127.0.0.1:6232
ℹ Fetching models for openai service...
✖ HTTP 401 Unauthorized.
• OAuth error
• realm: OpenAI API
✖ No models available
ℹ Fetching models for ollama service...
✔ Got models!
Ostrzeżenie: Error in validate_skeleton: `api_key` is not a valid character scalar. It is a <character>.
  4: shiny::runApp
  3: eval
  2: eval
  1: .rs.sourceWithProgress

Session info

r
gptstudio::gptstudio_sitrep()
#> 
#> ── Configuration for gptstudio ─────────────────────────────────────────────────
#> No user configuration file found at
#> 'C:\Users\m.switnicki\AppData\Roaming/R/config/R/gptstudio/config.yml'. Using
#> default configuration. Change configuration settings in the chat app. Lauch the
#> chat app with addins or `gptstudio_chat()`.
#> 
#> ── Current Settings ──
#> 
#> - Model: gpt-4o
#> - Task: coding
#> - Language: en
#> - Service: openai
#> - Custom prompt:
#> - Stream: TRUE
#> - Code style: no preference
#> - Skill: beginner
#> 
#> ── Checking API connections ──
#> 
#> ── Checking OpenAI API connection
#> ✖ API key is not set or invalid for OpenAI 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
#> ✔ Ollama is running
#> 
#> ── 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 ──────────────────────────────────────────────

Created on 2024-10-14 with reprex v2.1.1

Session info
sessioninfo::session_info()
#> ─ Session info ───────────────────────────────────────────────────────────────
#>  setting  value
#>  version  R version 4.4.0 (2024-04-24 ucrt)
#>  os       Windows 10 x64 (build 19045)
#>  system   x86_64, mingw32
#>  ui       RTerm
#>  language (EN)
#>  collate  Polish_Poland.utf8
#>  ctype    Polish_Poland.utf8
#>  tz       Europe/Warsaw
#>  date     2024-10-14
#>  pandoc   3.1.11 @ C:/Program Files/RStudio/resources/app/bin/quarto/bin/tools/ (via rmarkdown)
#> 
#> ─ Packages ───────────────────────────────────────────────────────────────────
#>  package     * version    date (UTC) lib source
#>  cli           3.6.2      2023-12-11 [1] CRAN (R 4.4.0)
#>  curl          5.2.3      2024-09-20 [1] CRAN (R 4.4.1)
#>  digest        0.6.35     2024-03-11 [1] CRAN (R 4.4.0)
#>  evaluate      0.23       2023-11-01 [1] CRAN (R 4.4.0)
#>  fastmap       1.2.0      2024-05-15 [1] CRAN (R 4.4.1)
#>  fs            1.6.4      2024-04-25 [1] CRAN (R 4.4.0)
#>  glue          1.7.0      2024-01-09 [1] CRAN (R 4.4.0)
#>  gptstudio     0.4.0.9007 2024-10-14 [1] Github (MichelNivard/gptstudio@dfc8b43)
#>  htmltools     0.5.8.1    2024-04-04 [1] CRAN (R 4.4.0)
#>  htmlwidgets   1.6.4      2023-12-06 [1] CRAN (R 4.4.1)
#>  httpuv        1.6.15     2024-03-26 [1] CRAN (R 4.4.1)
#>  httr2         1.0.5      2024-09-26 [1] CRAN (R 4.4.1)
#>  jsonlite      1.8.8      2023-12-04 [1] CRAN (R 4.4.0)
#>  knitr         1.46       2024-04-06 [1] CRAN (R 4.4.0)
#>  later         1.3.2      2023-12-06 [1] CRAN (R 4.4.1)
#>  lifecycle     1.0.4      2023-11-07 [1] CRAN (R 4.4.0)
#>  magrittr      2.0.3      2022-03-30 [1] CRAN (R 4.4.0)
#>  mime          0.12       2021-09-28 [1] CRAN (R 4.4.0)
#>  promises      1.3.0      2024-04-05 [1] CRAN (R 4.4.1)
#>  R6            2.5.1      2021-08-19 [1] CRAN (R 4.4.0)
#>  rappdirs      0.3.3      2021-01-31 [1] CRAN (R 4.4.0)
#>  Rcpp          1.0.12     2024-01-09 [1] CRAN (R 4.4.0)
#>  reprex        2.1.1      2024-07-06 [1] CRAN (R 4.4.1)
#>  rlang         1.1.3      2024-01-10 [1] CRAN (R 4.4.0)
#>  rmarkdown     2.28       2024-08-17 [1] CRAN (R 4.4.1)
#>  rstudioapi    0.16.0     2024-03-24 [1] CRAN (R 4.4.0)
#>  sessioninfo   1.2.2      2021-12-06 [1] CRAN (R 4.4.1)
#>  shiny         1.9.1      2024-08-01 [1] CRAN (R 4.4.1)
#>  withr         3.0.0      2024-01-16 [1] CRAN (R 4.4.0)
#>  xfun          0.43       2024-03-25 [1] CRAN (R 4.4.0)
#>  xtable        1.8-4      2019-04-21 [1] CRAN (R 4.4.1)
#>  yaml          2.3.8      2023-12-11 [1] CRAN (R 4.4.0)
#> 
#>  [1] C:/Users/m.switnicki/AppData/Local/Programs/R/R-4.4.0/library
#> 
#> ──────────────────────────────────────────────────────────────────────────────
```

Code of Conduct

  • I agree to follow this project's Code of Conduct
@indykpol indykpol added the bug an unexpected problem or unintended behavior label Oct 14, 2024
@calderonsamuel
Copy link
Collaborator

Thank you for the report. We'll take a look

@calderonsamuel
Copy link
Collaborator

calderonsamuel commented Oct 31, 2024

@indykpol I was able to reproduce this problem. You needed to save your settings after changing your API service or model. This is why OpenAI was being used still after selecting Ollama. This wasn't obvious, so I've added some info tooltips to be extra safe

@indykpol
Copy link
Author

Thanks - I can confirm it solved the problem. It really needs saving before it is usable.

@indykpol
Copy link
Author

indykpol commented Oct 31, 2024

Another related question. Let's suppose I have Ollama running at certain IP and I configured the Chat interface to use now. Now when I want to use "Chat in source" or the comment code functionality I encounter a strange behaviour. It tries to use local instance of Ollama out of the box, without giving me an opportunity to configure:

Error in req_perform():...
! Failed to perform HTTP request.
Caused by error in curl::curl_fetch_memory():
! Failed to connect to localhost port 11434 after 2235 ms: Couldn't connect to server
Run rlang::last_trace() to see where the error occurred.
✖ Sending query to ollama... [2.4s]

image

I actually got it to work, saving the config in the Chat as the default, and then restarting everything in a new project. I think some variables don't get updated properly during the runtime.

@calderonsamuel
Copy link
Collaborator

I think that is the expected behavior. The gptstudio chat runs in a different R process than the one Rstudio uses, this is why it doesn't block your R console. This is also why we have "Save for this session" (current R process running gptstudio) and "Save as default" (saves in disk + updates current process).

However, Rstudio's R process is already loaded with whatever options / ENV variables it found at startup, so your changes in the gptstudio configuration will not affect it until you restart your R session.

Let me know if you were referring to something different.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug an unexpected problem or unintended behavior
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants