Update app.py
Browse files
app.py
CHANGED
@@ -323,48 +323,49 @@ def handsome_chat_completions():
|
|
323 |
|
324 |
user_content = extract_user_content(data.get("messages", []))
|
325 |
|
326 |
-
|
327 |
-
|
328 |
|
|
|
329 |
logging.info("成功拦截一次!")
|
330 |
-
|
331 |
if data.get("stream", False):
|
332 |
-
|
333 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
334 |
"choices": [
|
335 |
{
|
336 |
-
"
|
337 |
"content": canned_response_content
|
338 |
},
|
339 |
"index": 0,
|
340 |
"finish_reason": "stop"
|
341 |
}
|
342 |
-
]
|
|
|
|
|
|
|
|
|
|
|
343 |
}
|
344 |
-
|
345 |
-
yield f"data: [DONE]\n\n".encode("utf-8")
|
346 |
-
return Response(
|
347 |
-
stream_with_context(generate_canned_stream()),
|
348 |
-
content_type="text/event-stream"
|
349 |
-
)
|
350 |
-
else:
|
351 |
-
canned_response = {
|
352 |
-
"choices": [
|
353 |
-
{
|
354 |
-
"message": {
|
355 |
-
"content": canned_response_content
|
356 |
-
},
|
357 |
-
"index": 0,
|
358 |
-
"finish_reason": "stop"
|
359 |
-
}
|
360 |
-
],
|
361 |
-
"usage": {
|
362 |
-
"prompt_tokens": 0,
|
363 |
-
"completion_tokens": 0,
|
364 |
-
"total_tokens": 0
|
365 |
-
}
|
366 |
-
}
|
367 |
-
return jsonify(canned_response)
|
368 |
|
369 |
api_key = select_key(request_type, model_name)
|
370 |
|
|
|
323 |
|
324 |
user_content = extract_user_content(data.get("messages", []))
|
325 |
|
326 |
+
phrases_to_check = ["hello", "你好", "什么模型", "签到", "社工", "你是谁"]
|
327 |
+
canned_response_content = "这是公益api,模型全部可用且保真,请不要对模型进行无意义的测试,请尽量不要使用高级模型解决没必要的问题。\n换个话题吧,请不要对模型进行无意义的测试,请尽量不要使用高级模型解决没必要的问题。"
|
328 |
|
329 |
+
if any(phrase in user_content.lower() for phrase in phrases_to_check):
|
330 |
logging.info("成功拦截一次!")
|
331 |
+
|
332 |
if data.get("stream", False):
|
333 |
+
def generate_canned_stream():
|
334 |
+
message_data = {
|
335 |
+
"choices": [
|
336 |
+
{
|
337 |
+
"delta": {
|
338 |
+
"content": canned_response_content
|
339 |
+
},
|
340 |
+
"index": 0,
|
341 |
+
"finish_reason": "stop"
|
342 |
+
}
|
343 |
+
]
|
344 |
+
}
|
345 |
+
yield f"data: {json.dumps(message_data)}\n\n".encode("utf-8")
|
346 |
+
yield f"data: [DONE]\n\n".encode("utf-8")
|
347 |
+
return Response(
|
348 |
+
stream_with_context(generate_canned_stream()),
|
349 |
+
content_type="text/event-stream"
|
350 |
+
)
|
351 |
+
else:
|
352 |
+
canned_response = {
|
353 |
"choices": [
|
354 |
{
|
355 |
+
"message": {
|
356 |
"content": canned_response_content
|
357 |
},
|
358 |
"index": 0,
|
359 |
"finish_reason": "stop"
|
360 |
}
|
361 |
+
],
|
362 |
+
"usage": {
|
363 |
+
"prompt_tokens": 0,
|
364 |
+
"completion_tokens": 0,
|
365 |
+
"total_tokens": 0
|
366 |
+
}
|
367 |
}
|
368 |
+
return jsonify(canned_response)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
369 |
|
370 |
api_key = select_key(request_type, model_name)
|
371 |
|