NanoGPT: Pull max context and vision capability from endpoint

5eea41d315eb1e53729c3db2383f7824ed6ce105

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

3 files changed, +40 -13Showing whitespace changes
public/index.html+1 -1
@@ -1999,7 +1999,7 @@
19991999 <strong data-i18n="enable_functions_desc_4">Not supported when Prompt Post-Processing with "no tools" is used!</strong>
20002000 </div>
20012001 </div>
20022002 <div class="range-block" data-source="openai,aimlapi,openrouter,mistralai,makersuite,vertexai,claude,custom,xai,pollinations,moonshot,cohere,cometapi,nanogpt">
20032003 <label for="openai_image_inlining" class="checkbox_label flexWrap widthFreeExpand">
20042004 <input id="openai_image_inlining" type="checkbox" />
20052005 <span data-i18n="Send inline images">Send inline images</span>
public/scripts/openai.js+26 -6
@@ -4570,6 +4570,27 @@ function getFireworksMaxContext(model, isUnlocked) {
45704570 return max_32k;
45714571}
45724572
4573+/**
4574+ * Get the maximum context size for the NanoGPT model
4575+ * @param {string} model Model identifier
4576+ * @param {boolean} isUnlocked Whether context limits are unlocked
4577+ * @returns {number} Maximum context size in tokens
4578+ */
4579+function getNanoGptMaxContext(model, isUnlocked) {
4580+ if (isUnlocked) {
4581+ return unlocked_max;
4582+ }
4583+
4584+ if (Array.isArray(model_list)) {
4585+ const modelInfo = model_list.find(m => m.id === model);
4586+ if (modelInfo?.context_length) {
4587+ return modelInfo.context_length;
4588+ }
4589+ }
4590+
4591+ return max_128k;
4592+}
4593+
45734594async function onModelChange() {
45744595 biasCache = undefined;
45754596 let value = String($(this).val() || '');
@@ -4900,14 +4921,11 @@ async function onModelChange() {
49004921 }
49014922
49024923 if (oai_settings.chat_completion_source === chat_completion_sources.NANOGPT) {
4903- if (oai_settings.max_context_unlocked) {
4924+ const maxContext = getNanoGptMaxContext(oai_settings.nanogpt_model, oai_settings.max_context_unlocked);
49044925 $('#openai_max_context').attr('max', unlocked_maxmaxContext);
4905- } else {
4906- $('#openai_max_context').attr('max', max_128k);
4907- }
4908-
49094926 oai_settings.openai_max_context = Math.min(Number($('#openai_max_context').attr('max')), oai_settings.openai_max_context);
49104927 $('#openai_max_context').val(oai_settings.openai_max_context).trigger('input');
4928+ oai_settings.temp_openai = Math.min(oai_max_temp, oai_settings.temp_openai);
49114929 $('#temp_openai').attr('max', oai_max_temp).val(oai_settings.temp_openai).trigger('input');
49124930 }
49134931
@@ -5504,6 +5522,8 @@ export function isImageInliningSupported() {
55045522 return true;
55055523 case chat_completion_sources.MOONSHOT:
55065524 return visionSupportedModels.some(model => oai_settings.moonshot_model.includes(model));
5525+ case chat_completion_sources.NANOGPT:
5526+ return (Array.isArray(model_list) && model_list.find(m => m.id === oai_settings.nanogpt_model)?.capabilities?.vision);
55075527 default:
55085528 return false;
55095529 }
src/endpoints/backends/chat-completions.js+13 -6
@@ -2,6 +2,7 @@ import process from 'node:process';
22import util from 'node:util';
33import express from 'express';
44import fetch from 'node-fetch';
5+import urlJoin from 'url-join';
56
67import {
78 AIMLAPI_HEADERS,
@@ -1197,9 +1198,10 @@ export const router = express.Router();
11971198router.post('/status', async function (request, statusResponse) {
11981199 if (!request.body) return statusResponse.sendStatus(400);
11991200
12001201 let apiUrl = '';
12011202 let apiKey = '';
12021203 let headers = {};
1204+ let queryParams = {};
12031205
12041206 if (request.body.chat_completion_source === CHAT_COMPLETION_SOURCES.OPENAI) {
12051207 apiUrl = new URL(request.body.reverse_proxy || API_OPENAI).toString();
@@ -1227,12 +1229,13 @@ router.post('/status', async function (request, statusResponse) {
12271229 apiUrl = API_NANOGPT;
12281230 apiKey = readSecret(request.user.directories, SECRET_KEYS.NANOGPT);
12291231 headers = {};
1232+ queryParams = { detailed: true };
12301233 } else if (request.body.chat_completion_source === CHAT_COMPLETION_SOURCES.DEEPSEEK) {
12311234 apiUrl = new URL(request.body.reverse_proxy || API_DEEPSEEK.replace('/beta', '')).toString();
12321235 apiKey = request.body.reverse_proxy ? request.body.proxy_password : readSecret(request.user.directories, SECRET_KEYS.DEEPSEEK);
12331236 headers = {};
12341237 } else if (request.body.chat_completion_source === CHAT_COMPLETION_SOURCES.XAI) {
12351238 apiUrl = new URL(request.body.reverse_proxy || API_XAI).toString();
12361239 apiKey = request.body.reverse_proxy ? request.body.proxy_password : readSecret(request.user.directories, SECRET_KEYS.XAI);
12371240 headers = {};
12381241 } else if (request.body.chat_completion_source === CHAT_COMPLETION_SOURCES.AIMLAPI) {
@@ -1307,7 +1310,11 @@ router.post('/status', async function (request, statusResponse) {
13071310 }
13081311
13091312 try {
13101313 const responsemodelsUrl = awaitnew fetchURL(urlJoin(apiUrl +, '/models', {));
1314+ Object.keys(queryParams).forEach(key => {
1315+ modelsUrl.searchParams.append(key, queryParams[key]);
1316+ });
1317+ const response = await fetch(modelsUrl, {
13111318 method: 'GET',
13121319 headers: {
13131320 'Authorization': 'Bearer ' + apiKey,