Skip to content

Commit 09f1763

Browse files
committed
Remove promo credits support and bump version (0.3.29)
1 parent 2d9704a commit 09f1763

3 files changed

Lines changed: 8 additions & 84 deletions

File tree

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ name = "weco"
88
authors = [{ name = "Weco AI Team", email = "contact@weco.ai" }]
99
description = "Documentation for `weco`, a CLI for using Weco AI's code optimizer."
1010
readme = "README.md"
11-
version = "0.3.28"
11+
version = "0.3.29"
1212
license = { file = "LICENSE" }
1313
requires-python = ">=3.9"
1414
dependencies = [

weco/cli.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -450,10 +450,13 @@ def execute_run_command(args: argparse.Namespace) -> None:
450450
if api_keys:
451451
console.print(f"[bold yellow]Custom API keys provided. Using default model: {model} for the run.[/]")
452452

453-
# Check for promotional credits and prompt user if applicable
454-
from .credits import check_promotional_credits
455-
456-
model = check_promotional_credits(model, api_keys, console)
453+
if api_keys and "/" in model:
454+
bare_model = model.split("/", 1)[1]
455+
console.print(
456+
f"[yellow]Note: provider prefix in '{model}' is ignored when using your own API keys — "
457+
f"the provider is inferred from the key you supplied. Using '{bare_model}'.[/]"
458+
)
459+
model = bare_model
457460

458461
# Send run attempt event before starting (helps measure dropoff before server)
459462
send_event(

weco/credits.py

Lines changed: 0 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -3,82 +3,13 @@
33
import webbrowser
44
import requests
55
from rich.console import Console
6-
from rich.prompt import Confirm
76
from rich.table import Table
87
from . import __base_url__
98
from .api import handle_api_error
109
from .auth import handle_authentication
1110
from .config import load_weco_api_key
1211

1312

14-
def check_promotional_credits(model: str, api_keys: dict[str, str] | None, console: Console) -> str:
15-
"""Check for promotional credits and prompt user to use them if applicable.
16-
17-
Returns the (possibly modified) model string with provider prefix.
18-
"""
19-
# Skip if user is using their own API keys (BYOK — not billed)
20-
if api_keys:
21-
return model
22-
23-
# If model already has provider prefix, inform user about matching credits
24-
if "/" in model:
25-
provider = model.split("/", 1)[0]
26-
try:
27-
weco_api_key = load_weco_api_key()
28-
if not weco_api_key:
29-
return model
30-
resp = requests.get(
31-
f"{__base_url__}/billing/balance", headers={"Authorization": f"Bearer {weco_api_key}"}, timeout=5
32-
)
33-
if resp.ok:
34-
promo_credits = resp.json().get("promotional_credits", [])
35-
matching = [g for g in promo_credits if g.get("provider") == provider]
36-
if matching:
37-
total = sum(g.get("remaining_credits", 0) for g in matching)
38-
expires = matching[0].get("expires_at", "")[:10]
39-
console.print(
40-
f"[green]✅ Using {provider.capitalize()} promotional credits "
41-
f"(${total:.2f} remaining, expires {expires})[/]"
42-
)
43-
except Exception:
44-
pass # Non-critical; don't block the run
45-
return model
46-
47-
# Bare model name — check for promotional credits
48-
try:
49-
weco_api_key = load_weco_api_key()
50-
if not weco_api_key:
51-
return model
52-
resp = requests.get(f"{__base_url__}/billing/balance", headers={"Authorization": f"Bearer {weco_api_key}"}, timeout=5)
53-
if not resp.ok:
54-
return model
55-
56-
promo_credits = resp.json().get("promotional_credits", [])
57-
if not promo_credits:
58-
return model
59-
60-
# Check if any grant provider could serve this model
61-
for grant in promo_credits:
62-
grant_provider = grant.get("provider", "")
63-
remaining = grant.get("remaining_credits", 0)
64-
expires = grant.get("expires_at", "")[:10]
65-
66-
# Suggest using the grant's provider
67-
prefixed_model = f"{grant_provider}/{model}"
68-
console.print(
69-
f"\n[yellow]💡 You have ${remaining:.2f} in {grant_provider.capitalize()} credits (expires {expires}).[/]"
70-
)
71-
use_credits = Confirm.ask(f" Use [bold]{prefixed_model}[/] to apply them?", default=True)
72-
if use_credits:
73-
console.print(f"[green]✅ Using {grant_provider.capitalize()} promotional credits[/]\n")
74-
return prefixed_model
75-
76-
except Exception:
77-
pass # Non-critical; don't block the run
78-
79-
return model
80-
81-
8213
def handle_credits_command(args, console: Console) -> None:
8314
"""Handle the credits command and its subcommands."""
8415
# Ensure user is authenticated
@@ -124,16 +55,6 @@ def check_balance(console: Console, auth_headers: dict) -> None:
12455

12556
console.print(table)
12657

127-
# Show promotional credits if any
128-
promo_credits = data.get("promotional_credits", [])
129-
if promo_credits:
130-
console.print("\n[bold cyan]Promotional Credits:[/]")
131-
for grant in promo_credits:
132-
provider = grant.get("provider", "Unknown")
133-
remaining = grant.get("remaining_credits", 0)
134-
expires_at = grant.get("expires_at", "")[:10] # Date portion only
135-
console.print(f" {provider.capitalize()} models: [green]${remaining:.2f}[/] (expires {expires_at})")
136-
13758
except requests.exceptions.HTTPError as e:
13859
if e.response.status_code == 401:
13960
console.print("[bold red]Authentication failed. Please log in again with 'weco'.[/]")

0 commit comments

Comments
 (0)