Spaces:
Runtime error
Runtime error
Reserve answer space for long tokens; paramter test.
Browse files
app.py
CHANGED
|
@@ -84,10 +84,16 @@ def evaluate_stream(msg, history, temperature, top_p):
|
|
| 84 |
context += history[-1][0]
|
| 85 |
context = context.replace(r'<br>', '')
|
| 86 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 87 |
h = []
|
| 88 |
print("History:", history)
|
| 89 |
print("Context:", context)
|
| 90 |
-
for response, h in model.stream_chat(tokenizer, context, h, max_length=
|
| 91 |
history[-1][1] = response
|
| 92 |
yield history, ""
|
| 93 |
|
|
@@ -108,7 +114,7 @@ with gr.Blocks() as demo:
|
|
| 108 |
with gr.Column(scale=2):
|
| 109 |
temp = gr.components.Slider(minimum=0, maximum=1.1, value=0.95, label="Temperature",
|
| 110 |
info="温度参数,越高的温度生成的内容越丰富,但是有可能出现语法问题。")
|
| 111 |
-
top_p = gr.components.Slider(minimum=0.5, maximum=1.0, value=0.
|
| 112 |
info="top-p参数,只输出前p>top-p的文字,越大生成的内容越丰富,但也可能出现语法问题。数字越小似乎上下文的衔接性越好。")
|
| 113 |
#code = gr.Textbox(label="temp_output", info="解码器输出")
|
| 114 |
#top_k = gr.components.Slider(minimum=1, maximum=200, step=1, value=25, label="Top k",
|
|
|
|
| 84 |
context += history[-1][0]
|
| 85 |
context = context.replace(r'<br>', '')
|
| 86 |
|
| 87 |
+
# TODO: Avoid the tokens are too long.
|
| 88 |
+
CUTOFF = 160
|
| 89 |
+
while tokenizer.encode(context) > CUTOFF:
|
| 90 |
+
# save 15 token size for the answer
|
| 91 |
+
context = context[15:]
|
| 92 |
+
|
| 93 |
h = []
|
| 94 |
print("History:", history)
|
| 95 |
print("Context:", context)
|
| 96 |
+
for response, h in model.stream_chat(tokenizer, context, h, max_length=CUTOFF, top_p=top_p, temperature=temperature):
|
| 97 |
history[-1][1] = response
|
| 98 |
yield history, ""
|
| 99 |
|
|
|
|
| 114 |
with gr.Column(scale=2):
|
| 115 |
temp = gr.components.Slider(minimum=0, maximum=1.1, value=0.95, label="Temperature",
|
| 116 |
info="温度参数,越高的温度生成的内容越丰富,但是有可能出现语法问题。")
|
| 117 |
+
top_p = gr.components.Slider(minimum=0.5, maximum=1.0, value=0.9, label="Top-p",
|
| 118 |
info="top-p参数,只输出前p>top-p的文字,越大生成的内容越丰富,但也可能出现语法问题。数字越小似乎上下文的衔接性越好。")
|
| 119 |
#code = gr.Textbox(label="temp_output", info="解码器输出")
|
| 120 |
#top_k = gr.components.Slider(minimum=1, maximum=200, step=1, value=25, label="Top k",
|