Groq: Pull models list from endpoint

86bac00a812fb3e2b822f74dfc39e20ddd61da49

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

3 files changed, +37 -20Showing whitespace changes
public/index.html+1 -19
@@ -3468,35 +3468,17 @@
34683468 </div>
34693469 <h4 data-i18n="Groq Model">Groq Model</h4>
34703470 <select id="model_groq_select">
3471- <optgroup label="Alibaba Cloud">
3471+ <option value="qwen/qwen3-32b">qwen/qwen3-32b</option>
3472- <option value="qwen-2.5-32b">qwen-2.5-32b</option>
3473- <option value="qwen-2.5-coder-32b">qwen-2.5-coder-32b</option>
3474- </optgroup>
3475- <optgroup label="DeepSeek">
3476- <option value="deepseek-r1-distill-qwen-32b">deepseek-r1-distill-qwen-32b</option>
34773472 <option value="deepseek-r1-distill-llama-70b">deepseek-r1-distill-llama-70b</option>
3478- </optgroup>
3479- <optgroup label="Google">
34803473 <option value="gemma2-9b-it">gemma2-9b-it</option>
3481- </optgroup>
3482- <optgroup label="Meta">
34833474 <option value="meta-llama/llama-4-scout-17b-16e-instruct">meta-llama/llama-4-scout-17b-16e-instruct</option>
34843475 <option value="meta-llama/llama-4-maverick-17b-128e-instruct">meta-llama/llama-4-maverick-17b-128e-instruct</option>
34853476 <option value="llama-3.1-8b-instant">llama-3.1-8b-instant</option>
3486- <option value="llama-3.2-11b-vision-preview">llama-3.2-11b-vision-preview </option>
3487- <option value="llama-3.2-1b-preview">llama-3.2-1b-preview </option>
3488- <option value="llama-3.2-3b-preview">llama-3.2-3b-preview </option>
3489- <option value="llama-3.2-90b-vision-preview">llama-3.2-90b-vision-preview </option>
3490- <option value="llama-3.3-70b-specdec">llama-3.3-70b-specdec</option>
34913477 <option value="llama-3.3-70b-versatile">llama-3.3-70b-versatile </option>
34923478 <option value="llama-guard-3-8b">llama-guard-3-8b</option>
34933479 <option value="llama3-70b-8192">llama3-70b-8192</option>
34943480 <option value="llama3-8b-8192">llama3-8b-8192</option>
3495- </optgroup>
3496- <optgroup label="Mistral AI">
34973481 <option value="mistral-saba-24b">mistral-saba-24b</option>
3498- <option value="mixtral-8x7b-32768">mixtral-8x7b-32768</option>
3499- </optgroup>
35003482 </select>
35013483 </div>
35023484 <div id="nanogpt_form" data-source="nanogpt">
public/scripts/openai.js+32 -1
@@ -1978,6 +1978,24 @@ function saveModelList(data) {
19781978
19791979 $('#model_google_select').val(oai_settings.google_model).trigger('change');
19801980 }
1981+
1982+ if (oai_settings.chat_completion_source === chat_completion_sources.GROQ) {
1983+ $('#model_groq_select').empty();
1984+ model_list.forEach((model) => {
1985+ $('#model_groq_select').append(
1986+ $('<option>', {
1987+ value: model.id,
1988+ text: model.id,
1989+ }));
1990+ });
1991+
1992+ const selectedModel = model_list.find(model => model.id === oai_settings.groq_model);
1993+ if (model_list.length > 0 && (!selectedModel || !oai_settings.groq_model)) {
1994+ oai_settings.groq_model = model_list[0].id;
1995+ }
1996+
1997+ $('#model_groq_select').val(oai_settings.groq_model).trigger('change');
1998+ }
19811999}
19822000
19832001function appendOpenRouterOptions(model_list, groupModels = false, sort = false) {
@@ -3827,7 +3845,6 @@ async function getStatusOpen() {
38273845 chat_completion_sources.AI21,
38283846 chat_completion_sources.VERTEXAI,
38293847 chat_completion_sources.PERPLEXITY,
3830- chat_completion_sources.GROQ,
38313848 ];
38323849 if (noValidateSources.includes(oai_settings.chat_completion_source)) {
38333850 let status = t`Key saved; press \"Test Message\" to verify.`;
@@ -4649,6 +4666,13 @@ function getGroqMaxContext(model, isUnlocked) {
46494666 return unlocked_max;
46504667 }
46514668
4669+ if (Array.isArray(model_list) && model_list.length > 0) {
4670+ const contextLength = model_list.find((record) => record.id === model)?.context_window;
4671+ if (contextLength) {
4672+ return contextLength;
4673+ }
4674+ }
4675+
46524676 const contextMap = {
46534677 'gemma2-9b-it': max_8k,
46544678 'llama-3.3-70b-versatile': max_128k,
@@ -4669,6 +4693,9 @@ function getGroqMaxContext(model, isUnlocked) {
46694693 'mistral-saba-24b': max_32k,
46704694 'meta-llama/llama-4-scout-17b-16e-instruct': max_128k,
46714695 'meta-llama/llama-4-maverick-17b-128e-instruct': max_128k,
4696+ 'compound-beta': max_128k,
4697+ 'compound-beta-mini': max_128k,
4698+ 'qwen/qwen3-32b': max_128k,
46724699 };
46734700
46744701 // Return context size if model found, otherwise default to 128k
@@ -4762,6 +4789,10 @@ async function onModelChange() {
47624789 }
47634790
47644791 if ($(this).is('#model_groq_select')) {
4792+ if (!value) {
4793+ console.debug('Null Groq model selected. Ignoring.');
4794+ return;
4795+ }
47654796 console.log('Groq model changed to', value);
47664797 oai_settings.groq_model = value;
47674798 }
src/endpoints/backends/chat-completions.js+4 -0
@@ -1192,6 +1192,10 @@ router.post('/status', async function (request, statusResponse) {
11921192 apiUrl = 'https://text.pollinations.ai';
11931193 apiKey = 'NONE';
11941194 headers = {};
1195+ } else if (request.body.chat_completion_source === CHAT_COMPLETION_SOURCES.GROQ) {
1196+ apiUrl = API_GROQ;
1197+ apiKey = readSecret(request.user.directories, SECRET_KEYS.GROQ);
1198+ headers = {};
11951199 } else if (request.body.chat_completion_source === CHAT_COMPLETION_SOURCES.MAKERSUITE) {
11961200 apiKey = request.body.reverse_proxy ? request.body.proxy_password : readSecret(request.user.directories, SECRET_KEYS.MAKERSUITE);
11971201 apiUrl = trimTrailingSlash(request.body.reverse_proxy || API_MAKERSUITE);