agi-med-common 5.0.3__py3-none-any.whl → 5.0.5__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.
- agi_med_common/__init__.py +1 -1
- agi_med_common/file_storage.py +4 -4
- agi_med_common/models/__init__.py +0 -1
- agi_med_common/models/chat_item.py +32 -1
- {agi_med_common-5.0.3.dist-info → agi_med_common-5.0.5.dist-info}/METADATA +1 -1
- {agi_med_common-5.0.3.dist-info → agi_med_common-5.0.5.dist-info}/RECORD +8 -8
- {agi_med_common-5.0.3.dist-info → agi_med_common-5.0.5.dist-info}/WHEEL +0 -0
- {agi_med_common-5.0.3.dist-info → agi_med_common-5.0.5.dist-info}/top_level.txt +0 -0
agi_med_common/__init__.py
CHANGED
agi_med_common/file_storage.py
CHANGED
@@ -56,8 +56,8 @@ class FileStorage:
|
|
56
56
|
def download_text(self, rid: ResourceId) -> str:
|
57
57
|
return Path(rid).read_text(encoding='utf-8')
|
58
58
|
|
59
|
-
def is_valid(self, rid: ResourceId) ->
|
60
|
-
return Path(rid).exists() and Path(rid).is_file()
|
59
|
+
def is_valid(self, rid: ResourceId | None) -> bool:
|
60
|
+
return rid and Path(rid).exists() and Path(rid).is_file()
|
61
61
|
|
62
|
-
def get_dtype(self, rid: ResourceId) -> str:
|
63
|
-
return rid.rsplit('.')[-1]
|
62
|
+
def get_dtype(self, rid: ResourceId | None) -> str | None:
|
63
|
+
return rid and rid.rsplit('.')[-1]
|
@@ -1,7 +1,6 @@
|
|
1
1
|
from ._base import _Base
|
2
2
|
|
3
3
|
from .enums import MTRSLabelEnum, DiagnosticsXMLTagEnum, MTRSXMLTagEnum, DoctorChoiceXMLTagEnum
|
4
|
-
|
5
4
|
from .chat_item import ChatItem, OuterContextItem, InnerContextItem, ReplicaItem
|
6
5
|
from .base_config_models import GigaChatConfig
|
7
6
|
from .tracks import TrackInfo, DomainInfo
|
@@ -1,8 +1,10 @@
|
|
1
|
+
import json
|
1
2
|
from datetime import datetime
|
2
3
|
from typing import Any, List
|
3
4
|
|
4
5
|
from agi_med_common.models.widget import Widget
|
5
|
-
from
|
6
|
+
from loguru import logger
|
7
|
+
from pydantic import Field, ConfigDict, ValidationError
|
6
8
|
|
7
9
|
from ._base import _Base
|
8
10
|
|
@@ -93,3 +95,32 @@ class ChatItem(_Base):
|
|
93
95
|
|
94
96
|
def zip_history(self, field: str) -> list[Any]:
|
95
97
|
return [replica.to_dict().get(field, None) for replica in self.inner_context.replicas]
|
98
|
+
|
99
|
+
@classmethod
|
100
|
+
def parse(cls, chat_text: str) -> "ChatItem":
|
101
|
+
return _parse_chat(chat_text)
|
102
|
+
|
103
|
+
|
104
|
+
def _is_moderation_int_error(ex):
|
105
|
+
errs = ex.errors()
|
106
|
+
if len(errs) != 1:
|
107
|
+
return False
|
108
|
+
err = errs[0]
|
109
|
+
if err['type'] == 'string_type' and err['loc'] == ('InnerContext', 'Replicas', 0, 'Moderation') and err['msg'] == 'Input should be a valid string':
|
110
|
+
return True
|
111
|
+
|
112
|
+
def _parse_chat(chat_text: str) -> ChatItem:
|
113
|
+
try:
|
114
|
+
return ChatItem.model_validate_json(chat_text)
|
115
|
+
except ValidationError as ex:
|
116
|
+
if _is_moderation_int_error(ex):
|
117
|
+
logger.warning("Failed to parse ChatItem, fallback to old version with `Moderation:int`")
|
118
|
+
else:
|
119
|
+
logger.error(f"Failed to parse: {ex}")
|
120
|
+
|
121
|
+
# old version
|
122
|
+
chat_dict = json.loads(chat_text)
|
123
|
+
for rep in chat_dict["InnerContext"]["Replicas"]:
|
124
|
+
rep["Moderation"] = "OK"
|
125
|
+
|
126
|
+
return ChatItem.model_validate(chat_dict)
|
@@ -1,5 +1,5 @@
|
|
1
|
-
agi_med_common/__init__.py,sha256=
|
2
|
-
agi_med_common/file_storage.py,sha256=
|
1
|
+
agi_med_common/__init__.py,sha256=OIJN7vCtRdYDTVy7gcMP5wqT1MT-khzZF9YV44Mi-6w,759
|
2
|
+
agi_med_common/file_storage.py,sha256=T0Hbs4W-pWO6HdWcmlVqABrQHYdq7lLZH4_Vu-YNVbw,1802
|
3
3
|
agi_med_common/parallel_map.py,sha256=Qx6xe7DqlEUDpSucp5Hm8r9y9Iquwh9JvX7lOqHhnOw,921
|
4
4
|
agi_med_common/utils.py,sha256=rBNAECUrvvyf-UZ650IpTfHvx5I8lYSnsB8QPBKti48,1276
|
5
5
|
agi_med_common/validators.py,sha256=vMoPN42XzC8re-zdjekk5_lNQYHuTiAWD56YLvj2Z2w,2824
|
@@ -8,15 +8,15 @@ agi_med_common/api/chat_manager_api.py,sha256=e-LJSmnWCFW1Wj5R3uavlKaq9p5VBoErqP
|
|
8
8
|
agi_med_common/logger/__init__.py,sha256=RW_0VZtbeJ4RsLqUXZUQWl5CtV9g840rU7qRlf5u49E,96
|
9
9
|
agi_med_common/logger/log_level_enum.py,sha256=lWuSMho9I0v_xf1RuwpERx5o8NJXaavjwxSdh8fxMqE,477
|
10
10
|
agi_med_common/logger/logger.py,sha256=-VU69ULbw2-pNpOcxKiMpOeRAPe6H-EsGV9WRTv1SUo,839
|
11
|
-
agi_med_common/models/__init__.py,sha256=
|
11
|
+
agi_med_common/models/__init__.py,sha256=UbZmFKH94-AsvLUeg2y2odJ6WMjumI0grOJWOWL-aVg,292
|
12
12
|
agi_med_common/models/_base.py,sha256=qNdH8x3x3mYbo5XgWtR9VpEarxsEvXvzynadUlDvHmU,149
|
13
|
-
agi_med_common/models/chat_item.py,sha256=
|
13
|
+
agi_med_common/models/chat_item.py,sha256=zrX3ktArwZ-gFfS6TCiKYs5imLtINvE_QFX3hnHFKbk,4859
|
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=g7Bobyk_gANghGEhjDjvi4i-YRoHo5Bm1Pr4eF-zf0U,661
|
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.
|
20
|
-
agi_med_common-5.0.
|
21
|
-
agi_med_common-5.0.
|
22
|
-
agi_med_common-5.0.
|
19
|
+
agi_med_common-5.0.5.dist-info/METADATA,sha256=HCcnLGZkxpY7rcP-gEV9TkOlfFO6d_sLklkVvltePCU,546
|
20
|
+
agi_med_common-5.0.5.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
21
|
+
agi_med_common-5.0.5.dist-info/top_level.txt,sha256=26o565jF_7wYQj7-YJfTedtT9yDxDcf8RNikOYuPq78,15
|
22
|
+
agi_med_common-5.0.5.dist-info/RECORD,,
|
File without changes
|
File without changes
|