Hiren122 commited on
Commit
ee4e40d
·
verified ·
1 Parent(s): a600bbe

Update session_id.py

Browse files
Files changed (1) hide show
  1. session_id.py +18 -14
session_id.py CHANGED
@@ -1,21 +1,25 @@
1
  import os
2
  import requests
3
 
4
- url = "https://cloud.onyx.app/api/chat/create-chat-session"
 
5
 
6
- payload = {
7
- "persona_id": 0,
8
- "description": "Session created via script",
9
- "project_id": 123
10
- }
11
 
12
- headers = {
13
- "Authorization": f"Bearer {os.getenv('PR_KEY')}",
14
- "Content-Type": "application/json"
15
- }
16
 
17
- response = requests.post(url, json=payload, headers=headers, timeout=60)
18
- response.raise_for_status()
19
 
20
- data = response.json()
21
- print(data["chat_session_id"])
 
 
 
 
1
  import os
2
  import requests
3
 
4
+ def generate_chat_session_id():
5
+ url = "https://cloud.onyx.app/api/chat/create-chat-session"
6
 
7
+ payload = {
8
+ "persona_id": 0,
9
+ "description": "auto session per response",
10
+ "project_id": 123
11
+ }
12
 
13
+ headers = {
14
+ "Authorization": f"Bearer {os.getenv('PR_KEY')}",
15
+ "Content-Type": "application/json"
16
+ }
17
 
18
+ response = requests.post(url, json=payload, headers=headers, timeout=60)
19
+ response.raise_for_status()
20
 
21
+ return response.json()["chat_session_id"]
22
+
23
+
24
+ if __name__ == "__main__":
25
+ print(generate_chat_session_id())