Vibow commited on
Commit
3cd12ed
·
verified ·
1 Parent(s): eecd2db

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -4
app.py CHANGED
@@ -767,10 +767,15 @@ def chat():
767
  except Exception:
768
  return Response("Cohere non-json response", mimetype="text/plain", status=500)
769
 
770
- ai_text = (
771
- res_json
772
- .get("content", {})
773
- )
 
 
 
 
 
774
 
775
  return Response(ai_text, mimetype="text/plain")
776
  # =====================================================
 
767
  except Exception:
768
  return Response("Cohere non-json response", mimetype="text/plain", status=500)
769
 
770
+ ai_text = ""
771
+ if (
772
+ isinstance(res_json, dict)
773
+ and "message" in res_json
774
+ and "content" in res_json["message"]
775
+ and isinstance(res_json["message"]["content"], list)
776
+ and len(res_json["message"]["content"]) > 0
777
+ ):
778
+ ai_text = res_json["message"]["content"][0].get("text", "")
779
 
780
  return Response(ai_text, mimetype="text/plain")
781
  # =====================================================