Skip to content

Commit

Permalink
populate API ref in langchain-tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ccurme committed Dec 17, 2024
1 parent 296cc39 commit e0f153e
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ def tool_choice_value(self) -> Optional[str]:
output.
By default, this is determined by whether the chat model's
`with_structured_output` method is overridden. If the base implementation is
``with_structured_output`` method is overridden. If the base implementation is
intended to be used, this method should be overridden.
See: https://python.langchain.com/docs/concepts/structured_outputs/
Expand All @@ -191,6 +191,21 @@ def tool_choice_value(self) -> Optional[str]:
def has_structured_output(self) -> bool:
return True
.. dropdown:: supports_json_mode
Boolean property indicating whether the chat model supports JSON mode in
``with_structured_output``.
See: https://python.langchain.com/docs/concepts/structured_outputs/#json-mode
Example:
.. code-block:: python
@property
def supports_json_mode(self) -> bool:
return True
.. dropdown:: supports_image_inputs
Boolean property indicating whether the chat model supports image inputs.
Expand Down Expand Up @@ -1296,6 +1311,27 @@ class Joke(BaseModel):
assert isinstance(joke_result, Joke)

def test_json_mode(self, model: BaseChatModel) -> None:
"""Test structured output via `JSON mode. <https://python.langchain.com/docs/concepts/structured_outputs/#json-mode>`_
This test is optional and should be skipped if the model does not support
the JSON mode feature (see Configuration below).
.. dropdown:: Configuration
To disable this test, set ``supports_json_mode`` to False in your
test class:
.. code-block:: python
class TestMyChatModelIntegration(ChatModelIntegrationTests):
@property
def supports_json_mode(self) -> bool:
return False
.. dropdown:: Troubleshooting
See example implementation of ``with_structured_output`` here: https://python.langchain.com/api_reference/_modules/langchain_openai/chat_models/base.html#BaseChatOpenAI.with_structured_output
""" # noqa: E501
if not self.supports_json_mode:
pytest.skip("Test requires json mode support.")

Expand Down
18 changes: 17 additions & 1 deletion libs/standard-tests/langchain_tests/unit_tests/chat_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ def has_structured_output(self) -> bool:

@property
def supports_json_mode(self) -> bool:
"""(bool) whether the chat model supports JSON mode."""
return False

@property
Expand Down Expand Up @@ -285,7 +286,7 @@ def tool_choice_value(self) -> Optional[str]:
output.
By default, this is determined by whether the chat model's
`with_structured_output` method is overridden. If the base implementation is
``with_structured_output`` method is overridden. If the base implementation is
intended to be used, this method should be overridden.
See: https://python.langchain.com/docs/concepts/structured_outputs/
Expand All @@ -298,6 +299,21 @@ def tool_choice_value(self) -> Optional[str]:
def has_structured_output(self) -> bool:
return True
.. dropdown:: supports_json_mode
Boolean property indicating whether the chat model supports JSON mode in
``with_structured_output``.
See: https://python.langchain.com/docs/concepts/structured_outputs/#json-mode
Example:
.. code-block:: python
@property
def supports_json_mode(self) -> bool:
return True
.. dropdown:: supports_image_inputs
Boolean property indicating whether the chat model supports image inputs.
Expand Down

0 comments on commit e0f153e

Please sign in to comment.