Skip to content

Commit

Permalink
Set min/max constraints to float arguments
Browse files Browse the repository at this point in the history
* Add .idea/ to .gitignore
* Set min and max constraints to float parameters

Closes #115
  • Loading branch information
pavelkraleu authored Jul 26, 2023
1 parent 531d188 commit 838484b
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ venv
.pytest_cache
*.egg-info
.DS_Store
.idea/
8 changes: 8 additions & 0 deletions llm/default_plugins/openai_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ class Options(llm.Options):
"0.8 will make the output more random, while lower values like 0.2 will "
"make it more focused and deterministic."
),
ge=0,
le=2,
default=None,
)
max_tokens: Optional[int] = Field(
Expand All @@ -107,6 +109,8 @@ class Options(llm.Options):
"10% probability mass are considered. Recommended to use top_p or "
"temperature but not both."
),
ge=0,
le=1,
default=None,
)
frequency_penalty: Optional[float] = Field(
Expand All @@ -115,6 +119,8 @@ class Options(llm.Options):
"on their existing frequency in the text so far, decreasing the model's "
"likelihood to repeat the same line verbatim."
),
ge=-2,
le=2,
default=None,
)
presence_penalty: Optional[float] = Field(
Expand All @@ -123,6 +129,8 @@ class Options(llm.Options):
"on whether they appear in the text so far, increasing the model's "
"likelihood to talk about new topics."
),
ge=-2,
le=2,
default=None,
)
stop: Optional[str] = Field(
Expand Down
25 changes: 25 additions & 0 deletions tests/test_cli_openai_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,28 @@ def test_openai_models(mocked_models):
"ada:2020-05-03 openai 2020-05-03T20:26:40\n"
"babbage:2020-05-03 openai 2020-05-03T20:26:40\n"
)


def test_openai_options_min_max(mocked_models):
options = {
"temperature": [0, 2],
"top_p": [0, 1],
"frequency_penalty": [-2, 2],
"presence_penalty": [-2, 2],
}
runner = CliRunner()

for option, [min_val, max_val] in options.items():
result = runner.invoke(cli, ["-m", "chatgpt", "-o", option, "-10"])
assert result.exit_code == 1
assert (
result.output
== f"Error: {option}\n Input should be greater than or equal to {min_val}\n"
)

result = runner.invoke(cli, ["-m", "chatgpt", "-o", option, "10"])
assert result.exit_code == 1
assert (
result.output
== f"Error: {option}\n Input should be less than or equal to {max_val}\n"
)

0 comments on commit 838484b

Please sign in to comment.