Fix Magistral latest reasoning extraction Fixes #4339
| @@ -2065,7 +2065,7 @@ | ||
| 2065 | 2065 | </span> |
| 2066 | 2066 | </div> |
| 2067 | 2067 | </div> |
| 2068 | 2068 | <div class="range-block" data-source="deepseek,aimlapi,openrouter,custom,claude,xai,makersuite,vertexai,pollinations,moonshot,mistralai"> |
| 2069 | 2069 | <label for="openai_show_thoughts" class="checkbox_label widthFreeExpand"> |
| 2070 | 2070 | <input id="openai_show_thoughts" type="checkbox" /> |
| 2071 | 2071 | <span data-i18n="Request model reasoning">Request model reasoning</span> |
| @@ -5317,28 +5317,33 @@ function parseAndSaveLogprobs(data, continueFrom) { | ||
| 5317 | 5317 | * @returns {string} Extracted message |
| 5318 | 5318 | */ |
| 5319 | 5319 | export 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 | + } | |
| 5323 | 5324 | |
| 5324 | 5325 | switch (activeApi ?? main_api) { |
| 5325 | 5326 | case 'kobold': |
| 5326 | 5327 | return data.results[0].text; |
| 5327 | 5328 | case 'koboldhorde': |
| 5328 | 5329 | return data.text; |
| 5329 | 5330 | case 'textgenerationwebui': |
| 5330 | 5331 | return data.choices?.[0]?.text |
| 5331 | 5332 | ?? data.choices?.[0]?.message?.content |
| 5332 | 5333 | ?? data.content |
| 5333 | 5334 | ?? data.response |
| 5334 | 5335 | ?? ''; |
| 5335 | 5336 | case 'novel': |
| 5336 | 5337 | return data.output; |
| 5337 | 5338 | case 'openai': |
| 5338 | 5339 | 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 ?? ''; |
| 5339 | 5340 | default: |
| 5340 | 5341 | return ''; |
| 5342 | + } | |
| 5341 | 5343 | } |
| 5344 | + | |
| 5345 | + const result = getResult(); | |
| 5346 | + return Array.isArray(result) ? result.map(x => x.text).filter(x => x).join('') : result; | |
| 5342 | 5347 | } |
| 5343 | 5348 | |
| 5344 | 5349 | /** |
| @@ -2399,6 +2399,12 @@ export function getStreamingReply(data, state, { chatCompletionSource = null, ov | ||
| 2399 | 2399 | ''; |
| 2400 | 2400 | } |
| 2401 | 2401 | 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; | |
| 2402 | 2408 | } else { |
| 2403 | 2409 | return data.choices?.[0]?.delta?.content ?? data.choices?.[0]?.message?.content ?? data.choices?.[0]?.text ?? ''; |
| 2404 | 2410 | } |
| @@ -118,6 +118,8 @@ export function extractReasoningFromData(data, { | ||
| 118 | 118 | return data?.responseContent?.parts?.filter(part => part.thought)?.map(part => part.text)?.join('\n\n') ?? ''; |
| 119 | 119 | case chat_completion_sources.CLAUDE: |
| 120 | 120 | 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') ?? ''; | |
| 121 | 123 | case chat_completion_sources.AIMLAPI: |
| 122 | 124 | case chat_completion_sources.POLLINATIONS: |
| 123 | 125 | case chat_completion_sources.MOONSHOT: |