agi-med-common 5.0.4__py3-none-any.whl → 5.0.6__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/models/__init__.py +0 -1
- agi_med_common/models/chat_item.py +33 -1
- {agi_med_common-5.0.4.dist-info → agi_med_common-5.0.6.dist-info}/METADATA +1 -1
- {agi_med_common-5.0.4.dist-info → agi_med_common-5.0.6.dist-info}/RECORD +7 -7
- {agi_med_common-5.0.4.dist-info → agi_med_common-5.0.6.dist-info}/WHEEL +0 -0
- {agi_med_common-5.0.4.dist-info → agi_med_common-5.0.6.dist-info}/top_level.txt +0 -0
agi_med_common/__init__.py
CHANGED
@@ -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,33 @@ 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(err):
|
105
|
+
return err['type'] == 'string_type' and err['loc'] == ('InnerContext', 'Replicas', 0, 'Moderation') and err['msg'] == 'Input should be a valid string'
|
106
|
+
|
107
|
+
def _is_moderation_int_errors(ex):
|
108
|
+
errs = ex.errors()
|
109
|
+
if len(errs) != 1:
|
110
|
+
return False
|
111
|
+
return all(map(_is_moderation_int_errors, errs))
|
112
|
+
|
113
|
+
def _parse_chat(chat_text: str) -> ChatItem:
|
114
|
+
try:
|
115
|
+
return ChatItem.model_validate_json(chat_text)
|
116
|
+
except ValidationError as ex:
|
117
|
+
if _is_moderation_int_error(ex):
|
118
|
+
logger.warning("Failed to parse ChatItem, fallback to old version with `Moderation:int`")
|
119
|
+
else:
|
120
|
+
logger.error(f"Failed to parse: {ex}")
|
121
|
+
|
122
|
+
# old version
|
123
|
+
chat_dict = json.loads(chat_text)
|
124
|
+
for rep in chat_dict["InnerContext"]["Replicas"]:
|
125
|
+
rep["Moderation"] = "OK"
|
126
|
+
|
127
|
+
return ChatItem.model_validate(chat_dict)
|
@@ -1,4 +1,4 @@
|
|
1
|
-
agi_med_common/__init__.py,sha256=
|
1
|
+
agi_med_common/__init__.py,sha256=a_kPHvngH3TR2fHLkFx62CYfzN-I_AkbcKlvi7s--AU,759
|
2
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
|
@@ -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=5mcHMx5it6cU91TYkwbT-fwKyJEqJ4crmnr5jVFNeDs,4914
|
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.6.dist-info/METADATA,sha256=f1_RfTWoxG2gwOaF7hjy9PML2-yU7oDrAo69A4TljFM,546
|
20
|
+
agi_med_common-5.0.6.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
21
|
+
agi_med_common-5.0.6.dist-info/top_level.txt,sha256=26o565jF_7wYQj7-YJfTedtT9yDxDcf8RNikOYuPq78,15
|
22
|
+
agi_med_common-5.0.6.dist-info/RECORD,,
|
File without changes
|
File without changes
|