-
Notifications
You must be signed in to change notification settings - Fork 12
feat: support NOT_GIVEN type #69
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
51ba3ed
feat: support NOT_GIVEN type
etang-ai21 6eb124d
fix: test when penalty is not passed
asafgardin a44d674
fix: fix import, make more variants of penalty
etang-ai21 652ddc2
refactor: completion test refactor
etang-ai21 4777b46
fix: rename endpoints
etang-ai21 ccc9b8c
fix: uncomment skip
asafgardin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,10 @@ | ||
| from dataclasses_json import LetterCase, DataClassJsonMixin | ||
|
|
||
| from ai21.utils.typing import is_not_given | ||
|
|
||
|
|
||
| class AI21BaseModelMixin(DataClassJsonMixin): | ||
| dataclass_json_config = { | ||
| "letter_case": LetterCase.CAMEL, | ||
| "exclude": is_not_given, | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,14 +1,16 @@ | ||
| from __future__ import annotations | ||
|
|
||
| from dataclasses import dataclass | ||
| from typing import Optional | ||
|
|
||
| from ai21.types import NOT_GIVEN, NotGiven | ||
| from ai21.models.ai21_base_model_mixin import AI21BaseModelMixin | ||
|
|
||
|
|
||
| @dataclass | ||
| class Penalty(AI21BaseModelMixin): | ||
| scale: float | ||
| apply_to_whitespaces: Optional[bool] = None | ||
| apply_to_punctuation: Optional[bool] = None | ||
| apply_to_numbers: Optional[bool] = None | ||
| apply_to_stopwords: Optional[bool] = None | ||
| apply_to_emojis: Optional[bool] = None | ||
| apply_to_whitespaces: bool | NotGiven = NOT_GIVEN | ||
| apply_to_punctuation: bool | NotGiven = NOT_GIVEN | ||
| apply_to_numbers: bool | NotGiven = NOT_GIVEN | ||
| apply_to_stopwords: bool | NotGiven = NOT_GIVEN | ||
| apply_to_emojis: bool | NotGiven = NOT_GIVEN |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| from typing_extensions import Literal | ||
|
|
||
|
|
||
| # Sentinel class used until PEP 0661 is accepted | ||
| class NotGiven: | ||
| """ | ||
| A sentinel singleton class used to distinguish omitted keyword arguments | ||
| from those passed in with the value None (which may have different behavior). | ||
|
|
||
| For example: | ||
|
|
||
| ```py | ||
| def get(timeout: Union[int, NotGiven, None] = NotGiven()) -> Response: | ||
| ... | ||
|
|
||
|
|
||
| get(timeout=1) # 1s timeout | ||
| get(timeout=None) # No timeout | ||
| get() # Default timeout behavior, which may not be statically known at the method definition. | ||
| ``` | ||
| """ | ||
|
|
||
| def __bool__(self) -> Literal[False]: | ||
| return False | ||
|
|
||
| def __repr__(self) -> str: | ||
| return "NOT_GIVEN" | ||
|
|
||
|
|
||
| NOT_GIVEN = NotGiven() |
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| from typing import Any, Dict | ||
|
|
||
| from ai21.types import NotGiven | ||
|
|
||
|
|
||
| def is_not_given(value: Any) -> bool: | ||
| return isinstance(value, NotGiven) | ||
|
|
||
|
|
||
| def remove_not_given(body: Dict[str, Any]) -> Dict[str, Any]: | ||
| return {k: v for k, v in body.items() if not is_not_given(v)} | ||
|
|
||
|
|
||
| def to_camel_case(snake_str: str) -> str: | ||
| return "".join(x.capitalize() for x in snake_str.lower().split("_")) | ||
|
|
||
|
|
||
| def to_lower_camel_case(snake_str: str) -> str: | ||
| # We capitalize the first letter of each component except the first one | ||
| # with the 'capitalize' method and join them together. | ||
| camel_string = to_camel_case(snake_str) | ||
| return snake_str[0].lower() + camel_string[1:] |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.