Skip to content

Commit

Permalink
feat(base models): now all models encapsulates response object.
Browse files Browse the repository at this point in the history
  • Loading branch information
ovuruska committed Apr 29, 2024
1 parent a6291f7 commit b03bb15
Show file tree
Hide file tree
Showing 10 changed files with 16 additions and 15 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ jobs:
pip install -r requirements.txt
pip install -r requirements-dev.txt
- name: Run lint check
- name: Run type check
run: |
black --check --verbose deepinfra
mypy --install-types deepinfra --non-interactive --verbose
- name: Run type check
- name: Run lint check
run: |
mypy --install-types deepinfra --non-interactive --verbose
black --check --verbose deepinfra
2 changes: 1 addition & 1 deletion deepinfra/models/base/automatic_speech_recognition.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ def generate(self, body) -> AutomaticSpeechRecognitionResponse:
response = self.client.post(
form_data, {"headers": {"content-type": form_data.content_type}}
)
return response.json()
return AutomaticSpeechRecognitionResponse(**response.json())
4 changes: 2 additions & 2 deletions deepinfra/models/base/embeddings.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ class Embeddings(BaseModel):
@docs Check the available models at https://deepinfra.com/models/embeddings
"""

def generate(self, body: EmbeddingsRequest) -> EmbeddingsResponse:
def generate(self, body) -> EmbeddingsResponse:
"""
Generates embeddings.
:param body:
:return:
"""
response = self.client.post(body)
return response
return EmbeddingsResponse(**response.json())
4 changes: 2 additions & 2 deletions deepinfra/models/base/text_generation.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ class TextGeneration(BaseModel):
@docs Check the available models at https://deepinfra.com/models/text-generation
"""

def generate(self, body: TextGenerationRequest) -> TextGenerationResponse:
def generate(self, body: dict) -> TextGenerationResponse:
"""
Generates text.
:param body:
:return:
"""
response = self.client.post(body)
return response
return TextGenerationResponse(**response.json())
3 changes: 2 additions & 1 deletion deepinfra/models/base/text_to_image.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from deepinfra.models.base import BaseModel
from deepinfra.types.text_to_image import TextToImageResponse


class TextToImage(BaseModel):
Expand All @@ -15,4 +16,4 @@ def generate(self, input):
"""
body = {"input": input}
response = self.client.post(body)
return response
return TextToImageResponse(**response.json())
2 changes: 0 additions & 2 deletions deepinfra/types/image_generation/__init__.py

This file was deleted.

2 changes: 2 additions & 0 deletions deepinfra/types/text_to_image/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from .request import TextToImageRequest
from .response import TextToImageResponse
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@


@dataclass
class ImageGenerationRequest:
class TextToImageRequest:
prompt: str
negative_prompt: Optional[str] = None
image: Optional[str] = None
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class Metrics:


@dataclass
class ImageGenerationResponse:
class TextToImageResponse:
request_id: str
inference_status: InferenceStatus
input: Dict
Expand Down
2 changes: 1 addition & 1 deletion deepinfra/utils/form_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class FormDataUtils:
"""

@staticmethod
def get_form_data(data, blob_keys: Optional[List[str]] = None):
def get_form_data(data: dict, blob_keys: Optional[List[str]] = None):
"""
Creates a MultipartEncoder object from the data.
:param data:
Expand Down

0 comments on commit b03bb15

Please sign in to comment.