qoder 0.2.2, workbuddy 0.1.6: each model's credit rate goes to magpie (rate, rateWas), as magpie's built-ins read it (yetone/magpie 33acb6bc, v0.1.667)
magpie now shows each model's credit rate in the provider's model list and an agent's picker (01huadalang on Discord: pick the cheap models without opening Qoder or WorkBuddy); a plugin gives it beside free on each model its provider.models hook lists. Qoder and Qoder CN: rate is the price_factor (priceFactor); rateWas an active promotion's before_promotion_price_factor, else an original_price_factor above the price (Qwen3.8-Flash: 0x, 0.1x struck through); a promotion's 0 that isn't free is its price before times its discount_factor; a listing with no price gives none — the rule of internal/qoder/models.go's ModelInfo.free. WorkBuddy and WorkBuddy AI: rate is the model's credits ("x0.03" is 0.03; x0.00 stays free; an unreadable, negative or infinite rate is neither free nor rated), as wbCredits reads it.
usage.test.mjs in each package gets a test fed a fake listing / fake /v3/config (the cases of core's TestParseModelsRate and TestWBCreditsRate); both fail against the previous index.mjs and pass now. No request was made to Qoder or WorkBuddy. bun test (HOME a temp dir) and bun scripts/check.mjs pass.
This commit is contained in:
@@ -282,6 +282,41 @@ test("a discount is not free: Qwen3.8-Max (0.5×, is_free true) is priced, Qwen3
|
||||
expect(_internal.modelInfo({ key: "x", priceFactor: 0, promotion: { active: true, beforePromotionPriceFactor: 1 } }).free).toBe(false)
|
||||
})
|
||||
|
||||
// Each model carries its price as Qoder's client shows it beside the model,
|
||||
// as magpie's built-in reads it (internal/qoder/models_test.go,
|
||||
// TestParseModelsRate): Qwen3.8-Max 0.5×, Kimi-K3 1.4×, Qwen3.8-Flash 0×
|
||||
// with 0.1× struck through; a running promotion's price before it struck
|
||||
// through, and its 0 that isn't free read as that price times its
|
||||
// discount. A listing with no price gives none.
|
||||
test("each model's rate, and its price before a running discount", async () => {
|
||||
const RATED = {
|
||||
chat: [
|
||||
{ key: "qmodel_38max", enable: true, price_factor: 0.5, is_free: true, promotion: OFF_PEAK },
|
||||
{ key: "qmodel_38max-offpeak", enable: true, price_factor: 0.2, promotion: { ...OFF_PEAK, active: true } },
|
||||
{ key: "qfmodel", enable: true, price_factor: 0.0, original_price_factor: 0.1, is_free: true },
|
||||
{ key: "qmodel_latest", enable: true, price_factor: 0.5, original_price_factor: 0.5 },
|
||||
{ key: "kmodel_latest", enable: true, priceFactor: 1.4, originalPriceFactor: 2 },
|
||||
{ key: "window", enable: true, price_factor: 0, promotion: { active: true, discount_factor: 0.5, before_promotion_price_factor: 1 } },
|
||||
{ key: "window-camel", enable: true, priceFactor: 0, promotion: { active: true, discountFactor: 0.25, beforePromotionPriceFactor: 2 } },
|
||||
{ key: "unpriced", enable: true, is_free: true },
|
||||
],
|
||||
}
|
||||
const { hooks, auth } = await chat(RATED, () => new Response(""))
|
||||
const ms = await hooks.provider.models({ models: {} }, { auth })
|
||||
expect(Object.fromEntries(Object.entries(ms).map(([k, m]) => [k, [m.rate, m.rateWas]]))).toEqual({
|
||||
qmodel_38max: [0.5, 0],
|
||||
"qmodel_38max-offpeak": [0.2, 0.5],
|
||||
qfmodel: [0, 0.1],
|
||||
qmodel_latest: [0.5, 0],
|
||||
kmodel_latest: [1.4, 2],
|
||||
window: [0.5, 1],
|
||||
"window-camel": [0.5, 2],
|
||||
unpriced: [0, 0],
|
||||
})
|
||||
expect(ms.qfmodel.free).toBe(true)
|
||||
expect(ms.window.free).toBe(false)
|
||||
})
|
||||
|
||||
// a usage read on an account whose job token is due, the refresh answered by refresh()
|
||||
async function dueUsage(refresh, read) {
|
||||
let auth = { ...account(), expires: 0 }
|
||||
|
||||
Reference in New Issue
Block a user