From 0ede3894e2e9bfa54873f0f2a15ddad0775c83f5 Mon Sep 17 00:00:00 2001 From: spacegeek69 <140951836+spacegeek69@users.noreply.github.com> Date: Thu, 10 Aug 2023 06:08:26 +0200 Subject: [PATCH] [OpenRouter] Show API prices on connect in console --- server.js | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/server.js b/server.js index 63e122fe4..9c565cae8 100644 --- a/server.js +++ b/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.');