mmar-mapi 1.0.6__py3-none-any.whl → 1.0.7__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of mmar-mapi might be problematic. Click here for more details.

mmar_mapi/__init__.py CHANGED
@@ -1,12 +1,47 @@
1
- __version__ = "5.2.4"
2
-
3
1
  from .file_storage import FileStorage, ResourceId
4
2
  from .models.base import Base
5
- from .models.base_config_models import GigaChatConfig
6
- from .models.chat import Chat, Context, ChatMessage, AIMessage, HumanMessage, MiscMessage, make_content, Content
3
+ from .models.chat import (
4
+ Chat,
5
+ Context,
6
+ ChatMessage,
7
+ AIMessage,
8
+ HumanMessage,
9
+ MiscMessage,
10
+ make_content,
11
+ Content,
12
+ BaseMessage,
13
+ )
7
14
  from .models.chat_item import ChatItem, OuterContextItem, InnerContextItem, ReplicaItem
8
15
  from .models.enums import MTRSLabelEnum, DiagnosticsXMLTagEnum, MTRSXMLTagEnum, DoctorChoiceXMLTagEnum
9
16
  from .models.tracks import TrackInfo, DomainInfo
10
17
  from .models.widget import Widget
11
18
  from .utils import make_session_id
12
19
  from .xml_parser import XMLParser
20
+
21
+ __all__ = [
22
+ "AIMessage",
23
+ "Base",
24
+ "BaseMessage",
25
+ "Chat",
26
+ "ChatItem",
27
+ "ChatMessage",
28
+ "Content",
29
+ "Context",
30
+ "DiagnosticsXMLTagEnum",
31
+ "DoctorChoiceXMLTagEnum",
32
+ "DomainInfo",
33
+ "FileStorage",
34
+ "HumanMessage",
35
+ "InnerContextItem",
36
+ "MTRSLabelEnum",
37
+ "MTRSXMLTagEnum",
38
+ "MiscMessage",
39
+ "OuterContextItem",
40
+ "ReplicaItem",
41
+ "ResourceId",
42
+ "TrackInfo",
43
+ "Widget",
44
+ "XMLParser",
45
+ "make_content",
46
+ "make_session_id",
47
+ ]
mmar_mapi/models/chat.py CHANGED
@@ -1,13 +1,13 @@
1
1
  import warnings
2
+ from collections.abc import Callable
2
3
  from copy import deepcopy
3
4
  from datetime import datetime
4
5
  from typing import Any, Literal, TypeVar
5
- from collections.abc import Callable
6
6
 
7
7
  from mmar_mapi.models.chat_item import ChatItem, ReplicaItem, OuterContextItem
8
8
  from mmar_mapi.models.widget import Widget
9
9
  from mmar_mapi.type_union import TypeUnion
10
- from pydantic import Field, ValidationError, Extra
10
+ from pydantic import Field, ValidationError
11
11
 
12
12
  from .base import Base
13
13
 
@@ -146,10 +146,6 @@ class BaseMessage(Base):
146
146
  def widget(self) -> Widget | None:
147
147
  return _get_widget(self.content)
148
148
 
149
- @staticmethod
150
- def DATETIME_FORMAT() -> str:
151
- return _DT_FORMAT
152
-
153
149
  def with_now_datetime(self):
154
150
  return self.model_copy(update=dict(date_time=now_pretty()))
155
151
 
@@ -161,6 +157,21 @@ class BaseMessage(Base):
161
157
  def is_human(self):
162
158
  return self.type == "human"
163
159
 
160
+ @staticmethod
161
+ def DATETIME_FORMAT() -> str:
162
+ return _DT_FORMAT
163
+
164
+ @staticmethod
165
+ def find_resource_id(msg: "BaseMessage", ext: str | None = None, type: str=None) -> str | None:
166
+ resource_id = msg.resource_id
167
+ if type and type != msg.type:
168
+ return None
169
+ if not resource_id:
170
+ return None
171
+ if ext and not resource_id.endswith(ext):
172
+ return None
173
+ return resource_id
174
+
164
175
 
165
176
  class HumanMessage(BaseMessage):
166
177
  type: Literal["human"] = "human"
@@ -182,15 +193,18 @@ class MiscMessage(BaseMessage):
182
193
  ChatMessage = TypeUnion[HumanMessage, AIMessage, MiscMessage]
183
194
 
184
195
 
196
+ def find_in_messages(messages: list[ChatMessage], func: Callable[[ChatMessage], T | None]) -> T | None:
197
+ return next(filter(None, map(func, messages)), None)
198
+
199
+
185
200
  class Chat(Base):
186
201
  context: Context = Field(default_factory=Context)
187
202
  messages: list[ChatMessage] = Field(default_factory=list)
188
203
 
189
- class Config:
190
- extra = Extra.ignore
204
+ model_config = {"extra": "ignore"}
191
205
 
192
206
  def __init__(self, **data):
193
- extra_fields = set(data.keys()) - set(self.__fields__.keys())
207
+ extra_fields = set(data.keys()) - set(type(self).model_fields.keys())
194
208
  if extra_fields:
195
209
  warnings.warn(f"Chat initialization: extra fields will be ignored: {extra_fields}")
196
210
  super().__init__(**data)
@@ -222,6 +236,12 @@ class Chat(Base):
222
236
  return message.state
223
237
  return default
224
238
 
239
+ def find_in_messages(self, func: Callable[[ChatMessage], T | None]) -> T | None:
240
+ return find_in_messages(self.messages, func)
241
+
242
+ def rfind_in_messages(self, func: Callable[[ChatMessage], T | None]) -> T | None:
243
+ return find_in_messages(self.messages[::-1], func)
244
+
225
245
 
226
246
  def make_content(
227
247
  text: str | None = None,
@@ -1,5 +1,6 @@
1
1
  from typing import Self, Literal
2
2
 
3
+ from more_itertools import chunked
3
4
  from pydantic import BaseModel, model_validator
4
5
 
5
6
 
@@ -20,3 +21,14 @@ class Widget(BaseModel):
20
21
  continue
21
22
  raise ValueError(f"Expected buttons like `<callback>:<caption>`, found: {btn}")
22
23
  return self
24
+
25
+ @staticmethod
26
+ def make_inline_buttons(ibuttons: dict[str, str], by=1) -> "Widget":
27
+ return _make_inline_buttons(ibuttons=ibuttons, by=by)
28
+
29
+
30
+ def _make_inline_buttons(ibuttons: dict[str, str], by=1) -> "Widget":
31
+ ibs0 = [f"{key}:{val}" for key, val in ibuttons.items()]
32
+ ibs = list(chunked(ibs0, n=by))
33
+ res = Widget(ibuttons=ibs)
34
+ return res
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: mmar-mapi
3
- Version: 1.0.6
3
+ Version: 1.0.7
4
4
  Summary: Common pure/IO utilities for multi-modal architectures team
5
5
  Keywords:
6
6
  Author: Eugene Tagin
@@ -1,19 +1,17 @@
1
- mmar_mapi/__init__.py,sha256=cj3McZDG8zU1nLSMjwtVHG0u99xN7LaNLW90d4tK7Io,613
1
+ mmar_mapi/__init__.py,sha256=hhLEK5u9NL1Du3X1M0SzmMPYYq5FIUcbiVNL2_jCZYc,1084
2
2
  mmar_mapi/api.py,sha256=C9Sr8dISvf51xfEznPjccI_odaG4coQE3HI_0jVpjMQ,1677
3
3
  mmar_mapi/file_storage.py,sha256=GbahBabBdAKjlAnv1MszERUxxZyA9HGMiR9tz2a9dgY,4409
4
4
  mmar_mapi/models/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
5
5
  mmar_mapi/models/base.py,sha256=mKtXV2x51XVj7W-et9tjGcPMDUUUMelW-BywMgFc2p0,411
6
- mmar_mapi/models/base_config_models/__init__.py,sha256=KjS_bSCka8BOMsigwcIML-e6eNB2ouMU6gxlhRmzeuY,44
7
- mmar_mapi/models/base_config_models/gigachat_config.py,sha256=QvKTnp0VioXzd3_PUgNBeYx5RDTZT-45j-Ll-wXEI_o,421
8
- mmar_mapi/models/chat.py,sha256=sAYuudA--i7qVfEERy5K5wmAkIFAjn6vUrKRT_BmfIE,12480
6
+ mmar_mapi/models/chat.py,sha256=IsIYoHY3Taxnfn-Audeml-WLGIbJgKr_-Arg-ZA8FIE,13293
9
7
  mmar_mapi/models/chat_item.py,sha256=ZfCKvTqr7gpuJSAuHVxWRnlTefRwki_IVNA2N_CXGdg,5557
10
8
  mmar_mapi/models/enums.py,sha256=J-GNpql9MCnKnWiV9aJRQGI-pAybvV86923RZs99grA,1006
11
9
  mmar_mapi/models/tracks.py,sha256=HKDp-BX1p7AlDfSEKfOKCu0TRSK9cD4Dmq1vJt8oRjw,307
12
- mmar_mapi/models/widget.py,sha256=KXSP3d4yQNeificMfzRxROdByw9IkxwCjkDD0kc7tcQ,704
10
+ mmar_mapi/models/widget.py,sha256=pQHiOukNLzsrz5lr5ptMeARPxSzJhJnijA0rVpVSIhk,1108
13
11
  mmar_mapi/type_union.py,sha256=diwmzcnbqkpGFckPHNw9o8zyQ955mOGNvhTlcBJ0RMI,1905
14
12
  mmar_mapi/utils.py,sha256=hcKJVslvTBLw2vjZ9zcKZxh_tqk48obHcVs_i3Rxn3M,112
15
13
  mmar_mapi/xml_parser.py,sha256=VvLIX_XCZao9i0qqpTVx8nx0vbFXSe8pEbdJdXnj97g,568
16
- mmar_mapi-1.0.6.dist-info/licenses/LICENSE,sha256=2A90w8WjhOgQXnFuUijKJYazaqZ4_NTokYb9Po4y-9k,1061
17
- mmar_mapi-1.0.6.dist-info/WHEEL,sha256=Jb20R3Ili4n9P1fcwuLup21eQ5r9WXhs4_qy7VTrgPI,79
18
- mmar_mapi-1.0.6.dist-info/METADATA,sha256=dxEk5xdH21b8jW053i5ojhUkguzCkgJoZMRc_JIRyAo,914
19
- mmar_mapi-1.0.6.dist-info/RECORD,,
14
+ mmar_mapi-1.0.7.dist-info/licenses/LICENSE,sha256=2A90w8WjhOgQXnFuUijKJYazaqZ4_NTokYb9Po4y-9k,1061
15
+ mmar_mapi-1.0.7.dist-info/WHEEL,sha256=Pi5uDq5Fdo_Rr-HD5h9BiPn9Et29Y9Sh8NhcJNnFU1c,79
16
+ mmar_mapi-1.0.7.dist-info/METADATA,sha256=GnTR9S4PdQJak3j-3tIJ61xrA7bU1AjubCe-vRWkL3I,914
17
+ mmar_mapi-1.0.7.dist-info/RECORD,,
@@ -1,4 +1,4 @@
1
1
  Wheel-Version: 1.0
2
- Generator: uv 0.8.15
2
+ Generator: uv 0.8.17
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
@@ -1 +0,0 @@
1
- from .gigachat_config import GigaChatConfig
@@ -1,14 +0,0 @@
1
- from typing import Self
2
-
3
- from pydantic import BaseModel, model_validator, SecretStr
4
-
5
-
6
- class GigaChatConfig(BaseModel):
7
- client_id: SecretStr = SecretStr("")
8
- client_secret: SecretStr = SecretStr("")
9
-
10
- @model_validator(mode="after")
11
- def empty_validator(self) -> Self:
12
- if not (self.client_id and self.client_secret):
13
- raise ValueError("creds for gigachat is not filled")
14
- return self