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]: gptstudio::gptstudio_sitrep() states failing to connect to Anthropic API when it is actually connected #231

Closed bio-info-guy closed 2 weeks ago

bio-info-guy commented 1 month ago

Confirm setup

What happened?

When i run the command gptstudio::gptstudio_sitrep(), it states that I failed to connect to the Anthropic API service. However, I can confirm that I am using my own API for anthropic. Upon a closer look, I believe that the check_api_connection_anthropic function checks for connecitivity by calling for claude-2.1, which requires a request url of: "https://api.anthropic.com/v1/complete" and not ""https://api.anthropic.com/v1/messages".

Relevant log output

> req_headers(request("https://api.anthropic.com/v1/complete"), 
            `anthropic-version` = "2023-06-01", `content-type` = "application/json", 
            `x-api-key` = Sys.getenv("ANTHROPIC_API_KEY")) |>
         httr2::req_body_json(
                data = list(
                        prompt = "\n\nHuman: Hello, Claude\n\nAssistant:",
                        model = "claude-2.1",
                        max_tokens_to_sample = 1024
                 )
             ) |> httr2::req_error(is_error = function(resp) FALSE) |> req_perform()
#OUTPUT:
#<httr2_response>
#POST https://api.anthropic.com/v1/complete
#Status: 200 OK
#Content-Type: application/json
#Body: In memory (195 bytes)

> req_headers(request("https://api.anthropic.com/v1/messages"), 
            `anthropic-version` = "2023-06-01", `content-type` = "application/json", 
            `x-api-key` = Sys.getenv("ANTHROPIC_API_KEY")) |>
         httr2::req_body_json(
                data = list(
                        prompt = "\n\nHuman: Hello, Claude\n\nAssistant:",
                        model = "claude-2.1",
                        max_tokens_to_sample = 1024
                 )
             ) |> httr2::req_error(is_error = function(resp) FALSE) |> req_perform()
#OUTPUT:
#<httr2_response>
#POST https://api.anthropic.com/v1/messages
#Status: 400 Bad Request
#Content-Type: application/json
#Body: In memory (94 bytes)

Session info

gptstudio::gptstudio_sitrep()
#> 
#> ── Configuration for gptstudio ─────────────────────────────────────────────────
#> Using user configuration file at
#> '/Users/ysu13/Library/Preferences/org.R-project.R/R/gptstudio/config.yml'
#> 
#> 
#> ── Current Settings ──
#> 
#> 
#> 
#> - Model: claude-3-5-sonnet-20240620
#> 
#> - Task: coding
#> 
#> - Language: en
#> 
#> - Service: anthropic
#> 
#> - Custom prompt:
#> 
#> - Stream: TRUE
#> 
#> - Code style: tidyverse
#> 
#> - 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 
#> 
#> ✖ Failed to connect to the Anthropic API 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 ──────────────────────────────────────────────

Code of Conduct

calderonsamuel commented 1 month ago

Thank you for your report and your reprex. We'll take a look into this