Skip to content

Commit

Permalink
Fix handling of integers in AutoIntParamType (#206)
Browse files Browse the repository at this point in the history
* Fix AutoIntParamType definition

* Bump the version
  • Loading branch information
mryab authored Oct 18, 2024
1 parent 395bc0e commit 2a96da0
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ build-backend = "poetry.masonry.api"

[tool.poetry]
name = "together"
version = "1.3.2"
version = "1.3.3"
authors = [
"Together AI <[email protected]>"
]
Expand Down
23 changes: 15 additions & 8 deletions src/together/cli/api/utils.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,30 @@
from __future__ import annotations

import click

from gettext import gettext as _
from typing import Literal

import click


class AutoIntParamType(click.ParamType):
name = "integer"
name = "integer_or_max"
_number_class = int

def convert(
self, value: str, param: click.Parameter | None, ctx: click.Context | None
) -> int | Literal["max"] | None:
if isinstance(value, int):
return value

if value == "max":
return "max"

self.fail("Invalid integer value: {value}")
try:
return int(value)
except ValueError:
self.fail(
_("{value!r} is not a valid {number_type}.").format(
value=value, number_type=self.name
),
param,
ctx,
)


INT_WITH_MAX = AutoIntParamType()

0 comments on commit 2a96da0

Please sign in to comment.