yashbyname commited on
Commit
c15f3d1
·
verified ·
1 Parent(s): fd7fd22

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -0
app.py CHANGED
@@ -20,6 +20,37 @@ logger = logging.getLogger(__name__)
20
  api_key = 'KGSjxB1uptfSk8I8A7ciCuNT9Xa3qWC3'
21
  external_user_id = 'plugin-1717464304'
22
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
23
  def load_model():
24
  try:
25
  model_path = 'model_epoch_01.h5.keras'
 
20
  api_key = 'KGSjxB1uptfSk8I8A7ciCuNT9Xa3qWC3'
21
  external_user_id = 'plugin-1717464304'
22
 
23
+ # Step 1: Create a chat session
24
+ def create_chat_session():
25
+ create_session_url = 'https://api.on-demand.io/chat/v1/sessions'
26
+ create_session_headers = {
27
+ 'apikey': api_key
28
+ }
29
+ create_session_body = {
30
+ "pluginIds": [],
31
+ "externalUserId": external_user_id
32
+ }
33
+ # Make the request to create a chat session
34
+ response = requests.post(create_session_url, headers=create_session_headers, json=create_session_body)
35
+ response_data = response.json()
36
+ session_id = response_data['data']['id']
37
+ return session_id
38
+
39
+ # Step 2: Submit a query to the API
40
+ def submit_query(session_id, query):
41
+ submit_query_url = f'https://api.on-demand.io/chat/v1/sessions/{session_id}/query'
42
+ submit_query_headers = {
43
+ 'apikey': api_key
44
+ }
45
+ submit_query_body = {
46
+ "endpointId": "predefined-openai-gpt4o",
47
+ "query": query,
48
+ "pluginIds": ["plugin-1712327325", "plugin-1713962163"],
49
+ "responseMode": "sync"
50
+ }
51
+ response = requests.post(submit_query_url, headers=submit_query_headers, json=submit_query_body)
52
+ return response.json()
53
+
54
  def load_model():
55
  try:
56
  model_path = 'model_epoch_01.h5.keras'