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,6 +5317,7 @@ function parseAndSaveLogprobs(data, continueFrom) { | ||
| 5317 | 5317 | * @returns {string} Extracted message |
| 5318 | 5318 | */ |
| 5319 | 5319 | export function extractMessageFromData(data, activeApi = null) { |
| 5320 | + function getResult() { | |
| 5320 | 5321 | if (typeof data === 'string') { |
| 5321 | 5322 | return data; |
| 5322 | 5323 | } |
| @@ -5341,6 +5342,10 @@ export function extractMessageFromData(data, activeApi = null) { | ||
| 5341 | 5342 | } |
| 5342 | 5343 | } |
| 5343 | 5344 | |
| 5345 | + const result = getResult(); | |
| 5346 | + return Array.isArray(result) ? result.map(x => x.text).filter(x => x).join('') : result; | |
| 5347 | +} | |
| 5348 | + | |
| 5344 | 5349 | /** |
| 5345 | 5350 | * Extracts JSON from the response data. |
| 5346 | 5351 | * @param {object} data Response data |
| @@ -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: |