nanova commited on
Commit
3722ca2
·
1 Parent(s): cade7ed
Files changed (1) hide show
  1. app.py +32 -18
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) > 16:
71
- if '<think>' in current_response:
72
- current_response = current_response.replace('<think>', '<details open><summary>Thinking</summary>\n\n```')
73
- if '</think>' in current_response:
74
- current_response = current_response.replace('</think>', '```\n\n</details>')
75
- if '**Final Answer**' in current_response:
76
- current_response = current_response.replace('**Final Answer**', '')
77
-
78
- formatted_response = current_response[:-16]
79
-
80
- formatted_response = formatted_response.replace('<', '&lt;').replace('>', '&gt;')
81
- formatted_response = formatted_response.replace('&lt;details open&gt;', '<details open>')
82
- formatted_response = formatted_response.replace('&lt;/details&gt;', '</details>')
83
- formatted_response = formatted_response.replace('&lt;summary&gt;', '<summary>')
84
- formatted_response = formatted_response.replace('&lt;/summary&gt;', '</summary>')
85
- formatted_response = formatted_response.replace('*', '\\*')
86
- yield formatted_response
 
 
 
 
 
 
 
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('<', '&lt;').replace('>', '&gt;')
88
+ formatted_response = formatted_response.replace('&lt;details open&gt;', '<details open>')
89
+ formatted_response = formatted_response.replace('&lt;/details&gt;', '</details>')
90
+ formatted_response = formatted_response.replace('&lt;summary&gt;', '<summary>')
91
+ formatted_response = formatted_response.replace('&lt;/summary&gt;', '</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(