gencay / vscode-chatgpt

An unofficial Visual Studio Code - OpenAI ChatGPT integration
ISC License
3.5k stars 760 forks source link

Feature: Use API key not session token #42

Closed benzntech closed 1 year ago

benzntech commented 1 year ago

Allow us to use the API key which is consistent and how we are supposed to use the ChatGPT API.

Example of curl using the api

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 

REFERENCE: https://beta.openai.com/docs/api-reference/authentication

Use the official OpenAI API to generate code or natural language responses from OpenAI's GPT3/GPT3.5 to your questions, right within the editor

gencay commented 1 year ago

Thanks for the suggestion! Yes, this is in the todo list for the extension

benzntech commented 1 year ago

Use the official OpenAI API to generate code or natural language responses from OpenAI's GPT3/GPT3.5 to your questions, right within the editor

https://github.com/timkmecl/codegpt

benzntech commented 1 year ago

Limitation on API :
OpenAI has some rate limits on their API access:

20 requests per minute for free access 60 rpm in pay as you go initially, then it ramps up to 3000 later see https://help.openai.com/en/articles/5955598-is-api-usage-subject-to-any-rate-limits for details.

Describe the solution you'd like I see 3 solutions:

get paid plan and wait a bit (3000 requests per minute should be fine for most cases) hack a time.sleep(X) in here haystack implements an optional rate limit in the eval methods

This request queries the Davinci model to complete the text starting with a prompt of "Say this is a test". The max_tokens parameter sets an upper bound on how many tokens the API will return. You should get a response back that resembles the following:

API usage subject to any rate limits image

gencay commented 1 year ago

@benzntech please check V3. OpenAI GPT3 integration is now available. And yes, there are rate-limits and I suspect the APIs will get more restrictive in the future. But I added it as a method for people to experiment with their personal or organizational API Keys.

benzntech commented 1 year ago

API is not working. Ask to reset the session not working as expected.