Explorar o código

api_like_OAI.py : compat with Microsoft Guidance (#2746)

Check for None in addition to empty string check in all request params

Co-authored-by: Georgi Gerganov <ggerganov@gmail.com>
Ryder Wishart %!s(int64=2) %!d(string=hai) anos
pai
achega
8e6716a102
Modificáronse 1 ficheiros con 7 adicións e 1 borrados
  1. 7 1
      examples/server/api_like_OAI.py

+ 7 - 1
examples/server/api_like_OAI.py

@@ -23,7 +23,13 @@ parser.add_argument("--port", type=int, help="Set the port to listen.(default: 8
 args = parser.parse_args()
 args = parser.parse_args()
 
 
 def is_present(json, key):
 def is_present(json, key):
-    return key in json
+    try:
+        buf = json[key]
+    except KeyError:
+        return False
+    if json[key] == None:
+        return False
+    return True
 
 
 #convert chat to prompt
 #convert chat to prompt
 def convert_chat(messages):
 def convert_chat(messages):