Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed May 16, 2024
1 parent e5b9034 commit 5e253d6
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions packages/jupyter-ai-magics/jupyter_ai_magics/providers.py
Original file line number Diff line number Diff line change
Expand Up @@ -658,7 +658,7 @@ def _call(
)

try:
if "generated_text" in str(response):
if "generated_text" in str(response):
# text2 text or text-generation task
response_text = json.loads(response.decode())[0]["generated_text"]
# Maybe the generation has stopped at one of the stop sequences:
Expand All @@ -685,10 +685,13 @@ def _call(
buffer = io.BytesIO()
image.save(buffer, format=imageFormat)
# # Encode image data to Base64 bytes, then decode bytes to str
return mimeType + ";base64," + base64.b64encode(buffer.getvalue()).decode()
except:
raise ValueError("Task not supported, only text-generation and text-to-image tasks are valid.")

return (
mimeType + ";base64," + base64.b64encode(buffer.getvalue()).decode()
)
except:
raise ValueError(
"Task not supported, only text-generation and text-to-image tasks are valid."
)

async def _acall(self, *args, **kwargs) -> Coroutine[Any, Any, str]:
return await self._call_in_executor(*args, **kwargs)
Expand Down

0 comments on commit 5e253d6

Please sign in to comment.