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

Add an after model validator ensuring temp=1 for o1 models #649

Merged
merged 8 commits into from
Oct 29, 2024
13 changes: 13 additions & 0 deletions paperqa/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -678,6 +678,19 @@ def _deprecated_field(self) -> Self:
setattr(self.agent.index, new_name, value) # Propagate to new location
return self

@model_validator(mode="after")
def _validate_temperature_for_o1_preview(self) -> Self:
dakoner marked this conversation as resolved.
Show resolved Hide resolved
"""Ensures temperature is 1 if the LLM is 'o1-preview' or 'o1-mini'.

o1 reasoning models only support temperature = 1. See
https://platform.openai.com/docs/guides/reasoning/quickstart
"""
if self.llm in ("o1-preview", "o1-mini") and self.temperature != 1:
dakoner marked this conversation as resolved.
Show resolved Hide resolved
raise ValueError(
"When using 'o1-preview' LLM, the temperature must be set to 1."
dakoner marked this conversation as resolved.
Show resolved Hide resolved
)
return self

@computed_field # type: ignore[prop-decorator]
@property
def md5(self) -> str:
Expand Down
Loading