Skip to content

Add docstrings for _models/image_generation#115

Merged
vhaldemar merged 19 commits intoyandex-cloud:masterfrom
Mandzhi:new-branch-4
Jul 2, 2025
Merged

Add docstrings for _models/image_generation#115
vhaldemar merged 19 commits intoyandex-cloud:masterfrom
Mandzhi:new-branch-4

Conversation

@Mandzhi
Copy link
Copy Markdown
Collaborator

@Mandzhi Mandzhi commented Jun 26, 2025

First version is ready for review

@Mandzhi Mandzhi changed the title Add docstrings for _models/image_generation/function.py Add docstrings for _models/image_generation/function.py and _models/image_generation/message.py Jun 29, 2025
Copy link
Copy Markdown
Collaborator

@vhaldemar vhaldemar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Я правильно понял, что ты в этом ПР со всеми файлами директории придешь?
И пока он не финальный?


class BaseImageGeneration(BaseModelFunction[ModelTypeT]):
"""
Base class for image generation models.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Это не бейз класс.
Точнее это бейз класс, но ты-то копируешь эту строчку через doc_from


Returns a model's object through which requests to the backend are made.

>>> model = sdk.models.image_generation('yandex-art') #this is how the model is created
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Кажется, оступ лишний в 4 пробела

#this is how the model is created -> # this is how the model is created

(два пробела перед # и один после, так принято)

@dataclass(frozen=True)
class ImageMessage:
"""
This class represents an image message with optional weight.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

optional weight field, мне кажется



def messages_to_proto(messages: ImageMessageInputType) -> list[ProtoMessage]:
"""
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Это не надо, это внутреннее.
:meta private:

"""
text: str


Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

зато надо ImageMessageType и ImageMessageInputType

@vhaldemar vhaldemar changed the title Add docstrings for _models/image_generation/function.py and _models/image_generation/message.py Add docstrings for _models/image_generation Jun 30, 2025
@dataclass(frozen=True)
class ImageMessage:
"""
This class represents an image message with optional weight field.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Что такое image message?)
На самом деле, это просто структура сообщения, которую модель ожидает от пользователя.
То есть "message for using in image generation models", ниже тоже самое



ImageMessageType = Union[ImageMessage, ImageMessageDict, AnyMessage, str]
"""Type alias for different types of image messages that can be processed."""
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Вообще, так, наверное, сработает, но я ожидал #: над переменной

class BaseImageGenerationModel(
ModelAsyncMixin[ImageGenerationModelConfig, ImageGenerationModelResult, OperationTypeT],
):
"""A class for image generation models."""
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Нет, это уже класс одной, конкретной модели.
Можно дописать, что она в себе инкапсулирует УРИ модели и конфигурацию

:param seed: a random seed for generation.
:param width_ratio: the width ratio for the generated image.
:param height_ratio: the height ratio for the generated image.
:param mime_type: the MIME type of the generated image.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Здесь бы не помешала бы ссылка на доку про то, а какие MIME-типы мы умеем принимать

and returns an operation representing the ongoing image generation process.

:param messages: the input messages for image generation.
:param timeout: the timeout for the operation in seconds.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Вот только тут слово "операция" конфликтует со словом "операция" выше.
Это разные операции))
В таймауте имеется ввиду - операция http-запрос по созданию объекта Операции.


@dataclass(frozen=True, repr=False)
class ImageGenerationModelResult(BaseResult):
"""This class represents the result of an image generation model."""
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This class represents the result of an image generation model inference

Как мне кажется


@classmethod
def _from_proto(cls, *, proto: ProtoMessage, sdk: BaseSDK) -> Self: # pylint: disable=unused-argument
""":meta private:"""
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Вот такие методы, начинающиеся с _, их не надо помечать

)

def _repr_jpeg_(self) -> bytes | None:
""":meta private:"""
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

А вот это, как ни странно, наоборот, именно _repr_smth_ - это как бы публичные методы.
Напиши им пока meta public, я не уверен, скушает ли это сфинкс.
А связанная ссылка про эти методы - https://ipython.readthedocs.io/en/stable/config/integrating.html#rich-display

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Сделай :meta public:, пожалуйста

return None

def __repr__(self) -> str:
""":meta private:"""
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

__repr__ просто не трогай)

text: str


#: type alias for different types of image messages that can be processed
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

of messages that can be processed by image generation models

)

def _repr_jpeg_(self) -> bytes | None:
""":meta private:"""
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Сделай :meta public:, пожалуйста

@vhaldemar vhaldemar merged commit 37a1118 into yandex-cloud:master Jul 2, 2025
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants