Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -1060,6 +1060,7 @@ def chat_response_stream_multiturn(
|
|
| 1060 |
global llm, RES_PRINTED
|
| 1061 |
assert llm is not None
|
| 1062 |
assert system_prompt.strip() != '', f'system prompt is empty'
|
|
|
|
| 1063 |
# force removing all
|
| 1064 |
vllm_abort(llm)
|
| 1065 |
|
|
@@ -1068,6 +1069,8 @@ def chat_response_stream_multiturn(
|
|
| 1068 |
max_tokens = int(max_tokens)
|
| 1069 |
|
| 1070 |
message = message.strip()
|
|
|
|
|
|
|
| 1071 |
|
| 1072 |
message_safety = safety_check(message, history=history)
|
| 1073 |
if message_safety is not None:
|
|
@@ -1079,6 +1082,9 @@ def chat_response_stream_multiturn(
|
|
| 1079 |
message, history, sys_prompt=system_prompt
|
| 1080 |
)
|
| 1081 |
|
|
|
|
|
|
|
|
|
|
| 1082 |
sampling_params = SamplingParams(
|
| 1083 |
temperature=temperature,
|
| 1084 |
max_tokens=max_tokens,
|
|
@@ -1103,7 +1109,7 @@ def chat_response_stream_multiturn(
|
|
| 1103 |
item = next(iter(gen.values()))
|
| 1104 |
cur_out = item.outputs[0].text
|
| 1105 |
|
| 1106 |
-
print(f'@@@@@@@@@@\n{full_prompt}<<<{cur_out}>>>\n
|
| 1107 |
|
| 1108 |
if cur_out is not None and "\\n" in cur_out:
|
| 1109 |
print(f'double slash-n in cur_out:\n{cur_out}')
|
|
|
|
| 1060 |
global llm, RES_PRINTED
|
| 1061 |
assert llm is not None
|
| 1062 |
assert system_prompt.strip() != '', f'system prompt is empty'
|
| 1063 |
+
tokenizer = llm.get_tokenizer()
|
| 1064 |
# force removing all
|
| 1065 |
vllm_abort(llm)
|
| 1066 |
|
|
|
|
| 1069 |
max_tokens = int(max_tokens)
|
| 1070 |
|
| 1071 |
message = message.strip()
|
| 1072 |
+
if len(message) == 0:
|
| 1073 |
+
raise gr.Error("The message cannot be empty!")
|
| 1074 |
|
| 1075 |
message_safety = safety_check(message, history=history)
|
| 1076 |
if message_safety is not None:
|
|
|
|
| 1082 |
message, history, sys_prompt=system_prompt
|
| 1083 |
)
|
| 1084 |
|
| 1085 |
+
if len(tokenizer.encode(full_prompt, add_special_tokens=False)) >= 1000:
|
| 1086 |
+
raise gr.Error(f"Conversation or prompt is too long, please clear the chatbox or try shorter input.")
|
| 1087 |
+
|
| 1088 |
sampling_params = SamplingParams(
|
| 1089 |
temperature=temperature,
|
| 1090 |
max_tokens=max_tokens,
|
|
|
|
| 1109 |
item = next(iter(gen.values()))
|
| 1110 |
cur_out = item.outputs[0].text
|
| 1111 |
|
| 1112 |
+
print(f'@@@@@@@@@@\n{full_prompt}<<<{cur_out}>>>\n##########\n')
|
| 1113 |
|
| 1114 |
if cur_out is not None and "\\n" in cur_out:
|
| 1115 |
print(f'double slash-n in cur_out:\n{cur_out}')
|