Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
Anmol6 committed Dec 1, 2023
1 parent f9a930c commit 9a261d8
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 4 deletions.
4 changes: 0 additions & 4 deletions instructor/patch.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,6 @@ def handle_response_model(
do not deviate at all: \n{response_model.model_json_schema()['properties']}
"""
else:
if not "vision" in new_kwargs.get("model", ""):
raise ValueError(
"MD_JSON is only supported for vision models, please specify a vision model"
)
message = f"""
As a genius expert, your task is to understand the content and provide
the parsed objects in json that match the following json_schema (do not deviate at all and its okay if you cant be exact):\n
Expand Down
40 changes: 40 additions & 0 deletions tests/openai/test_modes.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,46 @@ def test_json_mode():
assert user.name.lower() == "jason"
assert user.age == 25

def test_json_mode():
response = client.chat.completions.create(
model="gpt-3.5-turbo-1106",
response_format={"type": "json_object"},
messages=[
{
"role": "system",
"content": f"Make sure that your response to any message matchs the json_schema below, do not deviate at all: \n{UserExtract.model_json_schema()['properties']}",
},
{
"role": "user",
"content": "Extract jason is 25 years old",
},
],
)
user = UserExtract.from_response(response, mode=Mode.JSON)
assert user.name.lower()
assert user.age == 25



def test_markdown_json_mode():
response = client.chat.completions.create(
model="gpt-3.5-turbo-1106",
response_format={"type": "json_object"},
messages=[
{
"role": "system",
"content": f"Make sure that your response to any message matchs the json_schema below, do not deviate at all: \n{UserExtract.model_json_schema()['properties']}",
},
{
"role": "user",
"content": "Extract jason is 25 years old",
},
],
)
user = UserExtract.from_response(response, mode=Mode.MD_JSON)
assert user.name.lower()
assert user.age == 25


@pytest.mark.parametrize("mode", [Mode.FUNCTIONS, Mode.JSON, Mode.TOOLS])
def test_mode(mode):
Expand Down

0 comments on commit 9a261d8

Please sign in to comment.