Skip to content
Open
Show file tree
Hide file tree
Changes from 2 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
13 changes: 10 additions & 3 deletions mellea/backends/openai.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,16 @@ def __init__(
if self._base_url is not None
else _ServerType.OPENAI
) # type: ignore
if self._server_type != _ServerType.OPENAI:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Flagging in case another reviewer raises this: moving the log to fire on server type alone, regardless of whether format= is ever used, isn't scope creep — issue #1502's own "Proposed fix, Option 1" asks for exactly this ("tie the message to backend setup rather than the generate loop"). This matches the issue as written.

MelleaLogger.get_logger().info(
"Mellea assumes you are NOT using the OpenAI platform, and that "
"other model providers have less strict requirements on supporting "
"JSON schemas passed into `format=`. If you encounter a server-side "
"error when using format=, then you found an exception to this "
"assumption. Please open an issue at "
"github.com/generative_computing/mellea with the stack trace and "
Comment thread
planetf1 marked this conversation as resolved.
Outdated
"your inference engine / model provider."
)

self._openai_client_kwargs = self.filter_openai_client_kwargs(**kwargs)

Expand Down Expand Up @@ -934,9 +944,6 @@ async def _generate_from_chat_context_standard(
},
}
else:
MelleaLogger.get_logger().info(
"Mellea assumes you are NOT using the OpenAI platform, and that other model providers have less strict requirements on supporting JSON schemas passed into `format=`. If you encounter a server-side error following this message, then you found an exception to this assumption. Please open an issue at github.com/generative_computing/mellea with this stack trace and your inference engine / model provider."
)
extra_params["response_format"] = {
"type": "json_schema",
"json_schema": {
Expand Down
45 changes: 45 additions & 0 deletions test/backends/test_openai_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -429,5 +429,50 @@ class Answer(pydantic.BaseModel):
assert "guided_json" in extra_body or "structured_outputs" in extra_body


# --- #1502: non-OpenAI format= warning only at init ---

_FORMAT_ASSUMPTION = "NOT using the OpenAI platform"


def _info_msgs(mock_logger) -> list[str]:
return [str(c.args[0]) for c in mock_logger.info.call_args_list if c.args]


def test_non_openai_format_assumption_logged_once_at_init():
mock_logger = MagicMock()
with patch(
"mellea.backends.openai.MelleaLogger.get_logger", return_value=mock_logger
):
OpenAIBackend(
model_id="gpt-4o",
api_key="fake-key",
base_url="http://localhost:9999/v1",
)
OpenAIBackend(
model_id="gpt-4o",
api_key="fake-key",
base_url="http://localhost:9999/v1",
)
Comment thread
planetf1 marked this conversation as resolved.

matches = [m for m in _info_msgs(mock_logger) if _FORMAT_ASSUMPTION in m]
assert len(matches) == 2 # once per backend instance


def test_openai_platform_skips_format_assumption_log():
mock_logger = MagicMock()
with patch(
"mellea.backends.openai.MelleaLogger.get_logger", return_value=mock_logger
):
OpenAIBackend(
model_id="gpt-4o",
api_key="fake-key",
base_url="https://api.openai.com/v1",
)
Comment thread
planetf1 marked this conversation as resolved.
OpenAIBackend(model_id="gpt-4o", api_key="fake-key")

matches = [m for m in _info_msgs(mock_logger) if _FORMAT_ASSUMPTION in m]
assert matches == []


if __name__ == "__main__":
pytest.main([__file__, "-v"])
Loading