-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
5 high priosdxl #15
Open
ovuruska
wants to merge
10
commits into
main
Choose a base branch
from
5-high-priosdxl
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
5 high priosdxl #15
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
06c2215
Merge branch '11-unit-tests-pipeline' into 5-high-priosdxl
ovuruska 9b83c9f
Added tests
ovuruska 833de66
feat(base models): SDXL and Text to image
ovuruska 60c181f
refactor(SDXL): better reusability
ovuruska 8322a65
refactor(sdxl): removed redundant indent
ovuruska 198f49a
doc(SDXL): fixed
ovuruska 60401bf
revert(backoff)
ovuruska 831bdfb
ref(lint)
ovuruska fe44774
Merge branch 'main' into 5-high-priosdxl
ovuruska dd1bb95
fix(annottation)
ovuruska File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
from .client import MAX_RETRIES, USER_AGENT, INITIAL_BACKOFF, SUBSEQUENT_BACKOFF | ||
from .models import SDXL |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
SDXL = "stability-ai/sdxl" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
from .max_retries_exceeded import MaxRetriesExceededError | ||
from .max_retries_exceeded import MaxRetriesExceededError |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import json | ||
|
||
from black import Optional | ||
|
||
from deepinfra.models.base import BaseModel | ||
from deepinfra.constants import SDXL | ||
|
||
|
||
class Sdxl(BaseModel): | ||
""" | ||
Class for the SDXL model. | ||
@docs Check the model at https://deepinfra.com/stability-ai/sdxl/api | ||
""" | ||
|
||
def __init__(self, api_token: Optional[str] = None): | ||
super().__init__(SDXL, api_token) | ||
|
||
def generate(self, body: dict): | ||
""" | ||
Generates an image. | ||
:param input: | ||
:return: | ||
""" | ||
response = self.client.post(json.dumps(body)) | ||
return response.json() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
from dataclasses import dataclass | ||
|
||
from deepinfra.types.text_to_image import TextToImageRequest | ||
|
||
|
||
@dataclass | ||
class SdxlRequest: | ||
input: TextToImageRequest |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
from typing import List | ||
|
||
from dataclasses import dataclass | ||
|
||
|
||
@dataclass | ||
class SdxlResponseItem: | ||
format: str | ||
type: str | ||
|
||
|
||
@dataclass | ||
class SdxlResponse: | ||
items: List[SdxlResponseItem] | ||
title: str | ||
type: str |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
setuptools | ||
setuptools-scm | ||
requests | ||
dataclasses | ||
requests-toolbelt | ||
requests-toolbelt | ||
pydantic |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import unittest | ||
from unittest.mock import patch | ||
|
||
from deepinfra import TextToImage | ||
from deepinfra.constants import SDXL | ||
from deepinfra.models.base.sdxl import Sdxl | ||
|
||
model_name = SDXL | ||
api_key = "API KEY" | ||
|
||
|
||
class TestSdxl(unittest.TestCase): | ||
@patch("requests.post") | ||
def test_generate(self, mock_post): | ||
mock_post.return_value.status_code = 200 | ||
mock_post.return_value.json.return_value = {"image": "image data"} | ||
|
||
text_to_image = Sdxl(api_key) | ||
body = {"input": {"prompt": "Hello, World!"}} | ||
response = text_to_image.generate(body) | ||
|
||
called_args, called_kwargs = mock_post.call_args | ||
url = called_args[0] | ||
header = called_kwargs["headers"] | ||
self.assertEqual(url, f"https://api.deepinfra.com/v1/inference/{model_name}") | ||
|
||
self.assertEqual(response["image"], "image data") | ||
self.assertEqual(header["Authorization"], f"Bearer {api_key}") |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess this steps on top of the other PR, so the same arguments apply. The generate method absolutely needs annotations on the input (
body
) and response.Now I see the code is blocking (i.e not async). We should provide sync and async variants in that case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for annotation, I got an idea which may be scope of another PR.
Example usage
`
request = EmbeddingsRequest(inputs=["Hello World!"])
model = Embeddings()
model.generate(request)
`
By creating a request class for each base class, we can
1-) Validate the input before request is sent.
2-) Increase iteration speed for our users by improving code completion aspects.