forked from dotneet/smart-chatbot-ui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
init-mongo.js
31 lines (30 loc) · 1.35 KB
/
init-mongo.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
db.createCollection("llmPriceRate");
parseAndUpdateApiRates();
function parseAndUpdateApiRates() {
// modelId from /types/openai OpenAIModelID
Object.entries(process.env)
.filter(([key, value]) => key.startsWith("MODEL_PRICING_1000_"))
.forEach(([key, value]) => {
let modelId, promptPricing, completionPricing;
if (key.startsWith("MODEL_PRICING_1000_PROMPT_")) {
modelId = key.replace("MODEL_PRICING_1000_PROMPT_", "");
promptPricing = parseFloat(value);
} else if (key.startsWith("MODEL_PRICING_1000_COMPLETION_")) {
modelId = key.replace("MODEL_PRICING_1000_COMPLETION_", "");
completionPricing = parseFloat(value);
}
console.log("Setting " + (promptPricing ? "prompt" : "completion") + " price rate for model " + modelId +
" to " + (promptPricing || completionPricing));
db.llmPriceRate.updateOne(
{ modelId },
{
$set: {
modelId,
...(promptPricing ? { promptPriceUSDPer1000: promptPricing } : {}),
...(completionPricing ? { completionPriceUSDPer1000: completionPricing } : {}),
}
},
{ upsert: true }
)
})
}