nsarrazin commited on
Commit
6cd421f
·
unverified ·
1 Parent(s): 7e91987

feat(reasoning): support end token search across multiple chunks (#1838)

Browse files

* feat(huggingchat): model update 27-05-25

* feat: update prompt examples in config

* feat: revert model config changes

src/lib/server/textGeneration/generate.ts CHANGED
@@ -154,6 +154,40 @@ Do not use prefixes such as Response: or Answer: when answering to the user.`,
154
  if (reasoning) {
155
  reasoningBuffer += output.token.text;
156
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
157
  // yield status update if it has changed
158
  if (status !== "") {
159
  yield {
 
154
  if (reasoning) {
155
  reasoningBuffer += output.token.text;
156
 
157
+ if (model.reasoning && model.reasoning.type === "tokens") {
158
+ // split reasoning buffer so that anything that comes after the end token is separated
159
+ // add it to the normal buffer, and yield two updates, one for the reasoning and one for the normal content
160
+ // also set reasoning to false
161
+
162
+ if (reasoningBuffer.lastIndexOf(model.reasoning.endToken) !== -1) {
163
+ const endTokenIndex = reasoningBuffer.lastIndexOf(model.reasoning.endToken);
164
+ const textBuffer = reasoningBuffer.slice(endTokenIndex + model.reasoning.endToken.length);
165
+ reasoningBuffer = reasoningBuffer.slice(
166
+ 0,
167
+ endTokenIndex + model.reasoning.endToken.length + 1
168
+ );
169
+
170
+ yield {
171
+ type: MessageUpdateType.Reasoning,
172
+ subtype: MessageReasoningUpdateType.Stream,
173
+ token: output.token.text,
174
+ };
175
+
176
+ yield {
177
+ type: MessageUpdateType.Stream,
178
+ token: textBuffer,
179
+ };
180
+
181
+ yield {
182
+ type: MessageUpdateType.Reasoning,
183
+ subtype: MessageReasoningUpdateType.Status,
184
+ status: `Done in ${Math.round((new Date().getTime() - startTime.getTime()) / 1000)}s.`,
185
+ };
186
+
187
+ reasoning = false;
188
+ continue;
189
+ }
190
+ }
191
  // yield status update if it has changed
192
  if (status !== "") {
193
  yield {