From a21caf64ced210fafae9aaa5c0d8faf01a3dcd85 Mon Sep 17 00:00:00 2001 From: Krista Pratico Date: Mon, 19 Jun 2023 18:21:08 -0700 Subject: [PATCH 1/7] add edit apis --- openai/client.py | 44 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) diff --git a/openai/client.py b/openai/client.py index 0eef61f0ce..75d1f623c1 100644 --- a/openai/client.py +++ b/openai/client.py @@ -371,7 +371,49 @@ async def aimage_edit( response_format=response_format, user=user, ) - return typing.cast(openai.Image, await openai.Image.acreate_edit(**kwargs)) + return cast(openai.Image, await openai.Image.acreate_edit(**kwargs)) + + def edit( + self, + instruction: str, + *, + input: str = ..., + n: int = ..., + temperature: float = ..., + top_p: float = ..., + **kwargs, + ): + self._populate_args( + kwargs, + instruction=instruction, + input=input, + n=n, + temperature=temperature, + top_p=top_p, + ) + self._normalize_model(kwargs) + return cast(openai.Edit, openai.Edit.create(**kwargs)) + + async def aedit( + self, + instruction: str, + *, + input: str = ..., + n: int = ..., + temperature: float = ..., + top_p: float = ..., + **kwargs, + ): + self._populate_args( + kwargs, + instruction=instruction, + input=input, + n=n, + temperature=temperature, + top_p=top_p, + ) + self._normalize_model(kwargs) + return cast(openai.Edit, await openai.Edit.create(**kwargs)) if __name__ == "__main__": From ed0ff4da9606ffc9ad61511f0c08e2305c3e418d Mon Sep 17 00:00:00 2001 From: Krista Pratico Date: Mon, 19 Jun 2023 18:29:08 -0700 Subject: [PATCH 2/7] add moderation apis --- openai/client.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/openai/client.py b/openai/client.py index 75d1f623c1..571aed9c9d 100644 --- a/openai/client.py +++ b/openai/client.py @@ -415,6 +415,29 @@ async def aedit( self._normalize_model(kwargs) return cast(openai.Edit, await openai.Edit.create(**kwargs)) + def moderation( + self, + input: Union[str, Iterable[str]], + **kwargs, + ): + self._populate_args( + kwargs, + input=input, + ) + self._normalize_model(kwargs) + return cast(openai.Moderation, openai.Moderation.create(**kwargs)) + + async def amoderation( + self, + input: Union[str, Iterable[str]], + **kwargs, + ): + self._populate_args( + kwargs, + input=input, + ) + self._normalize_model(kwargs) + return cast(openai.Moderation, await openai.Moderation.create(**kwargs)) if __name__ == "__main__": client = OpenAIClient( From 673eaad9b07cb06a85feb142bf6a1b7b4e1d58a4 Mon Sep 17 00:00:00 2001 From: Krista Pratico Date: Mon, 19 Jun 2023 18:38:38 -0700 Subject: [PATCH 3/7] add audio apis --- openai/client.py | 80 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) diff --git a/openai/client.py b/openai/client.py index 571aed9c9d..65a3248388 100644 --- a/openai/client.py +++ b/openai/client.py @@ -439,6 +439,86 @@ async def amoderation( self._normalize_model(kwargs) return cast(openai.Moderation, await openai.Moderation.create(**kwargs)) + def transcribe_audio( + self, + file: Union[bytes, BinaryIO], + *, + prompt: str = ..., + response_format: str = ..., + temperature: float = ..., + language: str = ..., + **kwargs, + ): + self._populate_args( + kwargs, + file=file, + prompt=prompt, + response_format=response_format, + temperature=temperature, + language=language + ) + self._normalize_model(kwargs) + return cast(openai.Audio, openai.Audio.transcribe(**kwargs)) + + async def atranscribe_audio( + self, + file: Union[bytes, BinaryIO], + *, + prompt: str = ..., + response_format: str = ..., + temperature: float = ..., + language: str = ..., + **kwargs, + ): + self._populate_args( + kwargs, + file=file, + prompt=prompt, + response_format=response_format, + temperature=temperature, + language=language + ) + self._normalize_model(kwargs) + return cast(openai.Audio, await openai.Audio.transcribe(**kwargs)) + + def translate_audio( + self, + file: Union[bytes, BinaryIO], + *, + prompt: str = ..., + response_format: str = ..., + temperature: float = ..., + **kwargs, + ): + self._populate_args( + kwargs, + file=file, + prompt=prompt, + response_format=response_format, + temperature=temperature, + ) + self._normalize_model(kwargs) + return cast(openai.Audio, openai.Audio.translate(**kwargs)) + + async def atranslate_audio( + self, + file: Union[bytes, BinaryIO], + *, + prompt: str = ..., + response_format: str = ..., + temperature: float = ..., + **kwargs, + ): + self._populate_args( + kwargs, + file=file, + prompt=prompt, + response_format=response_format, + temperature=temperature, + ) + self._normalize_model(kwargs) + return cast(openai.Audio, await openai.Audio.translate(**kwargs)) + if __name__ == "__main__": client = OpenAIClient( api_base="https://achand-openai-0.openai.azure.com/", From 21ac49e588b0201a5fb6fd64dfd863ae5e22e718 Mon Sep 17 00:00:00 2001 From: Krista Pratico Date: Thu, 22 Jun 2023 12:28:59 -0700 Subject: [PATCH 4/7] Update openai/client.py Co-authored-by: Johan Stenberg (MSFT) --- openai/client.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openai/client.py b/openai/client.py index 65a3248388..18df7d37a5 100644 --- a/openai/client.py +++ b/openai/client.py @@ -413,7 +413,7 @@ async def aedit( top_p=top_p, ) self._normalize_model(kwargs) - return cast(openai.Edit, await openai.Edit.create(**kwargs)) + return cast(openai.Edit, await openai.Edit.acreate(**kwargs)) def moderation( self, From 755bcaacfa915b996f6d3cd6187295aa2e0ca1f4 Mon Sep 17 00:00:00 2001 From: Krista Pratico Date: Thu, 22 Jun 2023 12:29:06 -0700 Subject: [PATCH 5/7] Update openai/client.py Co-authored-by: Johan Stenberg (MSFT) --- openai/client.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openai/client.py b/openai/client.py index 18df7d37a5..cfdeb5b5b2 100644 --- a/openai/client.py +++ b/openai/client.py @@ -437,7 +437,7 @@ async def amoderation( input=input, ) self._normalize_model(kwargs) - return cast(openai.Moderation, await openai.Moderation.create(**kwargs)) + return cast(openai.Moderation, await openai.Moderation.acreate(**kwargs)) def transcribe_audio( self, From 03265845dc3eabd12520159b15fe574abb07a56f Mon Sep 17 00:00:00 2001 From: Krista Pratico Date: Thu, 22 Jun 2023 12:29:29 -0700 Subject: [PATCH 6/7] Update openai/client.py Co-authored-by: Johan Stenberg (MSFT) --- openai/client.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openai/client.py b/openai/client.py index cfdeb5b5b2..158f2cca69 100644 --- a/openai/client.py +++ b/openai/client.py @@ -479,7 +479,7 @@ async def atranscribe_audio( language=language ) self._normalize_model(kwargs) - return cast(openai.Audio, await openai.Audio.transcribe(**kwargs)) + return cast(openai.Audio, await openai.Audio.atranscribe(**kwargs)) def translate_audio( self, From 5343a5f98674b6a53b1f1f72eca02459386d3218 Mon Sep 17 00:00:00 2001 From: Krista Pratico Date: Thu, 22 Jun 2023 12:29:34 -0700 Subject: [PATCH 7/7] Update openai/client.py Co-authored-by: Johan Stenberg (MSFT) --- openai/client.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openai/client.py b/openai/client.py index 158f2cca69..f7e754d079 100644 --- a/openai/client.py +++ b/openai/client.py @@ -517,7 +517,7 @@ async def atranslate_audio( temperature=temperature, ) self._normalize_model(kwargs) - return cast(openai.Audio, await openai.Audio.translate(**kwargs)) + return cast(openai.Audio, await openai.Audio.atranslate(**kwargs)) if __name__ == "__main__": client = OpenAIClient(