agi-med-common 5.0.23__py3-none-any.whl → 5.0.25__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.
@@ -1,4 +1,4 @@
1
- __version__ = "5.0.23"
1
+ __version__ = "5.0.25"
2
2
 
3
3
  from .models import (
4
4
  MTRSLabelEnum,
@@ -10,6 +10,7 @@ from agi_med_common.utils import first_nonnull
10
10
  from pydantic import Field, ValidationError
11
11
 
12
12
  from ._base import _Base
13
+ from typing import Callable
13
14
 
14
15
 
15
16
  _DT_FORMAT: str = "%Y-%m-%d-%H-%M-%S"
@@ -17,7 +18,7 @@ _EXAMPLE_DT: str = datetime(year=1970, month=1, day=1).strftime(_DT_FORMAT)
17
18
  StrDict = Dict[str, Any]
18
19
  ContentBase = str | Widget | StrDict
19
20
  Content = ContentBase | List[ContentBase]
20
- T = TypeVar('T')
21
+ T = TypeVar("T")
21
22
 
22
23
 
23
24
  def now_pretty() -> str:
@@ -76,6 +77,18 @@ def _get_text(obj: Content) -> str:
76
77
  return ""
77
78
 
78
79
 
80
+ def _modify_text(obj: Content, callback: Callable[[str], str | None]) -> str:
81
+ if isinstance(obj, str):
82
+ return callback(obj)
83
+ if isinstance(obj, list):
84
+ return [_modify_text(el, callback) for el in obj]
85
+ if isinstance(obj, dict) and obj.get("type") == "text":
86
+ text = _get_field(obj, "text", str) or ""
87
+ text_upd = callback(text)
88
+ return {"type": "text", "text": text_upd}
89
+ return obj
90
+
91
+
79
92
  def _get_resource_id(obj: Content) -> str | None:
80
93
  if isinstance(obj, list):
81
94
  return first_nonnull(map(_get_resource_id, obj))
@@ -113,6 +126,10 @@ class BaseMessage(_Base):
113
126
  def text(self) -> str:
114
127
  return _get_text(self.content)
115
128
 
129
+ def modify_text(self, callback: Callable[[str], str]) -> "BaseMessage":
130
+ content_upd = _modify_text(self.content, callback)
131
+ return self.model_copy(update=dict(content=content_upd))
132
+
116
133
  @property
117
134
  def body(self) -> str:
118
135
  # legacy: eliminate after migration
@@ -168,6 +185,13 @@ class Chat(_Base):
168
185
  def to_chat_item(self) -> ChatItem:
169
186
  return convert_chat_to_chat_item(self)
170
187
 
188
+ def add_message(self, message: ChatMessage):
189
+ self.messages.append(message)
190
+
191
+ def add_messages(self, messages: List[ChatMessage]):
192
+ for message in messages:
193
+ self.messages.append(message)
194
+
171
195
 
172
196
  def convert_replica_item_to_message(replica: ReplicaItem) -> ChatMessage:
173
197
  # legacy: eliminate after migration
@@ -253,7 +277,7 @@ def convert_message_to_replica_item(message: ChatMessage) -> ReplicaItem | None:
253
277
  else:
254
278
  return None
255
279
 
256
- extra = deepcopy(message.extra) if message.extra or {}
280
+ extra = deepcopy(message.extra) if message.extra else {}
257
281
  action = extra.pop("action", "")
258
282
  moderation = extra.pop("moderation", "OK")
259
283
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: agi_med_common
3
- Version: 5.0.23
3
+ Version: 5.0.25
4
4
  Summary: Сommon for agi-med team
5
5
  Author: AGI-MED-TEAM
6
6
  Requires-Python: >=3.11
@@ -1,4 +1,4 @@
1
- agi_med_common/__init__.py,sha256=ygwhdPR5f4EnhXs8JSK6yncgDCSnScoDWxivgcxp_TE,740
1
+ agi_med_common/__init__.py,sha256=_cVr0Xpyf_UeT_iBf-t76dvcwpgFjzri5yywDp08rd8,740
2
2
  agi_med_common/api.py,sha256=kGLKiebbF91s_7V2S55ETS7R6tQgZNkoFMoawdjeMYw,1860
3
3
  agi_med_common/api_v2.py,sha256=gj6BPEAOvpT6GHWeE7bzmKIR-pvq0yORZ3L0ADvI8ps,1828
4
4
  agi_med_common/file_storage.py,sha256=T0Hbs4W-pWO6HdWcmlVqABrQHYdq7lLZH4_Vu-YNVbw,1802
@@ -9,14 +9,14 @@ agi_med_common/validators.py,sha256=vMoPN42XzC8re-zdjekk5_lNQYHuTiAWD56YLvj2Z2w,
9
9
  agi_med_common/xml_parser.py,sha256=VvLIX_XCZao9i0qqpTVx8nx0vbFXSe8pEbdJdXnj97g,568
10
10
  agi_med_common/models/__init__.py,sha256=dqr2kP-RuxFfAZhCr103PQzTVZFKIcdxyzTYiHhdTsE,375
11
11
  agi_med_common/models/_base.py,sha256=qNdH8x3x3mYbo5XgWtR9VpEarxsEvXvzynadUlDvHmU,149
12
- agi_med_common/models/chat.py,sha256=ag0Q3YaOf_7YMJS_pWLdVxHvTey16v-P51Jq3AjkmLU,9228
12
+ agi_med_common/models/chat.py,sha256=Tc-qPDvmLOkKalHEsx9OX2qQ6o4RCcdod0ciHune4Q8,10115
13
13
  agi_med_common/models/chat_item.py,sha256=bg_l6B4RAqiSO84vF50nQN7kYCkLB6JHAzItwm1-RzM,4791
14
14
  agi_med_common/models/enums.py,sha256=J-GNpql9MCnKnWiV9aJRQGI-pAybvV86923RZs99grA,1006
15
15
  agi_med_common/models/tracks.py,sha256=UP-jeWqDiCK6dyoMDfs7hemgl_xsJKee_DApjBf-XYc,311
16
16
  agi_med_common/models/widget.py,sha256=aJZ2vWx_PTFN02Wz16eokz9IIVrxqNuZYVDqLG36toE,710
17
17
  agi_med_common/models/base_config_models/__init__.py,sha256=KjS_bSCka8BOMsigwcIML-e6eNB2ouMU6gxlhRmzeuY,44
18
18
  agi_med_common/models/base_config_models/gigachat_config.py,sha256=WNSCTO8Fjpxc1v2LRUHfKqo9aeMDpXltTHYBFgTD2N0,422
19
- agi_med_common-5.0.23.dist-info/METADATA,sha256=kq3tcdnb2NwO5mHGtAmPTFa2ulZTMnnaqK_tVYni4k4,518
20
- agi_med_common-5.0.23.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
21
- agi_med_common-5.0.23.dist-info/top_level.txt,sha256=26o565jF_7wYQj7-YJfTedtT9yDxDcf8RNikOYuPq78,15
22
- agi_med_common-5.0.23.dist-info/RECORD,,
19
+ agi_med_common-5.0.25.dist-info/METADATA,sha256=ESt2Yy4UvU-c9T35RdeX4kX4APEusfOY2C0QpJXEsow,518
20
+ agi_med_common-5.0.25.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
21
+ agi_med_common-5.0.25.dist-info/top_level.txt,sha256=26o565jF_7wYQj7-YJfTedtT9yDxDcf8RNikOYuPq78,15
22
+ agi_med_common-5.0.25.dist-info/RECORD,,