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

feat: OpenAI support for o1 preview #4633

Merged
merged 2 commits into from
Sep 17, 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
27 changes: 24 additions & 3 deletions packages/phoenix-evals/src/phoenix/evals/models/openai.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand Down Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"


Expand Down
Loading