From 1056881f207e596d5bd6e4d9f0d42c1ca5c233df Mon Sep 17 00:00:00 2001 From: Payman Hodaie Date: Tue, 9 Jan 2024 09:44:58 -0500 Subject: [PATCH] Update function call mode and add deprecation warning (#337) --- instructor/function_calls.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/instructor/function_calls.py b/instructor/function_calls.py index 1bb87dd..83f037c 100644 --- a/instructor/function_calls.py +++ b/instructor/function_calls.py @@ -4,7 +4,7 @@ from pydantic import BaseModel, create_model from instructor.exceptions import IncompleteOutputException import enum - +import warnings class Mode(enum.Enum): """The mode to use for patching the client""" @@ -15,6 +15,15 @@ class Mode(enum.Enum): MD_JSON: str = "markdown_json_mode" JSON_SCHEMA: str = "json_schema_mode" + def __new__(cls, value): + member = object.__new__(cls) + member._value_ = value + + # Deprecation warning for FUNCTIONS + if value == "function_call": + warnings.warn("FUNCTIONS is deprecated and will be removed in future versions", DeprecationWarning, stacklevel=2) + + return member class OpenAISchema(BaseModel): """ @@ -106,7 +115,7 @@ class OpenAISchema(BaseModel): completion, validation_context=None, strict: bool = None, - mode: Mode = Mode.FUNCTIONS, + mode: Mode = Mode.TOOLS, stream_multitask: bool = False, ): """Execute the function from the response of an openai chat completion @@ -167,7 +176,7 @@ class OpenAISchema(BaseModel): completion, validation_context=None, strict: bool = None, - mode: Mode = Mode.FUNCTIONS, + mode: Mode = Mode.TOOLS, stream_multitask: bool = False, ): """Execute the function from the response of an openai chat completion