mirror of
https://github.com/Routstr/routstr-core.git
synced 2026-08-01 08:16:13 +00:00
Compare commits
8
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
46a1e8ebef | ||
|
|
9593437a81 | ||
|
|
801bc50fd7 | ||
|
|
ecbe3158c0 | ||
|
|
bac50f2150 | ||
|
|
4bf02226dc | ||
|
|
c8f4e7d3e5 | ||
|
|
3d4a8e0e14 |
@@ -35,12 +35,15 @@ jobs:
|
||||
run: |
|
||||
uv run mypy .
|
||||
|
||||
- name: Run tests with pytest
|
||||
- name: Run tests with pytest (with coverage & junit)
|
||||
env:
|
||||
UPSTREAM_BASE_URL: "http://test"
|
||||
UPSTREAM_API_KEY: "test"
|
||||
run: |
|
||||
uv run pytest --verbose --tb=short
|
||||
uv run pytest \
|
||||
--verbose --tb=short \
|
||||
--junitxml=pytest.xml \
|
||||
--cov=routstr --cov-report=term
|
||||
|
||||
- name: Upload test results
|
||||
if: always()
|
||||
|
||||
@@ -320,18 +320,20 @@ async def fetch_provider_health(endpoint_url: str) -> dict[str, Any]:
|
||||
is_onion = ".onion" in endpoint_url
|
||||
|
||||
# Set up client arguments conditionally
|
||||
proxies = None
|
||||
proxies: dict[str, str] | None = None
|
||||
if is_onion:
|
||||
try:
|
||||
tor_proxy = settings.tor_proxy_url
|
||||
except Exception:
|
||||
tor_proxy = "socks5://127.0.0.1:9050"
|
||||
proxies = {"http://": tor_proxy, "https://": tor_proxy} # type: ignore[assignment]
|
||||
proxies = {"http://": tor_proxy, "https://": tor_proxy}
|
||||
|
||||
async with httpx.AsyncClient(
|
||||
timeout=httpx.Timeout(30.0),
|
||||
follow_redirects=True,
|
||||
proxies=proxies, # type: ignore[arg-type]
|
||||
# NOTE: httpx < 0.28 supports the 'proxies' kwarg, 0.28+ removed it.
|
||||
# We ignore the call-arg type here to keep compatibility across versions.
|
||||
proxies=proxies, # type: ignore[call-arg]
|
||||
) as client:
|
||||
# Prefer provider's /v1/info for full details
|
||||
info_url = f"{endpoint_url.rstrip('/')}/v1/info"
|
||||
|
||||
@@ -183,14 +183,23 @@ async def calculate_discounted_max_cost(
|
||||
else:
|
||||
adjusted = adjusted + math.ceil(-estimated_prompt_delta_sats * 1000)
|
||||
|
||||
if max_tokens := body.get("max_tokens"):
|
||||
estimated_completion_delta_sats = (
|
||||
max_completion_allowed_sats - max_tokens * model_pricing.completion
|
||||
)
|
||||
if estimated_completion_delta_sats >= 0:
|
||||
adjusted = adjusted - math.floor(estimated_completion_delta_sats * 1000)
|
||||
max_tokens_raw = body.get("max_tokens", None)
|
||||
if max_tokens_raw is not None:
|
||||
try:
|
||||
max_tokens_int = int(max_tokens_raw)
|
||||
except (TypeError, ValueError):
|
||||
logger.warning(
|
||||
"Invalid max_tokens; ignoring in cost adjustment",
|
||||
extra={"max_tokens": str(max_tokens_raw)[:64], "model": model},
|
||||
)
|
||||
else:
|
||||
adjusted = adjusted + math.ceil(-estimated_completion_delta_sats * 1000)
|
||||
estimated_completion_delta_sats = (
|
||||
max_completion_allowed_sats - max_tokens_int * model_pricing.completion
|
||||
)
|
||||
if estimated_completion_delta_sats >= 0:
|
||||
adjusted = adjusted - math.floor(estimated_completion_delta_sats * 1000)
|
||||
else:
|
||||
adjusted = adjusted + math.ceil(-estimated_completion_delta_sats * 1000)
|
||||
|
||||
logger.debug(
|
||||
"Discounted max cost computed",
|
||||
|
||||
+2
-2
@@ -28,7 +28,7 @@ async def recieve_token(
|
||||
wallet = await get_wallet(token_obj.mint, token_obj.unit, load=False)
|
||||
wallet.keyset_id = token_obj.keysets[0]
|
||||
|
||||
if token_obj.mint not in settings.cashu_mints:
|
||||
if token_obj.mint.rstrip("/") not in [mint.rstrip("/") for mint in settings.cashu_mints]:
|
||||
return await swap_to_primary_mint(token_obj, wallet)
|
||||
|
||||
wallet.verify_proofs_dleq(token_obj.proofs)
|
||||
@@ -153,7 +153,7 @@ async def get_wallet(mint_url: str, unit: str = "sat", load: bool = True) -> Wal
|
||||
id = f"{mint_url}_{unit}"
|
||||
if id not in _wallets:
|
||||
_wallets[id] = await Wallet.with_db(
|
||||
mint_url, db=".wallet", load_all_keysets=True, unit=unit
|
||||
mint_url, db=".wallet", unit=unit
|
||||
)
|
||||
|
||||
if load:
|
||||
|
||||
Reference in New Issue
Block a user