models-dev 1.0.54__tar.gz → 1.0.56__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1 @@
1
+ /.env
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: models-dev
3
- Version: 1.0.54
3
+ Version: 1.0.56
4
4
  Summary: Typed Python interface to models.dev API data
5
5
  Project-URL: Homepage, https://github.com/vklimontovich/models-dev
6
6
  Project-URL: Documentation, https://models.dev
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "models-dev"
3
- version = "1.0.54"
3
+ version = "1.0.56"
4
4
  description = "Typed Python interface to models.dev API data"
5
5
  readme = "README.md"
6
6
  requires-python = ">=3.10"
@@ -1,5 +1,5 @@
1
1
  # /// script
2
- # dependencies = ["anthropic", "httpx", "gitpython"]
2
+ # dependencies = ["anthropic", "httpx", "gitpython", "models-dev"]
3
3
  # ///
4
4
  """Update data.json.gz from models.dev.
5
5
 
@@ -23,6 +23,7 @@ DATA_URL = "https://models.dev/api.json"
23
23
  ROOT = Path(__file__).parent.parent.parent
24
24
  DATA_PATH = ROOT / "python" / "src" / "models_dev" / "data.json.gz"
25
25
  PYPROJECT_PATH = ROOT / "python" / "pyproject.toml"
26
+ NODE_PACKAGE_PATH = ROOT / "node" / "package.json"
26
27
 
27
28
 
28
29
  def fetch_latest() -> str:
@@ -48,11 +49,14 @@ def compute_diff(old: str, new: str) -> str:
48
49
  return "".join(diff)
49
50
 
50
51
 
51
- def generate_commit_message(diff: str) -> str:
52
- """Generate commit message using Anthropic API."""
52
+ MODEL_ID = "claude-haiku-4-5-20251001"
53
+
54
+
55
+ def generate_commit_message(diff: str) -> tuple[str, int, int]:
56
+ """Generate commit message using Anthropic API. Returns (message, in_tokens, out_tokens)."""
53
57
  api_key = os.environ.get("ANTHROPIC_API_KEY")
54
58
  if not api_key:
55
- return "chore: update models data"
59
+ return "chore: update models data", 0, 0
56
60
 
57
61
  import anthropic
58
62
 
@@ -64,11 +68,28 @@ def generate_commit_message(diff: str) -> str:
64
68
  )
65
69
  prompt = f"{prompt}\n\n{diff[:10000]}"
66
70
  resp = client.messages.create(
67
- model="claude-haiku-4-5",
71
+ model=MODEL_ID,
68
72
  max_tokens=1000,
69
73
  messages=[{"role": "user", "content": prompt}],
70
74
  )
71
- return resp.content[0].text.strip()
75
+ return resp.content[0].text.strip(), resp.usage.input_tokens, resp.usage.output_tokens
76
+
77
+
78
+ def print_token_stats(input_tokens: int, output_tokens: int) -> None:
79
+ """Print token usage and cost using models-dev pricing."""
80
+ from models_dev import get_model_by_id
81
+
82
+ model = get_model_by_id("anthropic", MODEL_ID)
83
+ if not model.cost:
84
+ print(f"Tokens: {input_tokens} in, {output_tokens} out (no pricing data)")
85
+ return
86
+
87
+ input_cost = (input_tokens / 1_000_000) * (model.cost.input or 0)
88
+ output_cost = (output_tokens / 1_000_000) * (model.cost.output or 0)
89
+ total_cost = input_cost + output_cost
90
+
91
+ print(f"Tokens: {input_tokens} in, {output_tokens} out")
92
+ print(f"Cost: ${total_cost:.6f} (${model.cost.input}/M in, ${model.cost.output}/M out)")
72
93
 
73
94
 
74
95
  def get_version() -> str:
@@ -78,7 +99,7 @@ def get_version() -> str:
78
99
 
79
100
 
80
101
  def bump_version() -> str:
81
- """Bump patch version and return new version."""
102
+ """Bump patch version in pyproject.toml and package.json. Returns new version."""
82
103
  content = PYPROJECT_PATH.read_text()
83
104
  old = get_version()
84
105
  parts = old.split(".")
@@ -86,6 +107,12 @@ def bump_version() -> str:
86
107
  new = ".".join(parts)
87
108
  content = re.sub(r'^version = ".+"', f'version = "{new}"', content, flags=re.MULTILINE)
88
109
  PYPROJECT_PATH.write_text(content)
110
+
111
+ # Update node package.json
112
+ pkg = json.loads(NODE_PACKAGE_PATH.read_text())
113
+ pkg["version"] = new
114
+ NODE_PACKAGE_PATH.write_text(json.dumps(pkg, indent=2) + "\n")
115
+
89
116
  return new
90
117
 
91
118
 
@@ -95,10 +122,28 @@ def save_data(data_str: str) -> None:
95
122
  f.write(json.dumps(json.loads(data_str), separators=(",", ":")))
96
123
 
97
124
 
125
+ def get_action_url() -> str | None:
126
+ """Get GitHub Action run URL from environment."""
127
+ server = os.environ.get("GITHUB_SERVER_URL")
128
+ repo = os.environ.get("GITHUB_REPOSITORY")
129
+ run_id = os.environ.get("GITHUB_RUN_ID")
130
+ if server and repo and run_id:
131
+ return f"{server}/{repo}/actions/runs/{run_id}"
132
+ return None
133
+
134
+
98
135
  def commit(message: str) -> None:
99
136
  """Commit changes."""
137
+ action_url = get_action_url()
138
+ if action_url:
139
+ message = f"{message}\n\nAction: {action_url}"
140
+
100
141
  repo = git.Repo(ROOT)
101
- repo.index.add(["python/pyproject.toml", "python/src/models_dev/data.json.gz"])
142
+ repo.index.add([
143
+ "python/pyproject.toml",
144
+ "python/src/models_dev/data.json.gz",
145
+ "node/package.json",
146
+ ])
102
147
  repo.index.commit(message)
103
148
 
104
149
 
@@ -122,8 +167,9 @@ def main() -> int:
122
167
  print(diff[:500])
123
168
 
124
169
  print("Generating commit message...")
125
- message = generate_commit_message(diff)
170
+ message, input_tokens, output_tokens = generate_commit_message(diff)
126
171
  print(f"Message: {message}")
172
+ print_token_stats(input_tokens, output_tokens)
127
173
 
128
174
  if args.dry_run:
129
175
  print("Dry run, stopping")
@@ -34,7 +34,7 @@ wheels = [
34
34
 
35
35
  [[package]]
36
36
  name = "models-dev"
37
- version = "1.0.54"
37
+ version = "1.0.56"
38
38
  source = { editable = "." }
39
39
 
40
40
  [package.dev-dependencies]
@@ -1,10 +0,0 @@
1
- .venv/
2
- __pycache__/
3
- *.pyc
4
- *.egg-info/
5
- dist/
6
- build/
7
- .pytest_cache/
8
- .ruff_cache/
9
- .idea/
10
- python/.venv/
File without changes
File without changes