From 877f57a2baea1766774d028b7fc976979ef83129 Mon Sep 17 00:00:00 2001 From: Jason Liu Date: Thu, 9 Nov 2023 09:22:47 -0500 Subject: [PATCH] hotfix --- README.md | 2 +- instructor/function_calls.py | 10 ++-------- instructor/patch.py | 6 ++---- pyproject.toml | 2 +- tests/test_patch.py | 3 --- 5 files changed, 6 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index abf1cf1..f181387 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ Built to interact solely with openai's function calling api from python. It's de ## Usage ```py hl_lines="5 13" -from openai import OpenAI() +from openai import OpenAI import instructor # Enables `response_model` diff --git a/instructor/function_calls.py b/instructor/function_calls.py index 1a40fc1..5f82a38 100644 --- a/instructor/function_calls.py +++ b/instructor/function_calls.py @@ -191,16 +191,10 @@ class OpenAISchema(BaseModel): Returns: cls (OpenAISchema): An instance of the class """ - message = completion["choices"][0]["message"] - - if throw_error: - assert "function_call" in message, "No function call detected" - assert ( - message["function_call"]["name"] == cls.openai_schema["name"] - ), "Function name does not match" + message = completion.choices[0].message return cls.model_validate_json( - message["function_call"]["arguments"], + message.function_call.arguments, context=validation_context, strict=strict, ) diff --git a/instructor/patch.py b/instructor/patch.py index c0ab0d8..579e4e6 100644 --- a/instructor/patch.py +++ b/instructor/patch.py @@ -122,7 +122,7 @@ def retry_sync( None, ) except (ValidationError, JSONDecodeError) as e: - kwargs["messages"].append(dict(**response.choices[0].message)) # type: ignore + kwargs["messages"].append(response.choices[0].message) # type: ignore kwargs["messages"].append( { "role": "user", @@ -139,7 +139,6 @@ def wrap_chatcompletion(func: Callable) -> Callable: @wraps(func) async def new_chatcompletion_async( - cls, response_model=None, validation_context=None, max_retries=1, @@ -161,7 +160,6 @@ def wrap_chatcompletion(func: Callable) -> Callable: @wraps(func) def new_chatcompletion_sync( - cls, response_model=None, validation_context=None, max_retries=1, @@ -183,7 +181,7 @@ def wrap_chatcompletion(func: Callable) -> Callable: wrapper_function = new_chatcompletion_async if is_async else new_chatcompletion_sync wrapper_function.__doc__ = OVERRIDE_DOCS - return classmethod(wrapper_function) + return wrapper_function def patch(client): diff --git a/pyproject.toml b/pyproject.toml index 026df7d..df14706 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "instructor" -version = "0.3.0" +version = "0.3.1" description = "Helper functions that allow us to improve openai's function_call ergonomics" authors = ["Jason Liu "] license = "MIT" diff --git a/tests/test_patch.py b/tests/test_patch.py index ed95dd8..a3a1ea9 100644 --- a/tests/test_patch.py +++ b/tests/test_patch.py @@ -1,13 +1,11 @@ from pydantic import BaseModel from openai import OpenAI -import pytest import instructor client = instructor.patch(OpenAI()) -@pytest.mark.skip("Not implemented") def test_runmodel(): class UserExtract(BaseModel): name: str @@ -27,7 +25,6 @@ def test_runmodel(): ), "The raw response should be available from OpenAI" -@pytest.mark.skip("Not implemented") def test_runmodel_validator(): from pydantic import field_validator