Skip to content

Commit 63cc289

Browse files
hpondehallacy
andauthored
(Version 0.15.0) Add support for edit call (#82)
* Add support for edit call * Add version bump (0.16.0) Co-authored-by: hallacy <[email protected]>
1 parent db4750c commit 63cc289

File tree

4 files changed

+36
-1
lines changed

4 files changed

+36
-1
lines changed

openai/__init__.py

+2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
Answer,
1010
Classification,
1111
Completion,
12+
Edit,
1213
Embedding,
1314
Engine,
1415
ErrorObject,
@@ -42,6 +43,7 @@
4243
"Answer",
4344
"Classification",
4445
"Completion",
46+
"Edit",
4547
"Embedding",
4648
"Engine",
4749
"ErrorObject",

openai/api_resources/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from openai.api_resources.answer import Answer # noqa: F401
22
from openai.api_resources.classification import Classification # noqa: F401
33
from openai.api_resources.completion import Completion # noqa: F401
4+
from openai.api_resources.edit import Edit # noqa: F401
45
from openai.api_resources.embedding import Embedding # noqa: F401
56
from openai.api_resources.engine import Engine # noqa: F401
67
from openai.api_resources.error_object import ErrorObject # noqa: F401

openai/api_resources/edit.py

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import time
2+
3+
from openai import util
4+
from openai.api_resources.abstract.engine_api_resource import EngineAPIResource
5+
from openai.error import InvalidRequestError, TryAgain
6+
7+
8+
class Edit(EngineAPIResource):
9+
engine_required = False
10+
OBJECT_NAME = "edit"
11+
12+
@classmethod
13+
def create(cls, *args, **kwargs):
14+
"""
15+
Creates a new edit for the provided input, instruction, and parameters.
16+
"""
17+
start = time.time()
18+
timeout = kwargs.pop("timeout", None)
19+
if kwargs.get("model", None) is None and kwargs.get("engine", None) is None:
20+
raise InvalidRequestError(
21+
"Must provide an 'engine' or 'model' parameter to create an Edit.",
22+
param="engine",
23+
)
24+
25+
while True:
26+
try:
27+
return super().create(*args, **kwargs)
28+
except TryAgain as e:
29+
if timeout is not None and time.time() > start + timeout:
30+
raise
31+
32+
util.log_info("Waiting for model to warm up", error=e)

openai/version.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
VERSION = "0.15.0"
1+
VERSION = "0.16.0"

0 commit comments

Comments
 (0)