From e3c46ffb2439422e047f9a47eae174895d59361d Mon Sep 17 00:00:00 2001 From: hallacy Date: Tue, 15 Mar 2022 10:11:33 -0700 Subject: [PATCH] (Version 0.15.0) Add support for edit call * Add support for edit call * Add version bump (0.16.0) --- openai/__init__.py | 2 ++ openai/api_resources/__init__.py | 1 + openai/api_resources/edit.py | 32 ++++++++++++++++++++++++++++++++ openai/version.py | 2 +- 4 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 openai/api_resources/edit.py diff --git a/openai/__init__.py b/openai/__init__.py index dd9d163fc7..59d717b4cc 100644 --- a/openai/__init__.py +++ b/openai/__init__.py @@ -9,6 +9,7 @@ Answer, Classification, Completion, + Edit, Embedding, Engine, ErrorObject, @@ -42,6 +43,7 @@ "Answer", "Classification", "Completion", + "Edit", "Embedding", "Engine", "ErrorObject", diff --git a/openai/api_resources/__init__.py b/openai/api_resources/__init__.py index 7f4731bacf..393c714be7 100644 --- a/openai/api_resources/__init__.py +++ b/openai/api_resources/__init__.py @@ -1,6 +1,7 @@ from openai.api_resources.answer import Answer # noqa: F401 from openai.api_resources.classification import Classification # noqa: F401 from openai.api_resources.completion import Completion # noqa: F401 +from openai.api_resources.edit import Edit # noqa: F401 from openai.api_resources.embedding import Embedding # noqa: F401 from openai.api_resources.engine import Engine # noqa: F401 from openai.api_resources.error_object import ErrorObject # noqa: F401 diff --git a/openai/api_resources/edit.py b/openai/api_resources/edit.py new file mode 100644 index 0000000000..e4378eec60 --- /dev/null +++ b/openai/api_resources/edit.py @@ -0,0 +1,32 @@ +import time + +from openai import util +from openai.api_resources.abstract.engine_api_resource import EngineAPIResource +from openai.error import InvalidRequestError, TryAgain + + +class Edit(EngineAPIResource): + engine_required = False + OBJECT_NAME = "edit" + + @classmethod + def create(cls, *args, **kwargs): + """ + Creates a new edit for the provided input, instruction, and parameters. + """ + start = time.time() + timeout = kwargs.pop("timeout", None) + if kwargs.get("model", None) is None and kwargs.get("engine", None) is None: + raise InvalidRequestError( + "Must provide an 'engine' or 'model' parameter to create an Edit.", + param="engine", + ) + + while True: + try: + return super().create(*args, **kwargs) + except TryAgain as e: + if timeout is not None and time.time() > start + timeout: + raise + + util.log_info("Waiting for model to warm up", error=e) diff --git a/openai/version.py b/openai/version.py index 7376d84f5a..99977b4919 100644 --- a/openai/version.py +++ b/openai/version.py @@ -1 +1 @@ -VERSION = "0.15.0" +VERSION = "0.16.0"