mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
Add prompt cost for OpenRouter under text completion
This commit is contained in:
@ -266,6 +266,9 @@
|
|||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<div data-tg-type="openrouter">
|
||||||
|
Max prompt cost: <span id="openrouter_max_prompt_cost_tg">Unknown</span>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<hr>
|
<hr>
|
||||||
</div>
|
</div>
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { isMobile } from './RossAscends-mods.js';
|
import { isMobile } from './RossAscends-mods.js';
|
||||||
import { callPopup, getRequestHeaders, setGenerationParamsFromPreset } from '../script.js';
|
import { amount_gen, callPopup, eventSource, event_types, getRequestHeaders, max_context, setGenerationParamsFromPreset } from '../script.js';
|
||||||
import { textgenerationwebui_settings as textgen_settings, textgen_types } from './textgen-settings.js';
|
import { textgenerationwebui_settings as textgen_settings, textgen_types } from './textgen-settings.js';
|
||||||
import { tokenizers } from './tokenizers.js';
|
import { tokenizers } from './tokenizers.js';
|
||||||
|
|
||||||
@ -151,6 +151,9 @@ export async function loadOpenRouterModels(data) {
|
|||||||
option.selected = model.id === textgen_settings.openrouter_model;
|
option.selected = model.id === textgen_settings.openrouter_model;
|
||||||
$('#openrouter_model').append(option);
|
$('#openrouter_model').append(option);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Calculate the cost of the selected model + update on settings change
|
||||||
|
calculateOpenRouterCost();
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function loadAphroditeModels(data) {
|
export async function loadAphroditeModels(data) {
|
||||||
@ -362,6 +365,32 @@ async function downloadOllamaModel() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function calculateOpenRouterCost() {
|
||||||
|
if (textgen_settings.type !== textgen_types.OPENROUTER) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
let cost = 'Unknown';
|
||||||
|
const model = openRouterModels.find(x => x.id === textgen_settings.openrouter_model);
|
||||||
|
|
||||||
|
if (model?.pricing) {
|
||||||
|
const completionCost = Number(model.pricing.completion);
|
||||||
|
const promptCost = Number(model.pricing.prompt);
|
||||||
|
const completionTokens = amount_gen;
|
||||||
|
const promptTokens = (max_context - completionTokens);
|
||||||
|
const totalCost = (completionCost * completionTokens) + (promptCost * promptTokens);
|
||||||
|
if (!isNaN(totalCost)) {
|
||||||
|
cost = '$' + totalCost.toFixed(3);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$('#openrouter_max_prompt_cost_tg').text(cost);
|
||||||
|
|
||||||
|
// Schedule an update when settings change
|
||||||
|
eventSource.removeListener(event_types.SETTINGS_UPDATED, calculateOpenRouterCost);
|
||||||
|
eventSource.once(event_types.SETTINGS_UPDATED, calculateOpenRouterCost);
|
||||||
|
}
|
||||||
|
|
||||||
export function getCurrentOpenRouterModelTokenizer() {
|
export function getCurrentOpenRouterModelTokenizer() {
|
||||||
const modelId = textgen_settings.openrouter_model;
|
const modelId = textgen_settings.openrouter_model;
|
||||||
const model = openRouterModels.find(x => x.id === modelId);
|
const model = openRouterModels.find(x => x.id === modelId);
|
||||||
|
Reference in New Issue
Block a user