Fix Magistral latest reasoning extraction Fixes #4339

d21afa1ae58e5ab2c1e848d538eb94369de6db98

Cohee <18619528+Cohee1207@users.noreply.github.com>

4 files changed, +30 -17Ignore whitespace
public/index.html+1 -1
@@ -2065,7 +2065,7 @@
20652065 </span>
20662066 </div>
20672067 </div>
20682068 <div class="range-block" data-source="deepseek,aimlapi,openrouter,custom,claude,xai,makersuite,vertexai,pollinations,moonshot,mistralai">
20692069 <label for="openai_show_thoughts" class="checkbox_label widthFreeExpand">
20702070 <input id="openai_show_thoughts" type="checkbox" />
20712071 <span data-i18n="Request model reasoning">Request model reasoning</span>
public/script.js+21 -16
@@ -5317,28 +5317,33 @@ function parseAndSaveLogprobs(data, continueFrom) {
53175317 * @returns {string} Extracted message
53185318 */
53195319export function extractMessageFromData(data, activeApi = null) {
5320- if (typeof data === 'string') {
5320+ function getResult() {
5321- return data;
5321+ if (typeof data === 'string') {
5322- }
5322+ return data;
5323+ }
53235324
53245325 switch (activeApi ?? main_api) {
53255326 case 'kobold':
53265327 return data.results[0].text;
53275328 case 'koboldhorde':
53285329 return data.text;
53295330 case 'textgenerationwebui':
53305331 return data.choices?.[0]?.text
53315332 ?? data.choices?.[0]?.message?.content
53325333 ?? data.content
53335334 ?? data.response
53345335 ?? '';
53355336 case 'novel':
53365337 return data.output;
53375338 case 'openai':
53385339 return data?.content?.find(p => p.type === 'text')?.text ?? data?.choices?.[0]?.message?.content ?? data?.choices?.[0]?.text ?? data?.text ?? data?.message?.content?.[0]?.text ?? data?.message?.tool_plan ?? '';
53395340 default:
53405341 return '';
5342+ }
53415343 }
5344+
5345+ const result = getResult();
5346+ return Array.isArray(result) ? result.map(x => x.text).filter(x => x).join('') : result;
53425347}
53435348
53445349/**
public/scripts/openai.js+6 -0
@@ -2399,6 +2399,12 @@ export function getStreamingReply(data, state, { chatCompletionSource = null, ov
23992399 '';
24002400 }
24012401 return data.choices?.[0]?.delta?.content ?? data.choices?.[0]?.message?.content ?? data.choices?.[0]?.text ?? '';
2402+ } else if (chat_completion_source === chat_completion_sources.MISTRALAI) {
2403+ if (show_thoughts) {
2404+ state.reasoning += (data.choices?.filter(x => x?.delta?.content?.[0]?.thinking)?.[0]?.delta?.content?.[0]?.thinking?.[0]?.text || '');
2405+ }
2406+ const content = data.choices?.[0]?.delta?.content ?? data.choices?.[0]?.message?.content ?? data.choices?.[0]?.text ?? '';
2407+ return Array.isArray(content) ? content.map(x => x.text).filter(x => x).join('') : content;
24022408 } else {
24032409 return data.choices?.[0]?.delta?.content ?? data.choices?.[0]?.message?.content ?? data.choices?.[0]?.text ?? '';
24042410 }
public/scripts/reasoning.js+2 -0
@@ -118,6 +118,8 @@ export function extractReasoningFromData(data, {
118118 return data?.responseContent?.parts?.filter(part => part.thought)?.map(part => part.text)?.join('\n\n') ?? '';
119119 case chat_completion_sources.CLAUDE:
120120 return data?.content?.find(part => part.type === 'thinking')?.thinking ?? '';
121+ case chat_completion_sources.MISTRALAI:
122+ return data?.choices?.[0]?.message?.content?.[0]?.thinking?.map(part => part.text)?.filter(x => x)?.join('\n\n') ?? '';
121123 case chat_completion_sources.AIMLAPI:
122124 case chat_completion_sources.POLLINATIONS:
123125 case chat_completion_sources.MOONSHOT: