carlrobertoh / CodeGPT

JetBrains extension providing access to state-of-the-art LLMs, such as GPT-4, Claude 3, Code Llama, and others, all for free
https://codegpt.ee
Apache License 2.0
912 stars 186 forks source link

can't use groq #511

Closed dss99911 closed 4 weeks ago

dss99911 commented 2 months ago

What happened?

Connection failed.

Incorrect API key provided: $CUSTOM_***_KEY. You can find your API key at https://platform.openai.com/account/api-keys.

Relevant log output or stack trace

No response

Steps to reproduce

  1. get api key from https://groq.com/

  2. on codegpt setting,

    • select custom openai service
    • select 'Groq' on preset template
    • input api key
    • click test connection

the error below occurred

Connection failed.

Incorrect API key provided: $CUSTOM_***********_KEY. You can find your API key at
https://platform.openai.com/account/api-keys.

when I tested on curl below, it's working fine.

curl -X POST "https://api.groq.com/openai/v1/chat/completions" \
     -H "Authorization: Bearer $GROQ_API_KEY" \
     -H "Content-Type: application/json" \
     -d '{"messages": [{"role": "user", "content": "Explain the importance of fast language models"}], "model": "mixtral-8x7b-32768"}'

CodeGPT version

2.6.3-241

Operating System

macOS

sisve commented 2 months ago

The error message indicates that 1) you're talking to openai.com, and 2) you're sending the literal string $CUSTOM_SERVICE_API_KEY as your api-key.

Can you verify that you have configured an custom URL and api-key in your CodeGPT plugin settings?

dss99911 commented 2 months ago

when I select 'Groq' on preset template. it changes the URL to https://api.groq.com/openai/v1/chat/completions automatically. I used the url

dss99911 commented 2 months ago
image
carlrobertoh commented 2 months ago

Did you apply the settings before testing the connection? There's a small bug around that.

dss99911 commented 2 months ago

the settings I mentioned above is applied before testing the connection

reneleonhardt commented 2 months ago

Same here since #476 has been merged, the wrong settings are being used for Custom OpenAI, depending on your application state. If you switch presets, the default settings are being applied (Ollama has no code completions, tab is disabled). If you reopen the settings dialog again, code completions becomes active with default settings for OpenAI (first FIM template autoselected), hence the Incorrect API key provided response for platform.openai.com (Ollama runs on localhost). So the user settings are being overwritten sometimes with "default values" or empty values depending on Preset template change, FIM template change, open settings dialog (init forms)... This feature is very flaky, I would suggest writing tests first for all supported services, models and FIM templates (success and errors like missing API key, unexpected API key, unexpected response). And especially changing user settings without the user knowing it, initializing forms shouldn't change persisted users settings but instead load them, but many more settings are changed/deleted/added depending on the selected Preset and FIM. Maybe it would be helpful if the listener would be usable with checked exceptions instead of RuntimeExceptions, so the application would have to handle all errors explicitly.

Incorrect API key provided: $CUSTOM_***********_KEY. You can find your API key at https://platform.openai.com/account/api-keys.

java.lang.RuntimeException
    at ee.carlrobert.llm.completion.CompletionEventSourceListener.onFailure(CompletionEventSourceListener.java:114)
    at okhttp3.internal.sse.RealEventSource.processResponse(RealEventSource.kt:52)
dss99911 commented 2 months ago

thanks for the solution. but, I couldn't understand the detail.

  1. can it be fixed?
  2. is there workaround before it's fixed?
reneleonhardt commented 2 months ago

Never open settings again before the next CodeGPT release 😅 Before closing settings, make sure to switch the Preset template first and check all settings to be correct.

carlrobertoh commented 2 months ago

@dss99911

is there workaround before it's fixed?

Delete CodeGPT_CustomServiceSettings.xml settings file from the options folder and restart your IDE.

https://intellij-support.jetbrains.com/hc/en-us/articles/206544519-Directories-used-by-the-IDE-to-store-settings-caches-plugins-and-logs

PhilKes commented 2 months ago

This is fixed by https://github.com/carlrobertoh/CodeGPT/pull/531