Futuresony commited on
Commit
596e686
·
verified ·
1 Parent(s): 114406d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -4
app.py CHANGED
@@ -24,21 +24,24 @@ async def chat(request: Request):
24
  raise HTTPException(status_code=403, detail="Invalid API Key")
25
 
26
  user_message = data.get("message")
27
- chat_history = data.get("chat_history", []) # Extract chat_history from request
28
  user_id = data.get("user_id") # Extract user_id from request
29
 
30
  if not user_message:
31
  raise HTTPException(status_code=400, detail="Message is required")
32
 
33
- # Call your hosted Space, passing the user_id
 
 
 
34
  result = client.predict(
35
  query=user_message,
36
- chat_history=chat_history, # Pass chat_history to the hosted space
37
  api_key=api_key, # Pass the validated api_key
38
  user_id=user_id, # Pass the user_id
39
- api_name="/chat"
40
  )
41
 
 
42
  return {"response": result}
43
 
44
  if __name__ == "__main__":
 
24
  raise HTTPException(status_code=403, detail="Invalid API Key")
25
 
26
  user_message = data.get("message")
27
+ # chat_history = data.get("chat_history", []) # Chat history is handled by Gradio's ChatInterface internally
28
  user_id = data.get("user_id") # Extract user_id from request
29
 
30
  if not user_message:
31
  raise HTTPException(status_code=400, detail="Message is required")
32
 
33
+ # Call your hosted Space, passing the user_id and message
34
+ # Chat history is managed by the Gradio ChatInterface itself,
35
+ # so we pass the user_id as an additional input.
36
+ # The message is passed as the primary query.
37
  result = client.predict(
38
  query=user_message,
 
39
  api_key=api_key, # Pass the validated api_key
40
  user_id=user_id, # Pass the user_id
41
+ api_name="/chat" # Ensure this matches the endpoint in the Gradio app
42
  )
43
 
44
+
45
  return {"response": result}
46
 
47
  if __name__ == "__main__":