mpociot / chatgpt-vscode

A VSCode extension that allows you to use ChatGPT
4.96k stars 366 forks source link

Feature: allow us to use api tokens #28

Open ollyde opened 1 year ago

ollyde commented 1 year ago

I wrote an Alfred script for chatgpt; so I know it’s possible to use the api key instead of the session token. Much more reliable.

timkmecl commented 1 year ago

Hi @ollydixon, what exactly do you mean by api token? The official OpenAI API key or something else?

ollyde commented 1 year ago

In OpenAI we have API keys which how you're supposed to use their APIs.

Using the session key might get your account banned.

Screenshot 2023-01-03 at 19 54 57
timkmecl commented 1 year ago

You're right, that's the correct/official way of using OpenAI API, and I have a version of this extension that uses this method to query GPT3 here (but it does not always perform as well as ChatGPT).

However, there is currently no official way to connect to ChatGPT as opposed to GPT3 via their API, so we have to use some unofficial ones until they release it, hopefully soon.

ollyde commented 1 year ago

You can connect to ChatGPT 3

Here's an example using the API key.


curl https://api.openai.com/v1/completions \
  -H 'Content-Type: application/json' \
  -H "Authorization: Bearer [api key]" \
  -d '{
  "model": "text-davinci-003",
  "prompt": "${query}",
  "max_tokens": 4000,
  "temperature": 0.9 
}' | /opt/homebrew/bin/jq '.choices[].text' | cut -c6- | sed 's/.$//' > temp.txt 
timkmecl commented 1 year ago

Your code does not connect to the same model that is available online via chat interface. The code you posted connects to code-davinci, a GPT3.5 model (that is used by my extension I linked above), but not ChatGPT which is a finetuned model based on it.

ollyde commented 1 year ago

Your code does not connect to the same model that is available online via chat interface. The code you posted connects to code-davinci, a GPT3.5 model (that is used by my extension I linked above), but not ChatGPT which is a finetuned model based on it.

Oh I didn't know

timkmecl commented 1 year ago

No problem! After the release of ChatGPT, many people online started calling Gpt3 ChatGpt to join the hype😆 That's why it's easy to mix them up

timkmecl commented 1 year ago

@ollydixon Try latest update of my version's repo (the updated version is already on the Marketplace so just update it if you already have it installed)

It uses a method described in this tweet (simple Node.js implementation here), already implemented in the unofficial chatgpt api. Only the official API key from OpenAI needed.

This is exactly what you wanted I think