${DOMPurify.sanitize(model.name)} | ${model.context_length} ctx | ${price}
`));
}
function calculateOpenRouterCost() {
if (oai_settings.chat_completion_source !== chat_completion_sources.OPENROUTER) {
return;
}
let cost = 'Unknown';
const model = model_list.find(x => x.id === oai_settings.openrouter_model);
if (model?.pricing) {
const completionCost = Number(model.pricing.completion);
const promptCost = Number(model.pricing.prompt);
const completionTokens = oai_settings.openai_max_tokens;
const promptTokens = (oai_settings.openai_max_context - completionTokens);
const totalCost = (completionCost * completionTokens) + (promptCost * promptTokens);
if (!isNaN(totalCost)) {
cost = '$' + totalCost.toFixed(3);
}
}
$('#openrouter_max_prompt_cost').text(cost);
}
function saveModelList(data) {
model_list = data.map((model) => ({ ...model }));
model_list.sort((a, b) => a?.id && b?.id && a.id.localeCompare(b.id));
if (oai_settings.chat_completion_source == chat_completion_sources.OPENROUTER) {
model_list = openRouterSortBy(model_list, oai_settings.openrouter_sort_models);
$('#model_openrouter_select').empty();
if (true === oai_settings.openrouter_group_models) {
appendOpenRouterOptions(openRouterGroupByVendor(model_list), oai_settings.openrouter_group_models);
} else {
appendOpenRouterOptions(model_list);
}
$('#model_openrouter_select').val(oai_settings.openrouter_model).trigger('change');
}
if (oai_settings.chat_completion_source == chat_completion_sources.OPENAI) {
$('#openai_external_category').empty();
model_list.forEach((model) => {
$('#openai_external_category').append(
$('