Add NanoGPT as chat completions provider

0882fb2d15d18ded7dd4021ac8870232f6426983

dylan <dylanbradshaw107@hotmail.com>

5 files changed, +106 -0Showing whitespace changes
public/index.html+71 -0
@@ -2602,6 +2602,7 @@
2602 <option value="groq">Groq</option>2602 <option value="groq">Groq</option>
2603 <option value="makersuite">Google AI Studio</option>2603 <option value="makersuite">Google AI Studio</option>
2604 <option value="mistralai">MistralAI</option>2604 <option value="mistralai">MistralAI</option>
2605 <option value="nanogpt">NanoGPT</option>
2605 <option value="openrouter">OpenRouter</option>2606 <option value="openrouter">OpenRouter</option>
2606 <option value="perplexity">Perplexity</option>2607 <option value="perplexity">Perplexity</option>
2607 <option value="scale">Scale</option>2608 <option value="scale">Scale</option>
@@ -3084,6 +3085,76 @@
3084 </optgroup>3085 </optgroup>
3085 </select>3086 </select>
3086 </div>3087 </div>
3088 <div id="nanogpt_form" data-source="nanogpt">
3089 <h4 data-i18n="NanoGPT API Key">NanoGPT API Key</h4>
3090 <div class="flex-container">
3091 <input id="api_key_nanogpt" name="api_key_nanogpt" class="text_pole flex1" value="" type="text" autocomplete="off">
3092 <div title="Clear your API key" data-i18n="[title]Clear your API key" class="menu_button fa-solid fa-circle-xmark clear-api-key" data-key="api_key_nanogpt"></div>
3093 </div>
3094 <div data-for="api_key_nanogpt" class="neutral_warning" data-i18n="For privacy reasons, your API key will be hidden after you reload the page.">
3095 For privacy reasons, your API key will be hidden after you reload the page.
3096 </div>
3097 <h4 data-i18n="NanoGPT Model">NanoGPT Model</h4>
3098 <select id="model_nanogpt_select">
3099 <option value="chatgpt-4o-latest">ChatGPT 4o</option>
3100 <option value="o1-preview">OpenAI o1</option>
3101 <option value="o1-mini">OpenAI o1-mini</option>
3102 <option value="claude-3-5-sonnet-20241022">Claude 3.5 Sonnet</option>
3103 <option value="claude-3-5-sonnet-20240620">Claude 3.5 Sonnet Old</option>
3104 <option value="google/gemini-pro-1.5">Gemini 1.5 Pro</option>
3105 <option value="google/gemini-pro-1.5-exp">Gemini 1.5 Pro Exp</option>
3106 <option value="Meta-Llama-3-1-405B-Instruct-FP8">Llama 3.1 Large</option>
3107 <option value="nvidia/llama-3.1-nemotron-70b-instruct">Nvidia Nemotron</option>
3108 <option value="nousresearch/hermes-3-llama-3.1-405b">Hermes 3 Large</option>
3109 <option value="meta-llama/llama-3.2-90b-vision-instruct">Llama 3.2 Medium</option>
3110 <option value="x-ai/grok-beta">Grok 2</option>
3111 <option value="neversleep/llama-3.1-lumimaid-70b">Lumimaid v0.2</option>
3112 <option value="inflection/inflection-3-pi">Inflection 3 Pi</option>
3113 <option value="inflection/inflection-3-productivity">Inflection 3 Productivity</option>
3114 <option value="microsoft/wizardlm-2-8x22b">WizardLM-2 8x22B</option>
3115 <option value="accounts/fireworks/models/llama-v3p1-405b-instruct">Llama 3.1 Large</option>
3116 <option value="gpt-4o-2024-08-06">GPT 4o</option>
3117 <option value="accounts/fireworks/models/llama-v3p1-70b-instruct">Llama 3.1 Medium</option>
3118 <option value="llama-3.1-70b-instruct">Llama 3.1 Medium</option>
3119 <option value="llama-3.1-sonar-huge-128k-online">Perplexity Online</option>
3120 <option value="gpt-4o-mini">GPT 4o mini</option>
3121 <option value="meta-llama/llama-3.1-405b-instruct">Llama 3.1 Large</option>
3122 <option value="claude-3-opus-20240229">Claude 3 Opus</option>
3123 <option value="google/gemini-flash-1.5-exp">Gemini 1.5 Flash</option>
3124 <option value="google/gemini-flash-1.5">Gemini 1.5 Flash</option>
3125 <option value="llama-3.1-sonar-large-128k-online">Perplexity Online Medium</option>
3126 <option value="nousresearch/hermes-3-llama-3.1-405b:extended">Hermes 3 Large</option>
3127 <option value="gryphe/mythomax-l2-13b">MythoMax 13B</option>
3128 <option value="deepseek/deepseek-chat">DeepSeek V2.5</option>
3129 <option value="qwen/qwen-2.5-72b-instruct">Qwen2.5 72B</option>
3130 <option value="eva-unit-01/eva-qwen-2.5-14b">EVA Qwen2.5 14B</option>
3131 <option value="cognitivecomputations/dolphin-mixtral-8x7b">Dolphin 2.6 Mixtral 8x7b</option>
3132 <option value="gpt-4-turbo-preview">GPT 4 Turbo</option>
3133 <option value="gpt-4o">GPT 4o</option>
3134 <option value="gpt-3.5-turbo">GPT 3.5 Turbo</option>
3135 <option value="gemini-1.5-flash-001">Gemini 1.5 Flash</option>
3136 <option value="gemini-1.5-pro-001">Gemini 1.5 Pro</option>
3137 <option value="free-model">Playground</option>
3138 <option value="anthracite-org/magnum-v4-72b">Magnum v4 72B</option>
3139 <option value="thedrummer/rocinante-12b">Rocinante 12B</option>
3140 <option value="cognitivecomputations/dolphin-mixtral-8x22b">Dolphin 2.9.2 Mixtral 8x22B</option>
3141 <option value="meta-llama/llama-3.1-70b-instruct">Llama 3.1 70b Instruct</option>
3142 <option value="meta-llama/llama-3.1-8b-instruct">Llama 3.1 8b Instruct</option>
3143 <option value="sao10k/l3-euryale-70b">L3 Euryale 70B</option>
3144 <option value="mistralai/mistral-tiny">Mistral Tiny</option>
3145 <option value="mistralai/mistral-7b-instruct">Mistral 7B Instruct</option>
3146 <option value="meta-llama/llama-3-70b-instruct">Llama 3 70b Instruct</option>
3147 <option value="microsoft/wizardlm-2-7b">WizardLM-2 7B</option>
3148 <option value="cohere/command-r">Cohere: Command R</option>
3149 <option value="nousresearch/hermes-3-llama-3.1-70b">Nous Hermes 3 70B Instruct</option>
3150 <option value="mistralai/mistral-nemo">Mistral Nemo</option>
3151 <option value="meta-llama/llama-3.2-3b-instruct">Llama 3.2 3b Instruct</option>
3152 <option value="neversleep/llama-3-lumimaid-70b">Llama 3 Lumimaid 70B</option>
3153 <option value="anthracite-org/magnum-v2-72b">Magnum v2 72B</option>
3154 <option value="Meta-Llama-3-1-8B-Instruct-FP8">Llama 3.1 8B (decentralized)</option>
3155 </select>
3156
3157 </div>
3087 <div id="perplexity_form" data-source="perplexity">3158 <div id="perplexity_form" data-source="perplexity">
3088 <h4 data-i18n="Perplexity API Key">Perplexity API Key</h4>3159 <h4 data-i18n="Perplexity API Key">Perplexity API Key</h4>
3089 <div class="flex-container">3160 <div class="flex-container">
public/scripts/openai.js+31 -0
@@ -181,6 +181,7 @@ export const chat_completion_sources = {
181 GROQ: 'groq',181 GROQ: 'groq',
182 ZEROONEAI: '01ai',182 ZEROONEAI: '01ai',
183 BLOCKENTROPY: 'blockentropy',183 BLOCKENTROPY: 'blockentropy',
184 NANOGPT: 'nanogpt',
184};185};
185186
186const character_names_behavior = {187const character_names_behavior = {
@@ -250,6 +251,7 @@ const default_settings = {
250 cohere_model: 'command-r-plus',251 cohere_model: 'command-r-plus',
251 perplexity_model: 'llama-3.1-70b-instruct',252 perplexity_model: 'llama-3.1-70b-instruct',
252 groq_model: 'llama-3.1-70b-versatile',253 groq_model: 'llama-3.1-70b-versatile',
254 nanogpt_model: 'gpt-4o-mini',
253 zerooneai_model: 'yi-large',255 zerooneai_model: 'yi-large',
254 blockentropy_model: 'be-70b-base-llama3.1',256 blockentropy_model: 'be-70b-base-llama3.1',
255 custom_model: '',257 custom_model: '',
@@ -326,6 +328,7 @@ const oai_settings = {
326 cohere_model: 'command-r-plus',328 cohere_model: 'command-r-plus',
327 perplexity_model: 'llama-3.1-70b-instruct',329 perplexity_model: 'llama-3.1-70b-instruct',
328 groq_model: 'llama-3.1-70b-versatile',330 groq_model: 'llama-3.1-70b-versatile',
331 nanogpt_model: 'gpt-4o-mini',
329 zerooneai_model: 'yi-large',332 zerooneai_model: 'yi-large',
330 blockentropy_model: 'be-70b-base-llama3.1',333 blockentropy_model: 'be-70b-base-llama3.1',
331 custom_model: '',334 custom_model: '',
@@ -1479,6 +1482,8 @@ function getChatCompletionModel() {
1479 return oai_settings.zerooneai_model;1482 return oai_settings.zerooneai_model;
1480 case chat_completion_sources.BLOCKENTROPY:1483 case chat_completion_sources.BLOCKENTROPY:
1481 return oai_settings.blockentropy_model;1484 return oai_settings.blockentropy_model;
1485 case chat_completion_sources.NANOGPT:
1486 return oai_settings.nanogpt_model;
1482 default:1487 default:
1483 throw new Error(`Unknown chat completion source: ${oai_settings.chat_completion_source}`);1488 throw new Error(`Unknown chat completion source: ${oai_settings.chat_completion_source}`);
1484 }1489 }
@@ -2960,6 +2965,7 @@ function loadOpenAISettings(data, settings) {
2960 oai_settings.cohere_model = settings.cohere_model ?? default_settings.cohere_model;2965 oai_settings.cohere_model = settings.cohere_model ?? default_settings.cohere_model;
2961 oai_settings.perplexity_model = settings.perplexity_model ?? default_settings.perplexity_model;2966 oai_settings.perplexity_model = settings.perplexity_model ?? default_settings.perplexity_model;
2962 oai_settings.groq_model = settings.groq_model ?? default_settings.groq_model;2967 oai_settings.groq_model = settings.groq_model ?? default_settings.groq_model;
2968 oai_settings.nanogpt_model = settings.nanogpt_model ?? default_settings.nanogpt_model;
2963 oai_settings.blockentropy_model = settings.blockentropy_model ?? default_settings.blockentropy_model;2969 oai_settings.blockentropy_model = settings.blockentropy_model ?? default_settings.blockentropy_model;
2964 oai_settings.zerooneai_model = settings.zerooneai_model ?? default_settings.zerooneai_model;2970 oai_settings.zerooneai_model = settings.zerooneai_model ?? default_settings.zerooneai_model;
2965 oai_settings.custom_model = settings.custom_model ?? default_settings.custom_model;2971 oai_settings.custom_model = settings.custom_model ?? default_settings.custom_model;
@@ -3040,6 +3046,8 @@ function loadOpenAISettings(data, settings) {
3040 $(`#model_perplexity_select option[value="${oai_settings.perplexity_model}"`).attr('selected', true);3046 $(`#model_perplexity_select option[value="${oai_settings.perplexity_model}"`).attr('selected', true);
3041 $('#model_groq_select').val(oai_settings.groq_model);3047 $('#model_groq_select').val(oai_settings.groq_model);
3042 $(`#model_groq_select option[value="${oai_settings.groq_model}"`).attr('selected', true);3048 $(`#model_groq_select option[value="${oai_settings.groq_model}"`).attr('selected', true);
3049 $('#model_nanogpt_select').val(oai_settings.nanogpt_model);
3050 $(`#model_nanogpt_select option[value="${oai_settings.nanogpt_model}"`).attr('selected', true);
3043 $('#model_01ai_select').val(oai_settings.zerooneai_model);3051 $('#model_01ai_select').val(oai_settings.zerooneai_model);
3044 $('#model_blockentropy_select').val(oai_settings.blockentropy_model);3052 $('#model_blockentropy_select').val(oai_settings.blockentropy_model);
3045 $('#custom_model_id').val(oai_settings.custom_model);3053 $('#custom_model_id').val(oai_settings.custom_model);
@@ -3734,6 +3742,7 @@ function onSettingsPresetChange() {
3734 cohere_model: ['#model_cohere_select', 'cohere_model', false],3742 cohere_model: ['#model_cohere_select', 'cohere_model', false],
3735 perplexity_model: ['#model_perplexity_select', 'perplexity_model', false],3743 perplexity_model: ['#model_perplexity_select', 'perplexity_model', false],
3736 groq_model: ['#model_groq_select', 'groq_model', false],3744 groq_model: ['#model_groq_select', 'groq_model', false],
3745 nanogpt_model: ['#model_nanogpt_select', 'nanogpt_model', false],
3737 zerooneai_model: ['#model_01ai_select', 'zerooneai_model', false],3746 zerooneai_model: ['#model_01ai_select', 'zerooneai_model', false],
3738 blockentropy_model: ['#model_blockentropy_select', 'blockentropy_model', false],3747 blockentropy_model: ['#model_blockentropy_select', 'blockentropy_model', false],
3739 custom_model: ['#custom_model_id', 'custom_model', false],3748 custom_model: ['#custom_model_id', 'custom_model', false],
@@ -3983,6 +3992,11 @@ async function onModelChange() {
3983 oai_settings.groq_model = value;3992 oai_settings.groq_model = value;
3984 }3993 }
39853994
3995 if ($(this).is('#model_nanogpt_select')) {
3996 console.log('NanoGPT model changed to', value);
3997 oai_settings.nanogpt_model = value;
3998 }
3999
3986 if (value && $(this).is('#model_01ai_select')) {4000 if (value && $(this).is('#model_01ai_select')) {
3987 console.log('01.AI model changed to', value);4001 console.log('01.AI model changed to', value);
3988 oai_settings.zerooneai_model = value;4002 oai_settings.zerooneai_model = value;
@@ -4497,6 +4511,19 @@ async function onConnectButtonClick(e) {
4497 }4511 }
4498 }4512 }
44994513
4514 if (oai_settings.chat_completion_source == chat_completion_sources.NANOGPT) {
4515 const api_key_nanogpt = String($('#api_key_nanogpt').val()).trim();
4516
4517 if (api_key_nanogpt.length) {
4518 await writeSecret(SECRET_KEYS.NANOGPT, api_key_nanogpt);
4519 }
4520
4521 if (!secret_state[SECRET_KEYS.NANOGPT]) {
4522 console.log('No secret key saved for NanoGPT');
4523 return;
4524 }
4525 }
4526
4500 if (oai_settings.chat_completion_source == chat_completion_sources.ZEROONEAI) {4527 if (oai_settings.chat_completion_source == chat_completion_sources.ZEROONEAI) {
4501 const api_key_01ai = String($('#api_key_01ai').val()).trim();4528 const api_key_01ai = String($('#api_key_01ai').val()).trim();
45024529
@@ -4566,6 +4593,9 @@ function toggleChatCompletionForms() {
4566 else if (oai_settings.chat_completion_source == chat_completion_sources.GROQ) {4593 else if (oai_settings.chat_completion_source == chat_completion_sources.GROQ) {
4567 $('#model_groq_select').trigger('change');4594 $('#model_groq_select').trigger('change');
4568 }4595 }
4596 else if (oai_settings.chat_completion_source == chat_completion_sources.NANOGPT) {
4597 $('#model_nanogpt_select').trigger('change');
4598 }
4569 else if (oai_settings.chat_completion_source == chat_completion_sources.ZEROONEAI) {4599 else if (oai_settings.chat_completion_source == chat_completion_sources.ZEROONEAI) {
4570 $('#model_01ai_select').trigger('change');4600 $('#model_01ai_select').trigger('change');
4571 }4601 }
@@ -5287,6 +5317,7 @@ export function initOpenAI() {
5287 $('#model_cohere_select').on('change', onModelChange);5317 $('#model_cohere_select').on('change', onModelChange);
5288 $('#model_perplexity_select').on('change', onModelChange);5318 $('#model_perplexity_select').on('change', onModelChange);
5289 $('#model_groq_select').on('change', onModelChange);5319 $('#model_groq_select').on('change', onModelChange);
5320 $('#model_nanogpt_select').on('change', onModelChange);
5290 $('#model_01ai_select').on('change', onModelChange);5321 $('#model_01ai_select').on('change', onModelChange);
5291 $('#model_blockentropy_select').on('change', onModelChange);5322 $('#model_blockentropy_select').on('change', onModelChange);
5292 $('#model_custom_select').on('change', onModelChange);5323 $('#model_custom_select').on('change', onModelChange);
public/scripts/secrets.js+2 -0
@@ -34,6 +34,7 @@ export const SECRET_KEYS = {
34 STABILITY: 'api_key_stability',34 STABILITY: 'api_key_stability',
35 BLOCKENTROPY: 'api_key_blockentropy',35 BLOCKENTROPY: 'api_key_blockentropy',
36 CUSTOM_OPENAI_TTS: 'api_key_custom_openai_tts',36 CUSTOM_OPENAI_TTS: 'api_key_custom_openai_tts',
37 NANOGPT: 'api_key_nanogpt',
37 TAVILY: 'api_key_tavily',38 TAVILY: 'api_key_tavily',
38};39};
3940
@@ -67,6 +68,7 @@ const INPUT_MAP = {
67 [SECRET_KEYS.ZEROONEAI]: '#api_key_01ai',68 [SECRET_KEYS.ZEROONEAI]: '#api_key_01ai',
68 [SECRET_KEYS.HUGGINGFACE]: '#api_key_huggingface',69 [SECRET_KEYS.HUGGINGFACE]: '#api_key_huggingface',
69 [SECRET_KEYS.BLOCKENTROPY]: '#api_key_blockentropy',70 [SECRET_KEYS.BLOCKENTROPY]: '#api_key_blockentropy',
71 [SECRET_KEYS.NANOGPT]: '#api_key_nanogpt',
70};72};
7173
72async function clearSecret() {74async function clearSecret() {
public/scripts/slash-commands.js+1 -0
@@ -3632,6 +3632,7 @@ function getModelOptions(quiet) {
3632 { id: 'model_cohere_select', api: 'openai', type: chat_completion_sources.COHERE },3632 { id: 'model_cohere_select', api: 'openai', type: chat_completion_sources.COHERE },
3633 { id: 'model_perplexity_select', api: 'openai', type: chat_completion_sources.PERPLEXITY },3633 { id: 'model_perplexity_select', api: 'openai', type: chat_completion_sources.PERPLEXITY },
3634 { id: 'model_groq_select', api: 'openai', type: chat_completion_sources.GROQ },3634 { id: 'model_groq_select', api: 'openai', type: chat_completion_sources.GROQ },
3635 { id: 'model_nanogpt_select', api: 'openai', type: chat_completion_sources.NANOGPT },
3635 { id: 'model_01ai_select', api: 'openai', type: chat_completion_sources.ZEROONEAI },3636 { id: 'model_01ai_select', api: 'openai', type: chat_completion_sources.ZEROONEAI },
3636 { id: 'model_blockentropy_select', api: 'openai', type: chat_completion_sources.BLOCKENTROPY },3637 { id: 'model_blockentropy_select', api: 'openai', type: chat_completion_sources.BLOCKENTROPY },
3637 { id: 'model_novel_select', api: 'novel', type: null },3638 { id: 'model_novel_select', api: 'novel', type: null },
src/constants.js+1 -0
@@ -200,6 +200,7 @@ export const CHAT_COMPLETION_SOURCES = {
200 GROQ: 'groq',200 GROQ: 'groq',
201 ZEROONEAI: '01ai',201 ZEROONEAI: '01ai',
202 BLOCKENTROPY: 'blockentropy',202 BLOCKENTROPY: 'blockentropy',
203 NANOGPT: 'nanogpt',
203};204};
204205
205/**206/**