diff --git a/stabilityai/__init__.py b/stabilityai/__init__.py index 5c4105c..7863915 100644 --- a/stabilityai/__init__.py +++ b/stabilityai/__init__.py @@ -1 +1 @@ -__version__ = "1.0.1" +__version__ = "1.0.2" diff --git a/stabilityai/client.py b/stabilityai/client.py index bec1e5a..97fe164 100644 --- a/stabilityai/client.py +++ b/stabilityai/client.py @@ -13,7 +13,7 @@ from stabilityai.constants import ( DEFAULT_STABILITY_CLIENT_VERSION, DEFAULT_UPSCALE_ENGINE, ) -from stabilityai.exceptions import YouNeedToUseAContextManager +from stabilityai.exceptions import ThisFunctionRequiresAPrompt, YouNeedToUseAContextManager from stabilityai.models import ( AccountResponseBody, BalanceResponseBody, @@ -127,7 +127,7 @@ class AsyncStabilityClient: text_prompt: Optional[SingleTextPrompt] ): if not bool(text_prompt) ^ bool(text_prompts): - raise RuntimeError( + raise ThisFunctionRequiresAPrompt( textwrap.dedent( f"""\ You must provide one of text_prompt and text_prompts. @@ -203,6 +203,27 @@ class AsyncStabilityClient: return TextToImageResponseBody.parse_obj(await res.json()) + async def text_to_image_simple( + self, + prompt: str, + style_preset: Optional[StylePreset] = StylePreset.digital_art, + n: int = 1, + size: str = "512x512", + ): + """ + An OpenAI SDK style call that makes it easy to migrate. + """ + + dim = int(size.split("x")[0]) + + return await self.text_to_image( + text_prompts=[TextPrompt(text=prompt)], + style_preset=style_preset, + samples=n, + width=dim, + height=dim, + ) + @validate_arguments async def image_to_image( self, diff --git a/stabilityai/exceptions.py b/stabilityai/exceptions.py index 273a9c1..8a2458e 100644 --- a/stabilityai/exceptions.py +++ b/stabilityai/exceptions.py @@ -1,2 +1,6 @@ -class YouNeedToUseAContextManager(Exception): +class YouNeedToUseAContextManager(ValueError): + pass + + +class ThisFunctionRequiresAPrompt(ValueError): pass