mirror of
https://github.com/dograh-hq/dograh.git
synced 2026-07-13 11:22:14 +02:00
feat: show model pricing in configuration UI (#528)
* feat: show model pricing in configuration UI * fix: display effective pricing rounding policy
This commit is contained in:
parent
e7494e9c21
commit
c76076fb93
13 changed files with 445 additions and 9 deletions
66
api/tests/test_model_configuration_pricing.py
Normal file
66
api/tests/test_model_configuration_pricing.py
Normal file
|
|
@ -0,0 +1,66 @@
|
|||
from types import SimpleNamespace
|
||||
from unittest.mock import AsyncMock
|
||||
|
||||
import pytest
|
||||
|
||||
from api.routes import organization as organization_routes
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_model_configuration_pricing_returns_empty_in_oss(monkeypatch):
|
||||
get_pricing = AsyncMock()
|
||||
monkeypatch.setattr(organization_routes, "DEPLOYMENT_MODE", "oss")
|
||||
monkeypatch.setattr(
|
||||
organization_routes.mps_service_key_client,
|
||||
"get_billing_pricing",
|
||||
get_pricing,
|
||||
)
|
||||
|
||||
response = await organization_routes.get_model_configuration_pricing(
|
||||
SimpleNamespace(selected_organization_id=42),
|
||||
)
|
||||
|
||||
assert response.platform_usage is None
|
||||
assert response.dograh_model is None
|
||||
get_pricing.assert_not_awaited()
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_model_configuration_pricing_uses_selected_organization(monkeypatch):
|
||||
get_pricing = AsyncMock(
|
||||
return_value={
|
||||
"organization_id": 42,
|
||||
"platform_usage": {
|
||||
"metric_code": "platform_usage",
|
||||
"display_name": "Platform usage",
|
||||
"unit": "minute",
|
||||
"price_per_minute": 0.01,
|
||||
"currency": "USD",
|
||||
"rounding_policy": "ceil_minute",
|
||||
},
|
||||
"dograh_model": {
|
||||
"metric_code": "voice_minutes",
|
||||
"display_name": "Dograh model usage",
|
||||
"unit": "minute",
|
||||
"price_per_minute": 0.07,
|
||||
"currency": "USD",
|
||||
"rounding_policy": "ceil_minute",
|
||||
},
|
||||
}
|
||||
)
|
||||
monkeypatch.setattr(organization_routes, "DEPLOYMENT_MODE", "saas")
|
||||
monkeypatch.setattr(
|
||||
organization_routes.mps_service_key_client,
|
||||
"get_billing_pricing",
|
||||
get_pricing,
|
||||
)
|
||||
|
||||
response = await organization_routes.get_model_configuration_pricing(
|
||||
SimpleNamespace(selected_organization_id=42),
|
||||
)
|
||||
|
||||
get_pricing.assert_awaited_once_with(42)
|
||||
assert response.platform_usage is not None
|
||||
assert response.platform_usage.price_per_minute == 0.01
|
||||
assert response.dograh_model is not None
|
||||
assert response.dograh_model.price_per_minute == 0.07
|
||||
Loading…
Add table
Add a link
Reference in a new issue