From 747a7824c09464e96e9b57ff875b110f1f95e717 Mon Sep 17 00:00:00 2001 From: Cohee <18619528+Cohee1207@users.noreply.github.com> Date: Thu, 11 Jan 2024 20:27:59 +0200 Subject: [PATCH] OpenRouter model dropdown facelift --- public/css/select2-overrides.css | 14 +++++++++++ public/scripts/openai.js | 42 +++++++++++++++++++++++++------- 2 files changed, 47 insertions(+), 9 deletions(-) diff --git a/public/css/select2-overrides.css b/public/css/select2-overrides.css index f3cc9356a..cdab229d8 100644 --- a/public/css/select2-overrides.css +++ b/public/css/select2-overrides.css @@ -107,6 +107,12 @@ position: relative; } +.select2-results .select2-results__option--group { + color: var(--SmartThemeBodyColor); + background-color: var(--SmartThemeBlurTintColor); + position: relative; +} + /* Customize the hovered option list item */ .select2-results .select2-results__option--highlighted.select2-results__option--selectable { color: var(--SmartThemeBodyColor); @@ -114,12 +120,20 @@ opacity: 1; } +.select2-results__option.select2-results__option--group::before { + display: none; +} + /* Customize the option list item */ .select2-results__option { padding-left: 30px; /* Add some padding to make room for the checkbox */ } +.select2-results .select2-results__option--group .select2-results__options--nested .select2-results__option { + padding-left: 2em; +} + /* Add the custom checkbox */ .select2-results__option::before { content: ''; diff --git a/public/scripts/openai.js b/public/scripts/openai.js index 6d354ef17..8ac693cb9 100644 --- a/public/scripts/openai.js +++ b/public/scripts/openai.js @@ -62,6 +62,7 @@ import { formatInstructModePrompt, formatInstructModeSystemPrompt, } from './instruct-mode.js'; +import { isMobile } from './RossAscends-mods.js'; export { openai_messages_count, @@ -1298,6 +1299,25 @@ function getChatCompletionModel() { } } +function getOpenRouterModelTemplate(option){ + const model = model_list.find(x => x.id === option?.element?.value); + + if (!option.id || !model) { + return option.text; + } + + let tokens_dollar = Number(1 / (1000 * model.pricing?.prompt)); + let tokens_rounded = (Math.round(tokens_dollar * 1000) / 1000).toFixed(0); + + const price = 0 === Number(model.pricing?.prompt) ? 'Free' : `${tokens_rounded}k t/$ `; + + return $((` +