Commit 0004cc8 authored Apr 18, 2023 Verified
1 parent 6741975 commit 0004cc8 Copy full SHA for 0004cc8
File tree 2 files changed +27
-4
lines changed
2 files changed +27
-4
lines changed Original file line number Diff line number Diff line change 1
1
#! /bin/bash
2
2
cd " $( dirname " $0 " ) " || exit
3
3
4
- echo -n " Enter your OpenAI Key (eg: sk...): "
4
+ is_valid_sk_key () {
5
+ local api_key=$1
6
+ local pattern=" ^sk-[a-zA-Z0-9]{48}$"
7
+ [[ $api_key =~ $pattern ]] && return 0 || return 1
8
+ }
9
+
10
+ echo -n " Enter your OpenAI Key (eg: sk...) or press enter to continue with no key: "
5
11
read OPENAI_API_KEY
6
12
13
+ if is_valid_sk_key $OPENAI_API_KEY || [ -z " $OPENAI_API_KEY " ]; then
14
+ echo " Valid API key"
15
+ else
16
+ echo " Invalid API key. Please ensure that you have billing set up on your OpenAI account"
17
+ exit
18
+ fi
19
+
7
20
NEXTAUTH_SECRET=$( openssl rand -base64 32)
8
21
9
22
ENV=" NODE_ENV=development\n\
24
37
./prisma/useSqlite.sh
25
38
npm install
26
39
npm run dev
27
- fi
40
+ fi
Original file line number Diff line number Diff line change @@ -45,9 +45,19 @@ export default function SettingsDialog({
45
45
close ( ) ;
46
46
} ;
47
47
48
+ function is_valid_key ( key : string ) {
49
+ const pattern = / ^ s k - [ a - z A - Z 0 - 9 ] { 48 } $ / ;
50
+ return pattern . test ( key ) ;
51
+ }
52
+
48
53
const handleSave = ( ) => {
49
- setCustomApiKey ( key ) ;
50
- close ( ) ;
54
+ if ( is_valid_key ( key ) ) {
55
+ setCustomApiKey ( key ) ;
56
+ close ( ) ;
57
+ }
58
+ else {
59
+ alert ( "key is invalid, please ensure that you have set up billing in your OpenAI account" )
60
+ }
51
61
} ;
52
62
53
63
React . useEffect ( ( ) => {
You can’t perform that action at this time.
0 commit comments