Skip to content

Commit 54e9aad

Browse files
authored
Add docstrings for _models/completions (#124)
1 parent 0ca2b24 commit 54e9aad

File tree

8 files changed

+218
-7
lines changed

8 files changed

+218
-7
lines changed

src/yandex_cloud_ml_sdk/_models/completions/config.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,21 +19,42 @@
1919

2020

2121
class ReasoningMode(ProtoEnumBase, Enum):
22+
"""Enumeration for reasoning modes.
23+
24+
This class defines the various modes of reasoning that can be used
25+
in the model's configurations.
26+
"""
27+
#: indicates that the reasoning mode is unspecified
2228
REASONING_MODE_UNSPECIFIED = _m.REASONING_MODE_UNSPECIFIED
29+
#: indicates that reasoning is disabled
2330
DISABLED = _m.DISABLED
31+
#: indicates that reasoning is enabled but hidden
2432
ENABLED_HIDDEN = _m.ENABLED_HIDDEN
2533

26-
34+
#: type alias for reasoning mode representation
2735
ReasoningModeType = Union[int, str, ReasoningMode]
36+
#: type alias for completion tools
2837
CompletionTool: TypeAlias = FunctionTool
2938

3039

3140
@dataclass(frozen=True)
3241
class GPTModelConfig(BaseModelConfig):
42+
"""Configuration for the GPT model.
43+
44+
It holds the configuration settings for the GPT model,
45+
including parameters for generation and tool usage.
46+
"""
47+
#: a sampling temperature to use - higher values mean more random results; should be a double number between 0 (inclusive) and 1 (inclusive)
3348
temperature: float | None = None
49+
#: a maximum number of tokens to generate in the response
3450
max_tokens: int | None = None
51+
#: the mode of reasoning to apply during generation, allowing the model to perform internal reasoning before responding
3552
reasoning_mode: ReasoningModeType | None = None
53+
#: a format of the response returned by the model. Could be a JsonSchema, a JSON string, or a pydantic model
3654
response_format: ResponseType | None = None
55+
#: tools to use for completion. Can be a sequence or a single tool
3756
tools: Sequence[CompletionTool] | CompletionTool | None = None
57+
#: whether to allow parallel calls to tools during completion; defaults to 'true'
3858
parallel_tool_calls: bool | None = None
59+
#: the strategy for choosing tools: depending on this parameter, the model can always call some tool, call the specific tool or don't call any tool.
3960
tool_choice: ToolChoiceType | None = None

src/yandex_cloud_ml_sdk/_models/completions/function.py

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,38 @@
33
from typing_extensions import override
44

55
from yandex_cloud_ml_sdk._types.function import BaseModelFunction, ModelTypeT
6+
from yandex_cloud_ml_sdk._utils.doc import doc_from
67

78
from .model import AsyncGPTModel, GPTModel
89

910

1011
class BaseCompletions(BaseModelFunction[ModelTypeT]):
12+
"""
13+
A class for handling completions models.
14+
15+
It defines the core functionality for calling a model
16+
to generate completions based on the provided model name and version.
17+
"""
1118
@override
1219
def __call__(
1320
self,
1421
model_name: str,
1522
*,
1623
model_version: str = 'latest',
1724
) -> ModelTypeT:
25+
"""
26+
Create a model object to call for generating completions.
27+
28+
This method constructs the URI for the model based on the provided
29+
name and version. If the name contains ``://``, it is
30+
treated as a full URI. Otherwise, it looks up the model name in
31+
the well-known names dictionary. But after this, in any case,
32+
we construct a URI in the form ``gpt://<folder_id>/<model>/<version>``.
33+
34+
:param model_name: the name or URI of the model to call.
35+
:param model_version: the version of the model to use.
36+
Defaults to 'latest'.
37+
"""
1838
if '://' in model_name:
1939
uri = model_name
2040
else:
@@ -26,10 +46,10 @@ def __call__(
2646
uri=uri,
2747
)
2848

29-
49+
@doc_from(BaseCompletions)
3050
class Completions(BaseCompletions[GPTModel]):
3151
_model_type = GPTModel
3252

33-
53+
@doc_from(BaseCompletions)
3454
class AsyncCompletions(BaseCompletions[AsyncGPTModel]):
3555
_model_type = AsyncGPTModel

src/yandex_cloud_ml_sdk/_models/completions/langchain.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ def _transform_messages(history: list[BaseMessage]) -> list[TextMessageDict]:
5151

5252

5353
class ChatYandexGPT(BaseYandexLanguageModel[BaseGPTModel], BaseChatModel):
54+
"""Chat model for Yandex GPT integration.
55+
This class provides integration with the `LangChain <https://python.langchain.com/docs/introduction/>`_ library."""
5456
class Config:
5557
arbitrary_types_allowed = True
5658

src/yandex_cloud_ml_sdk/_models/completions/message.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,18 @@
1717

1818
@runtime_checkable
1919
class TextMessageWithToolCallsProtocol(TextMessageProtocol, Protocol):
20+
"""
21+
A class with a protocol which defines a text message structure with associated tool calls.
22+
The protocol extends the TextMessageProtocol and requires a list of tool calls.
23+
"""
2024
tool_calls: ToolCallList
2125

2226

2327
class FunctionResultMessageDict(TypedDict):
28+
"""
29+
A class with the TypedDict representing the structure of a function result message.
30+
The dictionary contains the role of the message sender and the results of tool calls.
31+
"""
2432
role: NotRequired[str]
2533
tool_results: Required[Iterable[ToolResultDictType]]
2634

@@ -31,12 +39,14 @@ class _ProtoMessageKwargs(TypedDict):
3139
tool_result_list: NotRequired[ProtoCompletionsToolResultList]
3240
tool_call_list: NotRequired[ProtoCompletionsToolCallList]
3341

34-
42+
#: a type alias for a message that can either be a standard message or a function result message.
3543
CompletionsMessageType = Union[MessageType, FunctionResultMessageDict]
44+
#: a type alias for input that can be either a single completion message or a collection (i.e. an iterable) of completion messages.
3645
MessageInputType = Union[CompletionsMessageType, Iterable[CompletionsMessageType]]
3746

3847

3948
def messages_to_proto(messages: MessageInputType) -> list[ProtoMessage]:
49+
""":meta private:"""
4050
msgs: tuple[CompletionsMessageType, ...] = coerce_tuple(
4151
messages,
4252
(dict, str, TextMessageProtocol), # type: ignore[arg-type]

0 commit comments

Comments
 (0)