[OpenRouter] Show API prices on connect in console

This commit is contained in:
spacegeek69 2023-08-10 06:08:26 +02:00
parent 1a07fa8365
commit 0ede3894e2
1 changed files with 22 additions and 2 deletions

View File

@ -2964,8 +2964,28 @@ app.post("/getstatus_openai", jsonParser, function (request, response_getstatus_
client.get(api_url + "/models", args, function (data, response) { client.get(api_url + "/models", args, function (data, response) {
if (response.statusCode == 200) { if (response.statusCode == 200) {
response_getstatus_openai.send(data); response_getstatus_openai.send(data);
const modelIds = data?.data?.map(x => x.id)?.sort(); if (request.body.use_openrouter) {
console.log('Available OpenAI models:', modelIds); 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) { if (response.statusCode == 401) {
console.log('Access Token is incorrect.'); console.log('Access Token is incorrect.');