Skip to content
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

Made o1 temperature issue a warning, instead of valueerror #669

Merged
merged 2 commits into from
Nov 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions paperqa/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -690,10 +690,13 @@ def _validate_temperature_for_o1_preview(self) -> Self:
https://platform.openai.com/docs/guides/reasoning/quickstart
"""
if self.llm.startswith("o1-") and self.temperature != 1:
raise ValueError(
"When dealing with OpenAI o1 models, the temperature"
f" must be set to 1, {self.temperature} was specified."
warnings.warn(
"When dealing with OpenAI o1 models, the temperature must be set to 1."
f" The specified temperature {self.temperature} has been overridden to 1.",
category=UserWarning,
stacklevel=2,
)
self.temperature = 1
return self

@computed_field # type: ignore[prop-decorator]
Expand Down
15 changes: 12 additions & 3 deletions tests/test_configs.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import warnings
from unittest.mock import patch

import pytest
Expand Down Expand Up @@ -70,6 +71,14 @@ def test_router_kwargs_present_in_models() -> None:


def test_o1_requires_temp_equals_1() -> None:
with pytest.raises(ValidationError):
_ = Settings(llm="o1-thismodeldoesnotexist", temperature=0)
_ = Settings(llm="o1-thismodeldoesnotexist", temperature=1)
with warnings.catch_warnings(record=True) as w:
warnings.simplefilter("always")
s = Settings(llm="o1-thismodeldoesnotexist", temperature=0)
assert "temperature must be set to 1" in str(w[-1].message)
assert s.temperature == 1

# Test that temperature=1 produces no warning
with warnings.catch_warnings(record=True) as w:
warnings.simplefilter("always")
_ = Settings(llm="o1-thismodeldoesnotexist", temperature=1)
assert not w
2 changes: 1 addition & 1 deletion uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.