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 1/2] [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.');
From f9db8eee67094810bf1f105424e0978a1df8d45f Mon Sep 17 00:00:00 2001
From: spacegeek69 <140951836+spacegeek69@users.noreply.github.com>
Date: Thu, 10 Aug 2023 06:11:03 +0200
Subject: [PATCH 2/2] [OpenRouter] Show API prices in list/description
---
public/scripts/openai.js | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/public/scripts/openai.js b/public/scripts/openai.js
index 8393b4ed2..d27fc4c58 100644
--- a/public/scripts/openai.js
+++ b/public/scripts/openai.js
@@ -722,10 +722,13 @@ function saveModelList(data) {
$('#model_openrouter_select').empty();
$('#model_openrouter_select').append($('