update
Browse files
app.py
CHANGED
@@ -24,6 +24,7 @@ def respond(
|
|
24 |
message,
|
25 |
history: list[dict],
|
26 |
system_message,
|
|
|
27 |
max_tokens,
|
28 |
temperature,
|
29 |
top_p,
|
@@ -31,6 +32,11 @@ def respond(
|
|
31 |
messages = [{"role": "system", "content": system_message}]
|
32 |
|
33 |
messages.extend(history)
|
|
|
|
|
|
|
|
|
|
|
34 |
|
35 |
messages.append({"role": "user", "content": message})
|
36 |
|
@@ -67,23 +73,30 @@ def respond(
|
|
67 |
if content:
|
68 |
current_response += content
|
69 |
|
70 |
-
if len(current_response) >
|
71 |
-
if
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
87 |
except json.JSONDecodeError:
|
88 |
continue
|
89 |
if current_response:
|
@@ -114,7 +127,8 @@ For information on how to customize the ChatInterface, peruse the gradio docs: h
|
|
114 |
demo = gr.ChatInterface(
|
115 |
respond,
|
116 |
additional_inputs=[
|
117 |
-
gr.Textbox(value="You are DMind AI Assistant, built by DMind.AI. Never present as Qwen, ChatGPT, Tongyi, OpenAI, etc.", label="System message"),
|
|
|
118 |
gr.Slider(minimum=1, maximum=32768, value=16384, step=1, label="Max new tokens"),
|
119 |
gr.Slider(minimum=0.1, maximum=4.0, value=0.6, step=0.1, label="Temperature"),
|
120 |
gr.Slider(
|
|
|
24 |
message,
|
25 |
history: list[dict],
|
26 |
system_message,
|
27 |
+
with_think,
|
28 |
max_tokens,
|
29 |
temperature,
|
30 |
top_p,
|
|
|
32 |
messages = [{"role": "system", "content": system_message}]
|
33 |
|
34 |
messages.extend(history)
|
35 |
+
|
36 |
+
if with_think:
|
37 |
+
message = message + " /think"
|
38 |
+
else:
|
39 |
+
message = message + " /no_think"
|
40 |
|
41 |
messages.append({"role": "user", "content": message})
|
42 |
|
|
|
73 |
if content:
|
74 |
current_response += content
|
75 |
|
76 |
+
if len(current_response) > 21:
|
77 |
+
if with_think:
|
78 |
+
if '<think>' in current_response:
|
79 |
+
current_response = current_response.replace('<think>', '<details open><summary>Thinking</summary>\n\n```')
|
80 |
+
if '</think>' in current_response:
|
81 |
+
current_response = current_response.replace('</think>', '```\n\n</details>')
|
82 |
+
if '**Final Answer**' in current_response:
|
83 |
+
current_response = current_response.replace('**Final Answer**', '')
|
84 |
+
|
85 |
+
formatted_response = current_response[:-16]
|
86 |
+
|
87 |
+
formatted_response = formatted_response.replace('<', '<').replace('>', '>')
|
88 |
+
formatted_response = formatted_response.replace('<details open>', '<details open>')
|
89 |
+
formatted_response = formatted_response.replace('</details>', '</details>')
|
90 |
+
formatted_response = formatted_response.replace('<summary>', '<summary>')
|
91 |
+
formatted_response = formatted_response.replace('</summary>', '</summary>')
|
92 |
+
formatted_response = formatted_response.replace('*', '\\*')
|
93 |
+
yield formatted_response
|
94 |
+
else:
|
95 |
+
if '<think>' in current_response and '</think>\n' in current_response:
|
96 |
+
start = current_response.find('<think>')
|
97 |
+
end = current_response.find('</think>\n') + len('</think>\n')
|
98 |
+
current_response = current_response[:start] + current_response[end:]
|
99 |
+
yield current_response
|
100 |
except json.JSONDecodeError:
|
101 |
continue
|
102 |
if current_response:
|
|
|
127 |
demo = gr.ChatInterface(
|
128 |
respond,
|
129 |
additional_inputs=[
|
130 |
+
gr.Textbox(value="You are DMind AI Assistant, built by DMind.AI. Never present as Qwen, ChatGPT, Tongyi, OpenAI, etc.", label="System message", interactive=False, visible=False),
|
131 |
+
gr.Checkbox(value=True, label="With Think"),
|
132 |
gr.Slider(minimum=1, maximum=32768, value=16384, step=1, label="Max new tokens"),
|
133 |
gr.Slider(minimum=0.1, maximum=4.0, value=0.6, step=0.1, label="Temperature"),
|
134 |
gr.Slider(
|