mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-02-12 10:00:36 +01:00
Merge pull request #912 from spacegeek69/sg69-api-prices-fix
[OpenRouter] Show more API price information
This commit is contained in:
commit
92666b18d4
@ -722,10 +722,13 @@ 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})`;
|
||||
$('#model_openrouter_select').append(
|
||||
$('<option>', {
|
||||
value: model.id,
|
||||
text: model.id,
|
||||
text: model_description,
|
||||
}));
|
||||
});
|
||||
$('#model_openrouter_select').val(oai_settings.openrouter_model).trigger('change');
|
||||
|
24
server.js
24
server.js
@ -2964,8 +2964,28 @@ app.post("/getstatus_openai", jsonParser, function (request, response_getstatus_
|
||||
client.get(api_url + "/models", args, function (data, response) {
|
||||
if (response.statusCode == 200) {
|
||||
response_getstatus_openai.send(data);
|
||||
const modelIds = data?.data?.map(x => x.id)?.sort();
|
||||
console.log('Available OpenAI models:', modelIds);
|
||||
if (request.body.use_openrouter) {
|
||||
let models = [];
|
||||
data.data.forEach(model =>
|
||||
{
|
||||
context_length = model.context_length;
|
||||
prompt_max_price = parseFloat(model.pricing.prompt) * context_length;
|
||||
price_rounded = (Math.round(prompt_max_price * 1000)/1000).toFixed(3);
|
||||
// completion_price = parseFloat(model.pricing.completion) * 1000;
|
||||
models[model.id] = {
|
||||
// prompt_max_price: { text: price_rounded,
|
||||
// val: prompt_max_price },
|
||||
// completion_price: { text: (Math.round(completion_price * 1000)/1000).toFixed(3),
|
||||
// val: completion_price },
|
||||
prompt_max_price: price_rounded,
|
||||
context_length: model.context_length,
|
||||
};
|
||||
});
|
||||
console.log('Available OpenRouter models:', models);
|
||||
} else {
|
||||
const modelIds = data?.data?.map(x => x.id)?.sort();
|
||||
console.log('Available OpenAI models:', modelIds);
|
||||
}
|
||||
}
|
||||
if (response.statusCode == 401) {
|
||||
console.log('Access Token is incorrect.');
|
||||
|
Loading…
x
Reference in New Issue
Block a user