Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

login with OpenAI token #28

Closed
Tracked by #4
eubinecto opened this issue May 21, 2022 · 2 comments · Fixed by #29
Closed
Tracked by #4

login with OpenAI token #28

eubinecto opened this issue May 21, 2022 · 2 comments · Fixed by #29

Comments

@eubinecto
Copy link
Owner

eubinecto commented May 21, 2022

What is a simple way of.. just testing if the API token is valid?

@eubinecto eubinecto mentioned this issue May 21, 2022
34 tasks
@eubinecto
Copy link
Owner Author

We could do this in this way, possibly?

import openai
import requests
from requests import HTTPError


def login(key: str):

    url = "https://api.openai.com/v1/engines"
    headers = {
        'Authorization': f"Bearer {key}"
    }
    r = requests.get(url=url, headers=headers)

    try:
        r.raise_for_status()
    except HTTPError as e:
        raise ValueError("Login failed")
    else:
        print(f"Logged in with (The key is valid): {key}. The key is NOT stored in any databases whatsover")


def main():
    # this is where that is stored
    login(openai.api_key)
    login("haha")


if __name__ == '__main__':
    main()

@eubinecto
Copy link
Owner Author

but note - we should still have a master key.

if key == master_key:
  just use pre-registered key
elif key is valid:
  update the master key with  the valid key

eubinecto added a commit that referenced this issue May 21, 2022
eubinecto added a commit that referenced this issue May 21, 2022
@eubinecto eubinecto mentioned this issue May 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant