agi-med-common 5.0.4__tar.gz → 5.0.5__tar.gz

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.
Files changed (28) hide show
  1. {agi_med_common-5.0.4 → agi_med_common-5.0.5}/PKG-INFO +1 -1
  2. {agi_med_common-5.0.4 → agi_med_common-5.0.5}/src/agi_med_common/__init__.py +1 -1
  3. {agi_med_common-5.0.4 → agi_med_common-5.0.5}/src/agi_med_common/models/__init__.py +0 -1
  4. {agi_med_common-5.0.4 → agi_med_common-5.0.5}/src/agi_med_common/models/chat_item.py +32 -1
  5. {agi_med_common-5.0.4 → agi_med_common-5.0.5}/src/agi_med_common.egg-info/PKG-INFO +1 -1
  6. {agi_med_common-5.0.4 → agi_med_common-5.0.5}/README.md +0 -0
  7. {agi_med_common-5.0.4 → agi_med_common-5.0.5}/pyproject.toml +0 -0
  8. {agi_med_common-5.0.4 → agi_med_common-5.0.5}/requirements.txt +0 -0
  9. {agi_med_common-5.0.4 → agi_med_common-5.0.5}/setup.cfg +0 -0
  10. {agi_med_common-5.0.4 → agi_med_common-5.0.5}/src/agi_med_common/api/chat_manager_api.py +0 -0
  11. {agi_med_common-5.0.4 → agi_med_common-5.0.5}/src/agi_med_common/file_storage.py +0 -0
  12. {agi_med_common-5.0.4 → agi_med_common-5.0.5}/src/agi_med_common/logger/__init__.py +0 -0
  13. {agi_med_common-5.0.4 → agi_med_common-5.0.5}/src/agi_med_common/logger/log_level_enum.py +0 -0
  14. {agi_med_common-5.0.4 → agi_med_common-5.0.5}/src/agi_med_common/logger/logger.py +0 -0
  15. {agi_med_common-5.0.4 → agi_med_common-5.0.5}/src/agi_med_common/models/_base.py +0 -0
  16. {agi_med_common-5.0.4 → agi_med_common-5.0.5}/src/agi_med_common/models/base_config_models/__init__.py +0 -0
  17. {agi_med_common-5.0.4 → agi_med_common-5.0.5}/src/agi_med_common/models/base_config_models/gigachat_config.py +0 -0
  18. {agi_med_common-5.0.4 → agi_med_common-5.0.5}/src/agi_med_common/models/enums.py +0 -0
  19. {agi_med_common-5.0.4 → agi_med_common-5.0.5}/src/agi_med_common/models/tracks.py +0 -0
  20. {agi_med_common-5.0.4 → agi_med_common-5.0.5}/src/agi_med_common/models/widget.py +0 -0
  21. {agi_med_common-5.0.4 → agi_med_common-5.0.5}/src/agi_med_common/parallel_map.py +0 -0
  22. {agi_med_common-5.0.4 → agi_med_common-5.0.5}/src/agi_med_common/utils.py +0 -0
  23. {agi_med_common-5.0.4 → agi_med_common-5.0.5}/src/agi_med_common/validators.py +0 -0
  24. {agi_med_common-5.0.4 → agi_med_common-5.0.5}/src/agi_med_common/xml_parser.py +0 -0
  25. {agi_med_common-5.0.4 → agi_med_common-5.0.5}/src/agi_med_common.egg-info/SOURCES.txt +0 -0
  26. {agi_med_common-5.0.4 → agi_med_common-5.0.5}/src/agi_med_common.egg-info/dependency_links.txt +0 -0
  27. {agi_med_common-5.0.4 → agi_med_common-5.0.5}/src/agi_med_common.egg-info/requires.txt +0 -0
  28. {agi_med_common-5.0.4 → agi_med_common-5.0.5}/src/agi_med_common.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: agi_med_common
3
- Version: 5.0.4
3
+ Version: 5.0.5
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
- __version__ = "5.0.4"
1
+ __version__ = "5.0.5"
2
2
 
3
3
  from .logger import LogLevelEnum, logger_init, log_llm_error
4
4
  from .models import (
@@ -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 pydantic import Field, ConfigDict
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,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: agi_med_common
3
- Version: 5.0.4
3
+ Version: 5.0.5
4
4
  Summary: Сommon for agi-med team
5
5
  Author: AGI-MED-TEAM
6
6
  Requires-Python: >=3.11
File without changes
File without changes