Merge pull request #3836 from Erquint/staging Enable image inlining for visual models when connected to Mistral AI Le Platforme.

93acbcaa769401814836f7d85fedd5d027462f47

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

Signed
2 files changed, +80 -21Showing whitespace changes
public/index.html+1 -1
@@ -1975,7 +1975,7 @@
19751975 <span data-i18n="enable_functions_desc_3">Can be utilized by various extensions to provide additional functionality.</span>
19761976 </div>
19771977 </div>
19781978 <div class="range-block" data-source="openai,openrouter,mistralai,makersuite,claude,custom,01ai">
19791979 <label for="openai_image_inlining" class="checkbox_label flexWrap widthFreeExpand">
19801980 <input id="openai_image_inlining" type="checkbox" />
19811981 <span data-i18n="Send inline images">Send inline images</span>
public/scripts/openai.js+79 -20
@@ -4166,6 +4166,80 @@ function getMaxContextWindowAI(value) {
41664166}
41674167
41684168/**
4169+ * Get the maximum context size for the Mistral model
4170+ * @param {string} model Model identifier
4171+ * @param {boolean} isUnlocked Whether context limits are unlocked
4172+ * @returns {number} Maximum context size in tokens
4173+ */
4174+function getMistralMaxContext(model, isUnlocked) {
4175+ if (isUnlocked) {
4176+ return unlocked_max;
4177+ }
4178+
4179+ if (Array.isArray(model_list) && model_list.length > 0) {
4180+ const contextLength = model_list.find((record) => record.id === model)?.max_context_length;
4181+ if (contextLength) {
4182+ return contextLength;
4183+ }
4184+ }
4185+
4186+ const contextMap = {
4187+ 'codestral-2411-rc5': 262144,
4188+ 'codestral-2412': 262144,
4189+ 'codestral-2501': 262144,
4190+ 'codestral-latest': 262144,
4191+ 'codestral-mamba-2407': 262144,
4192+ 'codestral-mamba-latest': 262144,
4193+ 'open-codestral-mamba': 262144,
4194+ 'ministral-3b-2410': 131072,
4195+ 'ministral-3b-latest': 131072,
4196+ 'ministral-8b-2410': 131072,
4197+ 'ministral-8b-latest': 131072,
4198+ 'mistral-large-2407': 131072,
4199+ 'mistral-large-2411': 131072,
4200+ 'mistral-large-latest': 131072,
4201+ 'mistral-large-pixtral-2411': 131072,
4202+ 'mistral-tiny-2407': 131072,
4203+ 'mistral-tiny-latest': 131072,
4204+ 'open-mistral-nemo': 131072,
4205+ 'open-mistral-nemo-2407': 131072,
4206+ 'pixtral-12b': 131072,
4207+ 'pixtral-12b-2409': 131072,
4208+ 'pixtral-12b-latest': 131072,
4209+ 'pixtral-large-2411': 131072,
4210+ 'pixtral-large-latest': 131072,
4211+ 'open-mixtral-8x22b': 65536,
4212+ 'open-mixtral-8x22b-2404': 65536,
4213+ 'codestral-2405': 32768,
4214+ 'mistral-embed': 32768,
4215+ 'mistral-large-2402': 32768,
4216+ 'mistral-medium': 32768,
4217+ 'mistral-medium-2312': 32768,
4218+ 'mistral-medium-latest': 32768,
4219+ 'mistral-moderation-2411': 32768,
4220+ 'mistral-moderation-latest': 32768,
4221+ 'mistral-ocr-2503': 32768,
4222+ 'mistral-ocr-latest': 32768,
4223+ 'mistral-saba-2502': 32768,
4224+ 'mistral-saba-latest': 32768,
4225+ 'mistral-small': 32768,
4226+ 'mistral-small-2312': 32768,
4227+ 'mistral-small-2402': 32768,
4228+ 'mistral-small-2409': 32768,
4229+ 'mistral-small-2501': 32768,
4230+ 'mistral-small-2503': 32768,
4231+ 'mistral-small-latest': 32768,
4232+ 'mistral-tiny': 32768,
4233+ 'mistral-tiny-2312': 32768,
4234+ 'open-mistral-7b': 32768,
4235+ 'open-mixtral-8x7b': 32768,
4236+ };
4237+
4238+ // Return context size if model found, otherwise default to 32k
4239+ return Object.entries(contextMap).find(([key]) => model.includes(key))?.[1] || 32768;
4240+}
4241+
4242+/**
41694243 * Get the maximum context size for the Groq model
41704244 * @param {string} model Model identifier
41714245 * @param {boolean} isUnlocked Whether context limits are unlocked
@@ -4428,27 +4502,10 @@ async function onModelChange() {
44284502 }
44294503
44304504 if (oai_settings.chat_completion_source === chat_completion_sources.MISTRALAI) {
4431- if (oai_settings.max_context_unlocked) {
4505+ const maxContext = getMistralMaxContext(oai_settings.mistralai_model, oai_settings.max_context_unlocked);
44324506 $('#openai_max_context').attr('max', unlocked_maxmaxContext);
4433- } else if (['codestral-latest', 'codestral-mamba-2407', 'codestral-2411-rc5', 'codestral-2412', 'codestral-2501'].includes(oai_settings.mistralai_model)) {
4434- $('#openai_max_context').attr('max', max_256k);
4435- } else if (['mistral-large-2407', 'mistral-large-2411', 'mistral-large-pixtral-2411', 'mistral-large-latest'].includes(oai_settings.mistralai_model)) {
4436- $('#openai_max_context').attr('max', max_128k);
4437- } else if (oai_settings.mistralai_model.includes('mistral-nemo')) {
4438- $('#openai_max_context').attr('max', max_128k);
4439- } else if (oai_settings.mistralai_model.includes('mixtral-8x22b')) {
4440- $('#openai_max_context').attr('max', max_64k);
4441- } else if (oai_settings.mistralai_model.includes('pixtral')) {
4442- $('#openai_max_context').attr('max', max_128k);
4443- } else if (oai_settings.mistralai_model.includes('ministral')) {
4444- $('#openai_max_context').attr('max', max_32k);
4445- } else {
4446- $('#openai_max_context').attr('max', max_32k);
4447- }
44484507 oai_settings.openai_max_context = Math.min(oai_settings.openai_max_context, Number($('#openai_max_context').attr('max')));
44494508 $('#openai_max_context').val(oai_settings.openai_max_context).trigger('input');
4450-
4451- //mistral also caps temp at 1.0
44524509 oai_settings.temp_openai = Math.min(claude_max_temp, oai_settings.temp_openai);
44534510 $('#temp_openai').attr('max', claude_max_temp).val(oai_settings.temp_openai).trigger('input');
44544511 }
@@ -5006,7 +5063,9 @@ export function isImageInliningSupported() {
50065063 'o1-2024-12-17',
50075064 'chatgpt-4o-latest',
50085065 'yi-vision',
50095066 'mistral-large-pixtral-latest2411',
5067+ 'mistral-small-2503',
5068+ 'mistral-small-latest',
50105069 'pixtral-12b-latest',
50115070 'pixtral-12b',
50125071 'pixtral-12b-2409',