diff --git a/tests/test_function_calls.py b/tests/test_function_calls.py index bcedb9ef2..07b2dc1da 100644 --- a/tests/test_function_calls.py +++ b/tests/test_function_calls.py @@ -52,6 +52,7 @@ def mock_completion(request: T) -> ChatCompletion: return completion + @pytest.fixture # type: ignore[misc] def mock_anthropic_message(request: T) -> Message: data_content = '{\n"data": "Claude says hi"\n}' @@ -59,7 +60,7 @@ def mock_anthropic_message(request: T) -> Message: data_content = request.param.get("data_content", data_content) return Message( id="test_id", - content=[{ "type": "text", "text": data_content }], + content=[{"type": "text", "text": data_content}], model="claude-3-haiku-20240307", role="assistant", stop_reason="end_turn", @@ -68,9 +69,10 @@ def mock_anthropic_message(request: T) -> Message: usage=Usage( input_tokens=100, output_tokens=100, - ) + ), ) + def test_openai_schema() -> None: @openai_schema class Dataframe(BaseModel): # type: ignore[misc] @@ -142,12 +144,16 @@ def test_incomplete_output_exception_raise( with pytest.raises(IncompleteOutputException): test_model.from_response(mock_completion, mode=instructor.Mode.FUNCTIONS) + def test_anthropic_no_exception( test_model: type[OpenAISchema], mock_anthropic_message: Message ) -> None: - test_model_instance = test_model.from_response(mock_anthropic_message, mode=instructor.Mode.ANTHROPIC_JSON) + test_model_instance = test_model.from_response( + mock_anthropic_message, mode=instructor.Mode.ANTHROPIC_JSON + ) assert test_model_instance.data == "Claude says hi" + @pytest.mark.parametrize( "mock_anthropic_message", [{"data_content": '{\n"data": "Claude likes\ncontrol\ncharacters"\n}'}], @@ -167,6 +173,7 @@ def test_control_characters_not_allowed_in_anthropic_json_strict_mode( assert exc.errors()[0]["type"] == "json_invalid" assert "control character" in exc.errors()[0]["msg"] + @pytest.mark.parametrize( "mock_anthropic_message", [{"data_content": '{\n"data": "Claude likes\ncontrol\ncharacters"\n}'}],