openai/openai-python

Public

mirrored from https://github.com/openai/openai-pythonAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
v0.26.0

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

openai/api_resources/edit.py

57lines · modecode

1import time
2
3from openai import util, error
4from openai.api_resources.abstract.engine_api_resource import EngineAPIResource
5from openai.error import TryAgain
6
7
8class Edit(EngineAPIResource):
9 OBJECT_NAME = "edits"
10
11 @classmethod
12 def create(cls, *args, **kwargs):
13 """
14 Creates a new edit for the provided input, instruction, and parameters.
15 """
16 start = time.time()
17 timeout = kwargs.pop("timeout", None)
18
19 api_type = kwargs.pop("api_type", None)
20 typed_api_type = cls._get_api_type_and_version(api_type=api_type)[0]
21 if typed_api_type in (util.ApiType.AZURE, util.ApiType.AZURE_AD):
22 raise error.InvalidAPIType(
23 "This operation is not supported by the Azure OpenAI API yet."
24 )
25
26 while True:
27 try:
28 return super().create(*args, **kwargs)
29 except TryAgain as e:
30 if timeout is not None and time.time() > start + timeout:
31 raise
32
33 util.log_info("Waiting for model to warm up", error=e)
34
35 @classmethod
36 async def acreate(cls, *args, **kwargs):
37 """
38 Creates a new edit for the provided input, instruction, and parameters.
39 """
40 start = time.time()
41 timeout = kwargs.pop("timeout", None)
42
43 api_type = kwargs.pop("api_type", None)
44 typed_api_type = cls._get_api_type_and_version(api_type=api_type)[0]
45 if typed_api_type in (util.ApiType.AZURE, util.ApiType.AZURE_AD):
46 raise error.InvalidAPIType(
47 "This operation is not supported by the Azure OpenAI API yet."
48 )
49
50 while True:
51 try:
52 return await super().acreate(*args, **kwargs)
53 except TryAgain as e:
54 if timeout is not None and time.time() > start + timeout:
55 raise
56
57 util.log_info("Waiting for model to warm up", error=e)
58