agi-med-common 4.0.6__tar.gz → 4.2.0__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 (36) hide show
  1. {agi_med_common-4.0.6 → agi_med_common-4.2.0}/PKG-INFO +1 -1
  2. {agi_med_common-4.0.6 → agi_med_common-4.2.0}/src/agi_med_common/__init__.py +2 -2
  3. {agi_med_common-4.0.6 → agi_med_common-4.2.0}/src/agi_med_common/models/chat_item/outer_context_item.py +5 -1
  4. agi_med_common-4.2.0/src/agi_med_common/validators.py +75 -0
  5. {agi_med_common-4.0.6 → agi_med_common-4.2.0}/src/agi_med_common.egg-info/PKG-INFO +1 -1
  6. agi_med_common-4.0.6/src/agi_med_common/validators.py +0 -18
  7. {agi_med_common-4.0.6 → agi_med_common-4.2.0}/README.md +0 -0
  8. {agi_med_common-4.0.6 → agi_med_common-4.2.0}/pyproject.toml +0 -0
  9. {agi_med_common-4.0.6 → agi_med_common-4.2.0}/requirements.txt +0 -0
  10. {agi_med_common-4.0.6 → agi_med_common-4.2.0}/setup.cfg +0 -0
  11. {agi_med_common-4.0.6 → agi_med_common-4.2.0}/src/agi_med_common/file_storage.py +0 -0
  12. {agi_med_common-4.0.6 → agi_med_common-4.2.0}/src/agi_med_common/logger/__init__.py +0 -0
  13. {agi_med_common-4.0.6 → agi_med_common-4.2.0}/src/agi_med_common/logger/log_level_enum.py +0 -0
  14. {agi_med_common-4.0.6 → agi_med_common-4.2.0}/src/agi_med_common/logger/logger.py +0 -0
  15. {agi_med_common-4.0.6 → agi_med_common-4.2.0}/src/agi_med_common/models/__init__.py +0 -0
  16. {agi_med_common-4.0.6 → agi_med_common-4.2.0}/src/agi_med_common/models/_base.py +0 -0
  17. {agi_med_common-4.0.6 → agi_med_common-4.2.0}/src/agi_med_common/models/base_config_models/__init__.py +0 -0
  18. {agi_med_common-4.0.6 → agi_med_common-4.2.0}/src/agi_med_common/models/base_config_models/gigachat_config.py +0 -0
  19. {agi_med_common-4.0.6 → agi_med_common-4.2.0}/src/agi_med_common/models/chat_item/__init__.py +0 -0
  20. {agi_med_common-4.0.6 → agi_med_common-4.2.0}/src/agi_med_common/models/chat_item/chat_item.py +0 -0
  21. {agi_med_common-4.0.6 → agi_med_common-4.2.0}/src/agi_med_common/models/chat_item/inner_context_item.py +0 -0
  22. {agi_med_common-4.0.6 → agi_med_common-4.2.0}/src/agi_med_common/models/chat_item/replica_item.py +0 -0
  23. {agi_med_common-4.0.6 → agi_med_common-4.2.0}/src/agi_med_common/models/enums/__init__.py +0 -0
  24. {agi_med_common-4.0.6 → agi_med_common-4.2.0}/src/agi_med_common/models/enums/diagnostics_xml_tag_enum.py +0 -0
  25. {agi_med_common-4.0.6 → agi_med_common-4.2.0}/src/agi_med_common/models/enums/doctor_choice_xml_tag_enum.py +0 -0
  26. {agi_med_common-4.0.6 → agi_med_common-4.2.0}/src/agi_med_common/models/enums/moderation_label_enum.py +0 -0
  27. {agi_med_common-4.0.6 → agi_med_common-4.2.0}/src/agi_med_common/models/enums/mtrs_label_enum.py +0 -0
  28. {agi_med_common-4.0.6 → agi_med_common-4.2.0}/src/agi_med_common/models/enums/mtrs_xml_tag_enum.py +0 -0
  29. {agi_med_common-4.0.6 → agi_med_common-4.2.0}/src/agi_med_common/models/enums/track_id_enum.py +0 -0
  30. {agi_med_common-4.0.6 → agi_med_common-4.2.0}/src/agi_med_common/parallel_map.py +0 -0
  31. {agi_med_common-4.0.6 → agi_med_common-4.2.0}/src/agi_med_common/utils.py +0 -0
  32. {agi_med_common-4.0.6 → agi_med_common-4.2.0}/src/agi_med_common/xml_parser.py +0 -0
  33. {agi_med_common-4.0.6 → agi_med_common-4.2.0}/src/agi_med_common.egg-info/SOURCES.txt +0 -0
  34. {agi_med_common-4.0.6 → agi_med_common-4.2.0}/src/agi_med_common.egg-info/dependency_links.txt +0 -0
  35. {agi_med_common-4.0.6 → agi_med_common-4.2.0}/src/agi_med_common.egg-info/requires.txt +0 -0
  36. {agi_med_common-4.0.6 → agi_med_common-4.2.0}/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: 4.0.6
3
+ Version: 4.2.0
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__ = "4.0.6"
1
+ __version__ = "4.2.0"
2
2
 
3
3
  from .logger import LogLevelEnum, logger_init
4
4
  from .models import (
@@ -16,6 +16,6 @@ from .models import (
16
16
  from .file_storage import FileStorage
17
17
  from .models import DiagnosticsXMLTagEnum, MTRSXMLTagEnum, DoctorChoiceXMLTagEnum
18
18
  from .utils import make_session_id, read_json
19
- from .validators import is_file_exist, validate_prompt
19
+ from .validators import ExistingPath, ExistingFile, StrNotEmpty, Prompt
20
20
  from .xml_parser import XMLParser
21
21
  from .parallel_map import parallel_map
@@ -1,4 +1,4 @@
1
- from pydantic import Field
1
+ from pydantic import Field, ConfigDict
2
2
  from typing import Any
3
3
 
4
4
  from .. import _Base
@@ -6,12 +6,16 @@ from ..enums import TrackIdEnum
6
6
 
7
7
 
8
8
  class OuterContextItem(_Base):
9
+ # remove annoying warning for protected `model_` namespace
10
+ model_config = ConfigDict(protected_namespaces=())
11
+
9
12
  sex: bool = Field(False, alias="Sex", description="True = male, False = female", examples=[True])
10
13
  age: int = Field(0, alias="Age", examples=[20])
11
14
  user_id: str = Field("", alias="UserId", examples=["123456789"])
12
15
  session_id: str = Field("", alias="SessionId", examples=["987654321"])
13
16
  client_id: str = Field("", alias="ClientId", examples=["543216789"])
14
17
  track_id: TrackIdEnum | str = Field(default=TrackIdEnum.CONSULTATION, alias="TrackId")
18
+ model_id: str = Field("", alias="ModelId", examples=["gigachat-2"])
15
19
 
16
20
  def create_id(self, short: bool = False, clean: bool = False) -> str:
17
21
  if short:
@@ -0,0 +1,75 @@
1
+ import os
2
+ import re
3
+ from pathlib import Path
4
+ from typing import Annotated, TypeVar
5
+ from pydantic import AfterValidator
6
+
7
+
8
+ PathLike = str | os.PathLike[str] | Path
9
+
10
+
11
+ def validate_existing_path(filepath: PathLike) -> PathLike:
12
+ if not os.path.exists(filepath):
13
+ raise ValueError(f"Path {filepath} is not exist")
14
+ return filepath
15
+
16
+
17
+ def validate_existing_file(filepath: PathLike) -> PathLike:
18
+ if not os.path.isfile(filepath):
19
+ raise ValueError(f"Path {filepath} is not file")
20
+ return filepath
21
+
22
+
23
+ ExistingPath = Annotated[Path, AfterValidator(validate_existing_path)]
24
+ ExistingFile = Annotated[Path, AfterValidator(validate_existing_file)]
25
+
26
+
27
+ def validate_not_empty(text: any) -> any:
28
+ if not text:
29
+ raise ValueError("Expected not empty")
30
+ return text
31
+
32
+
33
+ StrNotEmpty = Annotated[str, AfterValidator(validate_not_empty)]
34
+
35
+
36
+ def validate_prompt(prompt: str, prompt_required_keys: set[str]) -> str:
37
+ exist_keys: set[str] = set(re.findall(r"{(.*?)}", prompt))
38
+ if missed_keys := prompt_required_keys.difference(exist_keys):
39
+ raise ValueError(f"Missing required key in prompt: {missed_keys}")
40
+ if extern_keys := exist_keys.difference(prompt_required_keys):
41
+ raise ValueError(f"You have more keys for prompt: {extern_keys}")
42
+ return prompt
43
+
44
+
45
+ def validate_keys(*keys):
46
+ assert keys and all(isinstance(key, str) for key in keys)
47
+
48
+ def validate(prompt: str) -> str:
49
+ prompt_required_keys: set[str] = set(keys)
50
+ exist_keys: set[str] = set(re.findall(r"{(.*?)}", prompt))
51
+ if missed_keys := prompt_required_keys.difference(exist_keys):
52
+ raise ValueError(f"Missing required key in prompt: {missed_keys}")
53
+ if extern_keys := exist_keys.difference(prompt_required_keys):
54
+ raise ValueError(f"You have more keys for prompt: {extern_keys}")
55
+ return prompt
56
+
57
+ return validate
58
+
59
+
60
+ K = TypeVar("K", bound=str)
61
+
62
+
63
+ class Prompt:
64
+ # use inside pydantic models: prompt: Prompt['base_context']
65
+ def __class_getitem__(cls, keys: K | tuple[K, ...]) -> type[str]:
66
+ if isinstance(keys, tuple):
67
+ keys_tuple = keys
68
+ else:
69
+ keys_tuple = (keys,)
70
+
71
+ # Validate that all keys are strings
72
+ if not all(isinstance(key, str) for key in keys_tuple):
73
+ raise TypeError("All keys must be strings")
74
+
75
+ return Annotated[str, AfterValidator(validate_keys(*keys_tuple))]
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: agi_med_common
3
- Version: 4.0.6
3
+ Version: 4.2.0
4
4
  Summary: Сommon for agi-med team
5
5
  Author: AGI-MED-TEAM
6
6
  Requires-Python: >=3.11
@@ -1,18 +0,0 @@
1
- import os
2
- import re
3
- from pathlib import Path
4
-
5
-
6
- def is_file_exist(filepath: str | os.PathLike[str] | Path) -> str | os.PathLike | Path:
7
- if not os.path.exists(filepath):
8
- raise ValueError(f"File {filepath} is not exist. Check the path")
9
- return filepath
10
-
11
-
12
- def validate_prompt(prompt: str, prompt_required_keys: set[str]) -> str:
13
- exist_keys: set[str] = set(re.findall(r"{(.*?)}", prompt))
14
- if missed_keys := prompt_required_keys.difference(exist_keys):
15
- raise ValueError(f"Missing required key in prompt: {missed_keys}")
16
- if extern_keys := exist_keys.difference(prompt_required_keys):
17
- raise ValueError(f"You have more keys for prompt: {extern_keys}")
18
- return prompt
File without changes
File without changes