Merge pull request #915 from spacegeek69/sg69-api-prices-fix2

[OpenRouter] Switch to token per dollar for prices
This commit is contained in:
Cohee 2023-08-10 22:23:17 +03:00 committed by GitHub
commit d18bd20d75
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 6 deletions

View File

@ -722,9 +722,9 @@ function saveModelList(data) {
$('#model_openrouter_select').empty();
$('#model_openrouter_select').append($('<option>', { value: openrouter_website_model, text: 'Use OpenRouter website setting' }));
model_list.forEach((model) => {
let prompt_max_price = parseFloat(model.pricing.prompt) * model.context_length;
let price_rounded = (Math.round(prompt_max_price * 1000) / 1000).toFixed(3);
let model_description = `${model.id} \$${price_rounded} (${model.context_length})`;
let tokens_dollar = parseFloat(1 / (1000 * model.pricing.prompt));
let tokens_rounded = (Math.round(tokens_dollar * 1000) / 1000).toFixed(0);
let model_description = `${model.id} | ${tokens_rounded}k t/$ | ${model.context_length} ctx`;
$('#model_openrouter_select').append(
$('<option>', {
value: model.id,

View File

@ -2968,10 +2968,10 @@ app.post("/getstatus_openai", jsonParser, function (request, response_getstatus_
let models = [];
data.data.forEach(model => {
const context_length = model.context_length;
const prompt_max_price = parseFloat(model.pricing.prompt) * context_length;
const price_rounded = (Math.round(prompt_max_price * 1000) / 1000).toFixed(3);
const tokens_dollar = parseFloat(1 / (1000 * model.pricing.prompt));
const tokens_rounded = (Math.round(tokens_dollar * 1000) / 1000).toFixed(0);
models[model.id] = {
prompt_max_price: price_rounded,
tokens_per_dollar: tokens_rounded + 'k',
context_length: context_length,
};
});