tianlong12 commited on
Commit
2832e52
1 Parent(s): c2f8097

Create helper.py

Browse files
Files changed (1) hide show
  1. helper.py +24 -0
helper.py ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import jwt
2
+ import uuid
3
+ from datetime import datetime, timedelta
4
+
5
+ github_username_zed_userid_list = [
6
+ ("aaa", 123123),
7
+ ]
8
+
9
+ def create_jwt(github_user_login: str, user_id: int) -> str:
10
+ LLM_TOKEN_LIFETIME = timedelta(hours=1)
11
+ now = datetime.utcnow()
12
+
13
+ payload = {
14
+ "iat": int(now.timestamp()),
15
+ "exp": int((now + LLM_TOKEN_LIFETIME).timestamp()),
16
+ "jti": str(uuid.uuid4()),
17
+ "userId": user_id,
18
+ "githubUserLogin": github_user_login,
19
+ "isStaff": False,
20
+ "hasLlmClosedBetaFeatureFlag": False,
21
+ "plan": "Free"
22
+ }
23
+
24
+ return jwt.encode(payload, 'llm-secret', algorithm='HS256')