Skip to content

Commit

Permalink
ruff
Browse files Browse the repository at this point in the history
  • Loading branch information
jxnl committed May 6, 2024
1 parent 09b38e0 commit b4e5346
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions tests/test_function_calls.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,15 @@ 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}'
if hasattr(request, "param"):
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",
Expand All @@ -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]
Expand Down Expand Up @@ -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}'}],
Expand All @@ -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}'}],
Expand Down

0 comments on commit b4e5346

Please sign in to comment.