approximatelabs / sketch

AI code-writing assistant that understands data content
MIT License
2.21k stars 112 forks source link

Valid OpenApi Key Not Accepted with df.sektch.apply #5

Closed franzenzenhofer closed 1 year ago

franzenzenhofer commented 1 year ago

image

I copied your original Google Colb Example Sheet https://colab.research.google.com/gist/bluecoconut/410a979d94613ea2aaf29987cf0233bc/sketch-demo.ipynb#scrollTo=6xZgjwWypy91

https://colab.research.google.com/gist/bluecoconut/410a979d94613ea2aaf29987cf0233bc/sketch-demo.ipynb

top_5_states = state_sales.sort_values(by='Price Each', ascending=False).head(5).copy() top_5_states.sketch.apply("new column with full name of the states. just the top 5")

added the lines from the screenshot, the error code is always

Not sure what happened: {'error': {'message': "Incorrect API key provided: 'sk-ZCTf*****************************************cUZ'. You can find your API key at https://beta.openai.com/.", 'type': 'invalid_request_error', 'param': None, 'code': 'invalid_api_key'}} Not sure what happened: {'error': {'message': "Incorrect API key provided: 'sk-ZCTf*****************************************cUZ'. You can find your API key at https://beta.openai.com/.", 'type': 'invalid_request_error', 'param': None, 'code': 'invalid_api_key'}} Not sure what happened: {'error': {'message': "Incorrect API key provided: 'sk-ZCTf*****************************************cUZ'. You can find your API key at https://beta.openai.com/.", 'type': 'invalid_request_error', 'param': None, 'code': 'invalid_api_key'}} Not sure what happened: {'error': {'message': "Incorrect API key provided: 'sk-ZCTf*****************************************cUZ'. You can find your API key at https://beta.openai.com/.", 'type': 'invalid_request_error', 'param': None, 'code': 'invalid_api_key'}}

I copied the API key from https://beta.openai.com/account/api-keys

Bug? or What am I missing? Thx

bluecoconut commented 1 year ago

Hmm, I'm not sure.

1 thing to note: your key is visible in the screenshot, so you will probably want to roll that key asap.

it looks like the env var is getting noticed... so my best guess is something about cutting the key a character short or something when copying? Or having a deactivated key?

you can probably quickly test this (without using sketch apply) by just using lambdaprompt directly

import lambdaprompt
import os
os.environ['OPENAI_API_KEY'] = '***'

lambdaprompt.GPT3Prompt("Test completion after this line:")()

it will probably give you the same error (with the same wrong key) and then you can get one that works?

I just ran the above example, with a fresh key, and it worked immediately.

bluecoconut commented 1 year ago

I think this isn't a bug with the library, and i just realized you could probably iterate with the api key directly on openai endpoint as well (just use requests and env vars, and see if your key works)

import requests
import os
os.environ["OPENAI_API_KEY"] = "***"
headers = {
        "Authorization": f"Bearer {os.environ.get('OPENAI_API_KEY')}",
        "Content-Type": "application/json",
    }

data = {
    "prompt": "Hello...",
    "model": "text-davinci-003",
}

resp = requests.post("https://api.openai.com/v1/completions", headers=headers, json=data)
print(resp.text)

If this works for you, then setting up environment variables the same way with sketch doesn't -- then i can re-open this issue (be sure to reach out again here). For now i'm going to close the issue.