diff --git a/packages/phoenix-evals/src/phoenix/evals/models/openai.py b/packages/phoenix-evals/src/phoenix/evals/models/openai.py index 59d87f034d..8ccd4de3d3 100644 --- a/packages/phoenix-evals/src/phoenix/evals/models/openai.py +++ b/packages/phoenix-evals/src/phoenix/evals/models/openai.py @@ -46,6 +46,16 @@ class AzureOptions: azure_ad_token_provider: Optional[Callable[[], str]] +def _model_supports_temperature(model: str) -> bool: + """OpenAI 01 models do not support temperature.""" + return "o1-" not in model + + +def _model_supports_max_tokens(model: str) -> bool: + """OpenAI 01 models do not support max_tokens.""" + return "o1-" not in model + + @dataclass class OpenAIModel(BaseModel): """ @@ -380,15 +390,26 @@ def invocation_params(self) -> Dict[str, Any]: @property def _default_params(self) -> Dict[str, Any]: """Get the default parameters for calling OpenAI API.""" - return { - "temperature": self.temperature, - "max_tokens": self.max_tokens, + params = { "frequency_penalty": self.frequency_penalty, "presence_penalty": self.presence_penalty, "top_p": self.top_p, "n": self.n, "timeout": self.request_timeout, } + if _model_supports_max_tokens(self.model): + params.update( + { + "max_tokens": self.max_tokens, + } + ) + if _model_supports_temperature(self.model): + params.update( + { + "temperature": self.temperature, + } + ) + return params @property def supports_function_calling(self) -> bool: diff --git a/packages/phoenix-evals/tests/phoenix/evals/functions/test_classify.py b/packages/phoenix-evals/tests/phoenix/evals/functions/test_classify.py index 7942a43693..84cb6803d7 100644 --- a/packages/phoenix-evals/tests/phoenix/evals/functions/test_classify.py +++ b/packages/phoenix-evals/tests/phoenix/evals/functions/test_classify.py @@ -368,7 +368,8 @@ def test_llm_classify_prints_to_stdout_with_verbose_flag( assert "Snapped '\\nrelevant ' to rail: relevant" in out, "Snapping events should be printed" assert "Cannot snap 'unparsable' to rails" in out, "Snapping events should be printed" assert "OpenAI invocation parameters" in out, "Model-specific information should be printed" - assert "'model': 'gpt-4', 'temperature': 0.0" in out, "Model information should be printed" + assert "'model': 'gpt-4'" in out, "Model information should be printed" + assert "'temperature': 0.0" in out, "Model information should be printed" assert "sk-0123456789" not in out, "Credentials should not be printed out in cleartext"