Skip to content

(Version 0.16.0) Add support for edit call #82

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions openai/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
Answer,
Classification,
Completion,
Edit,
Embedding,
Engine,
ErrorObject,
Expand Down Expand Up @@ -42,6 +43,7 @@
"Answer",
"Classification",
"Completion",
"Edit",
"Embedding",
"Engine",
"ErrorObject",
Expand Down
1 change: 1 addition & 0 deletions openai/api_resources/__init__.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
32 changes: 32 additions & 0 deletions openai/api_resources/edit.py
Original file line number Diff line number Diff line change
@@ -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)
2 changes: 1 addition & 1 deletion openai/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
VERSION = "0.15.0"
VERSION = "0.16.0"