agi-med-common 4.0.6__py3-none-any.whl → 4.2.0__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__ = "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:
@@ -1,14 +1,38 @@
1
1
  import os
2
2
  import re
3
3
  from pathlib import Path
4
+ from typing import Annotated, TypeVar
5
+ from pydantic import AfterValidator
4
6
 
5
7
 
6
- def is_file_exist(filepath: str | os.PathLike[str] | Path) -> str | os.PathLike | Path:
8
+ PathLike = str | os.PathLike[str] | Path
9
+
10
+
11
+ def validate_existing_path(filepath: PathLike) -> PathLike:
7
12
  if not os.path.exists(filepath):
8
- raise ValueError(f"File {filepath} is not exist. Check the path")
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")
9
20
  return filepath
10
21
 
11
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
+
12
36
  def validate_prompt(prompt: str, prompt_required_keys: set[str]) -> str:
13
37
  exist_keys: set[str] = set(re.findall(r"{(.*?)}", prompt))
14
38
  if missed_keys := prompt_required_keys.difference(exist_keys):
@@ -16,3 +40,36 @@ def validate_prompt(prompt: str, prompt_required_keys: set[str]) -> str:
16
40
  if extern_keys := exist_keys.difference(prompt_required_keys):
17
41
  raise ValueError(f"You have more keys for prompt: {extern_keys}")
18
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,8 +1,8 @@
1
- agi_med_common/__init__.py,sha256=ieERcHJV_y_jHN7e9DFg6VSz2TAszb423gDMusC7q24,575
1
+ agi_med_common/__init__.py,sha256=IvElxZ-gSgSUhXTYjdzg0e5p8C74xFqsslUXktPQf5w,592
2
2
  agi_med_common/file_storage.py,sha256=uyZE3ePKrbVLNVcvxw9lbgumy1UPwDGIwQMs1Bd8HFI,1502
3
3
  agi_med_common/parallel_map.py,sha256=Qx6xe7DqlEUDpSucp5Hm8r9y9Iquwh9JvX7lOqHhnOw,921
4
4
  agi_med_common/utils.py,sha256=5iurKl5d1zZ_cN4yqtc0_FhrwuNBcDurbWilu28_saE,325
5
- agi_med_common/validators.py,sha256=R678gjPp-5XbnocRuEtdOQgJyCCOurxwaOe2nT04kSg,705
5
+ agi_med_common/validators.py,sha256=sWXWsJn9FBlbyUHCNBNSMiEnD9ZenXhzMBNTXjC7yRE,2413
6
6
  agi_med_common/xml_parser.py,sha256=VvLIX_XCZao9i0qqpTVx8nx0vbFXSe8pEbdJdXnj97g,568
7
7
  agi_med_common/logger/__init__.py,sha256=RW_0VZtbeJ4RsLqUXZUQWl5CtV9g840rU7qRlf5u49E,96
8
8
  agi_med_common/logger/log_level_enum.py,sha256=lWuSMho9I0v_xf1RuwpERx5o8NJXaavjwxSdh8fxMqE,477
@@ -14,7 +14,7 @@ agi_med_common/models/base_config_models/gigachat_config.py,sha256=WNSCTO8Fjpxc1
14
14
  agi_med_common/models/chat_item/__init__.py,sha256=NG1optUYwjnxfpTXntUfTDOA0eKTgdV43TZOcfHasHg,185
15
15
  agi_med_common/models/chat_item/chat_item.py,sha256=xP_uP14qK-u8z0ZUs2HFhhea-IP230UgOmjeqeC_N6Q,1180
16
16
  agi_med_common/models/chat_item/inner_context_item.py,sha256=2wIwDtZwicwhSyXeuOqH8-xONcskeEiw6QhjSnEEwZs,329
17
- agi_med_common/models/chat_item/outer_context_item.py,sha256=6YD3u5Xa-zKC9XSaum4b2zMB5-nWmTkGn05DMdWFxF4,1060
17
+ agi_med_common/models/chat_item/outer_context_item.py,sha256=_snB7FI4sAp17U29r_SYI6UMKm9yveO031HjCtQQ9Bo,1263
18
18
  agi_med_common/models/chat_item/replica_item.py,sha256=D1goRTINLa1rUcQcwHOWUSiv_OR1UW0GVn5_TqK3dyk,1672
19
19
  agi_med_common/models/enums/__init__.py,sha256=NFgy8J-bET2GQqUyTaKYLzaLaM-jDR8-7TBTadWKm5o,341
20
20
  agi_med_common/models/enums/diagnostics_xml_tag_enum.py,sha256=aiUJpe5joh5EOcJ5sk1Xs003XkRry2CBL6H-bIEiapA,278
@@ -23,7 +23,7 @@ agi_med_common/models/enums/moderation_label_enum.py,sha256=lbGG4Pu7cQp57uEyQEpt
23
23
  agi_med_common/models/enums/mtrs_label_enum.py,sha256=6emBndt3SCsQVZZFKQYCV2_iyjjmZEhwejJKJu39ZAw,257
24
24
  agi_med_common/models/enums/mtrs_xml_tag_enum.py,sha256=6OxuRsrx4b2uBjfrBgm4Y789Ly337_mQXL9VPRCpLyg,273
25
25
  agi_med_common/models/enums/track_id_enum.py,sha256=N3KUd97a4xDet_NKZ5URm0qWAAv3ts1l_foOjdlGY4c,532
26
- agi_med_common-4.0.6.dist-info/METADATA,sha256=RwjXqgPp2Pw0591Sjy0hUs73zkYEkgwCP69KCqV11wE,546
27
- agi_med_common-4.0.6.dist-info/WHEEL,sha256=DnLRTWE75wApRYVsjgc6wsVswC54sMSJhAEd4xhDpBk,91
28
- agi_med_common-4.0.6.dist-info/top_level.txt,sha256=26o565jF_7wYQj7-YJfTedtT9yDxDcf8RNikOYuPq78,15
29
- agi_med_common-4.0.6.dist-info/RECORD,,
26
+ agi_med_common-4.2.0.dist-info/METADATA,sha256=oSn4FoibCezpwEn5Qx1jUmfVAIOdnUraA3gxA_iVy0s,546
27
+ agi_med_common-4.2.0.dist-info/WHEEL,sha256=zaaOINJESkSfm_4HQVc5ssNzHCPXhJm0kEUakpsEHaU,91
28
+ agi_med_common-4.2.0.dist-info/top_level.txt,sha256=26o565jF_7wYQj7-YJfTedtT9yDxDcf8RNikOYuPq78,15
29
+ agi_med_common-4.2.0.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (80.4.0)
2
+ Generator: setuptools (80.8.0)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5