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

Add OpenAI key validation in settings page #53

Open
Tharun220602 opened this issue Jul 12, 2024 · 1 comment
Open

Add OpenAI key validation in settings page #53

Tharun220602 opened this issue Jul 12, 2024 · 1 comment
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@Tharun220602
Copy link

Steps

  1. Go to Settings
  2. Type in any key
  3. Click update changes

Observed: Any key gets accepted
Expected: Only valid keys need to be accepted

@JohnHunt999 JohnHunt999 added the good first issue Good for newcomers label Jul 15, 2024
@neelayan7 neelayan7 added the enhancement New feature or request label Jul 16, 2024
@PRASANNAPATHI
Copy link

I have worked on this issue of OpenAI API key validation on the settings page to ensure only valid keys are accepted. Here's a summary of the changes:

1. API Key Format Validation:

  • Introduced the isValidApiKeyFormat function in DashboardService.tsx to validate the API key format using a regex pattern.
  • This prevents incorrectly formatted keys from being processed further.

2. Validation Against OpenAI's API & GPT-4o Model:

  • Added the validateOpenAIKey function to check the validity of the API key by making a request to OpenAI’s API.
    • First, it checks if the API key format is valid.
    • Then, it makes a request to OpenAI to verify the key and ensure access to the GPT-4o model.

3. Integration in Models.tsx:

  • Updated Models.tsx to integrate the validation function. Now, before proceeding with further actions, the API key is checked to ensure both format and validity.

Testing:

Before validation:

  • Previously, even a 4-digit number like 1234 was accepted.

After validation:

  • Invalid pattern example: A string like 12345 will throw an error: 'Invalid API key format'.
  • Invalid OpenAI API key example: An expired key like sk-tVqE067MxmfAAPP68iuVT3BlbkFJkUz40Ub1cvyUUXrG3S will throw an error: 'Invalid API key'.

Here is the screenshot of its working,

This is example with expired key,
Screenshot 2024-09-14 173638

This is with format validation,
Screenshot 2024-09-14 170439

@neelayan7 @JohnHunt999 Could you please assign this issue to me? I’ll be happy to raise a PR once assigned. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
Status: Todo
Development

No branches or pull requests

4 participants