Skip to content

Commit

Permalink
Add an after model validator ensuring temp=1 for o1 models
Browse files Browse the repository at this point in the history
o1-preview and o1-mini in Beta only support temperature=1.
  • Loading branch information
dakoner committed Oct 29, 2024
1 parent 34bc169 commit f8a0213
Showing 1 changed file with 13 additions and 0 deletions.
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:
"""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:
raise ValueError(
"When using 'o1-preview' LLM, the temperature must be set to 1."
)
return self

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

0 comments on commit f8a0213

Please sign in to comment.