agi-med-common 5.1.6__tar.gz → 5.1.8__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 (26) hide show
  1. {agi_med_common-5.1.6 → agi_med_common-5.1.8}/PKG-INFO +1 -1
  2. {agi_med_common-5.1.6 → agi_med_common-5.1.8}/src/agi_med_common/__init__.py +1 -1
  3. {agi_med_common-5.1.6 → agi_med_common-5.1.8}/src/agi_med_common/api.py +3 -1
  4. {agi_med_common-5.1.6 → agi_med_common-5.1.8}/src/agi_med_common/file_storage.py +4 -4
  5. {agi_med_common-5.1.6 → agi_med_common-5.1.8}/src/agi_med_common/models/base_config_models/gigachat_config.py +0 -1
  6. {agi_med_common-5.1.6 → agi_med_common-5.1.8}/src/agi_med_common/models/chat.py +25 -3
  7. {agi_med_common-5.1.6 → agi_med_common-5.1.8}/src/agi_med_common/models/chat_item.py +0 -1
  8. {agi_med_common-5.1.6 → agi_med_common-5.1.8}/src/agi_med_common/parallel_map.py +2 -4
  9. {agi_med_common-5.1.6 → agi_med_common-5.1.8}/src/agi_med_common.egg-info/PKG-INFO +1 -1
  10. {agi_med_common-5.1.6 → agi_med_common-5.1.8}/README.md +0 -0
  11. {agi_med_common-5.1.6 → agi_med_common-5.1.8}/pyproject.toml +0 -0
  12. {agi_med_common-5.1.6 → agi_med_common-5.1.8}/setup.cfg +0 -0
  13. {agi_med_common-5.1.6 → agi_med_common-5.1.8}/src/agi_med_common/models/__init__.py +0 -0
  14. {agi_med_common-5.1.6 → agi_med_common-5.1.8}/src/agi_med_common/models/base.py +0 -0
  15. {agi_med_common-5.1.6 → agi_med_common-5.1.8}/src/agi_med_common/models/base_config_models/__init__.py +0 -0
  16. {agi_med_common-5.1.6 → agi_med_common-5.1.8}/src/agi_med_common/models/enums.py +0 -0
  17. {agi_med_common-5.1.6 → agi_med_common-5.1.8}/src/agi_med_common/models/tracks.py +0 -0
  18. {agi_med_common-5.1.6 → agi_med_common-5.1.8}/src/agi_med_common/models/widget.py +0 -0
  19. {agi_med_common-5.1.6 → agi_med_common-5.1.8}/src/agi_med_common/type_union.py +0 -0
  20. {agi_med_common-5.1.6 → agi_med_common-5.1.8}/src/agi_med_common/utils.py +0 -0
  21. {agi_med_common-5.1.6 → agi_med_common-5.1.8}/src/agi_med_common/validators.py +0 -0
  22. {agi_med_common-5.1.6 → agi_med_common-5.1.8}/src/agi_med_common/xml_parser.py +0 -0
  23. {agi_med_common-5.1.6 → agi_med_common-5.1.8}/src/agi_med_common.egg-info/SOURCES.txt +0 -0
  24. {agi_med_common-5.1.6 → agi_med_common-5.1.8}/src/agi_med_common.egg-info/dependency_links.txt +0 -0
  25. {agi_med_common-5.1.6 → agi_med_common-5.1.8}/src/agi_med_common.egg-info/requires.txt +0 -0
  26. {agi_med_common-5.1.6 → agi_med_common-5.1.8}/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.1.6
3
+ Version: 5.1.8
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.1.6"
1
+ __version__ = "5.1.8"
2
2
 
3
3
  from .file_storage import FileStorage, ResourceId
4
4
  from .models.base import Base
@@ -1,6 +1,8 @@
1
1
  from typing import List, Tuple
2
2
 
3
- from agi_med_common.models import Chat, ChatMessage, DomainInfo, TrackInfo
3
+ from agi_med_common.models.chat import Chat, ChatMessage
4
+ from agi_med_common.models.tracks import DomainInfo, TrackInfo
5
+
4
6
  from pydantic import BaseModel
5
7
 
6
8
 
@@ -15,12 +15,12 @@ def _validate_exist(files_dir):
15
15
  def _validate_dtype(dtype: str):
16
16
  if all(map(ASCII_DIGITS.__contains__, dtype)):
17
17
  return
18
- raise ValueError(f'Bad dtype: {dtype}')
18
+ raise ValueError(f"Bad dtype: {dtype}")
19
19
 
20
20
 
21
21
  def generate_fname(content, dtype):
22
22
  fname_hash = md5(content).hexdigest()
23
- fname = f'{fname_hash}.{dtype}'
23
+ fname = f"{fname_hash}.{dtype}"
24
24
  return fname
25
25
 
26
26
 
@@ -54,10 +54,10 @@ class FileStorage:
54
54
  return Path(rid).read_bytes()
55
55
 
56
56
  def download_text(self, rid: ResourceId) -> str:
57
- return Path(rid).read_text(encoding='utf-8')
57
+ return Path(rid).read_text(encoding="utf-8")
58
58
 
59
59
  def is_valid(self, rid: ResourceId | None) -> bool:
60
60
  return rid and Path(rid).exists() and Path(rid).is_file()
61
61
 
62
62
  def get_dtype(self, rid: ResourceId | None) -> str | None:
63
- return rid and rid.rsplit('.')[-1]
63
+ return rid and rid.rsplit(".")[-1]
@@ -4,7 +4,6 @@ from pydantic import BaseModel, model_validator, SecretStr
4
4
 
5
5
 
6
6
  class GigaChatConfig(BaseModel):
7
-
8
7
  client_id: SecretStr = SecretStr("")
9
8
  client_secret: SecretStr = SecretStr("")
10
9
 
@@ -7,7 +7,7 @@ from agi_med_common.models.chat_item import ChatItem, ReplicaItem, OuterContextI
7
7
  from agi_med_common.models.widget import Widget
8
8
  from agi_med_common.type_union import TypeUnion
9
9
  from agi_med_common.utils import first_nonnull
10
- from pydantic import Field, ValidationError
10
+ from pydantic import Field, ValidationError, Extra
11
11
 
12
12
  from .base import Base
13
13
 
@@ -28,7 +28,7 @@ class Context(Base):
28
28
  client_id: str = Field("", examples=["543216789"])
29
29
  user_id: str = Field("", examples=["123456789"])
30
30
  session_id: str = Field("", examples=["987654321"])
31
- track_id: str = Field(examples=["Hello"])
31
+ track_id: str = Field("", examples=["Hello"])
32
32
  extra: StrDict | None = Field(None, examples=[None])
33
33
 
34
34
  def create_id(self, short: bool = False) -> str:
@@ -183,9 +183,18 @@ ChatMessage = TypeUnion[HumanMessage, AIMessage, MiscMessage]
183
183
 
184
184
 
185
185
  class Chat(Base):
186
- context: Context
186
+ context: Context = Field(default_factory=Context)
187
187
  messages: List[ChatMessage] = Field(default_factory=list)
188
188
 
189
+ class Config:
190
+ extra = Extra.ignore
191
+
192
+ def __init__(self, **data):
193
+ extra_fields = set(data.keys()) - set(self.__fields__.keys())
194
+ if extra_fields:
195
+ warnings.warn(f"Chat initialization: extra fields will be ignored: {extra_fields}")
196
+ super().__init__(**data)
197
+
189
198
  def create_id(self, short: bool = False) -> str:
190
199
  return self.context.create_id(short)
191
200
 
@@ -368,8 +377,21 @@ def _parse_chat(chat_obj: str | dict) -> Chat:
368
377
  return Chat.model_validate_json(chat_obj)
369
378
 
370
379
 
380
+ def is_chat_item(chat_obj: str | dict | ChatItem) -> bool:
381
+ if isinstance(chat_obj, ChatItem):
382
+ return True
383
+ if isinstance(chat_obj, dict):
384
+ return "OuterContext" in chat_obj
385
+ if isinstance(chat_obj, str):
386
+ return "OuterContext" in chat_obj
387
+ warnings.warn(f"Unexpected chat object: {chat_obj} :: {type(chat_obj)}")
388
+ return False
389
+
390
+
371
391
  def _parse_chat_compat(chat_obj: str | dict | ChatItem) -> Chat:
372
392
  # legacy: eliminate after migration
393
+ if is_chat_item(chat_obj):
394
+ return parse_chat_item_as_chat(chat_obj)
373
395
  try:
374
396
  return _parse_chat(chat_obj)
375
397
  except ValidationError as ex:
@@ -141,7 +141,6 @@ class ChatItem(Base):
141
141
  return replica.state
142
142
  return default
143
143
 
144
-
145
144
  def zip_history(self, field: str) -> list[Any]:
146
145
  return [replica.to_dict().get(field, None) for replica in self.inner_context.replicas]
147
146
 
@@ -13,7 +13,7 @@ def parallel_map(
13
13
  multiple_args: bool = False,
14
14
  max_workers: int = 2,
15
15
  show_tqdm: bool = False,
16
- desc: str = ""
16
+ desc: str = "",
17
17
  ) -> list[X]:
18
18
  pool = (
19
19
  concurrent.futures.ProcessPoolExecutor(max_workers=max_workers)
@@ -27,7 +27,5 @@ def parallel_map(
27
27
  futures.append(executor.submit(func, *item))
28
28
  else:
29
29
  futures.append(executor.submit(func, item))
30
- results: list[X] = [
31
- future.result() for future in tqdm(futures, disable=(not show_tqdm), desc=desc)
32
- ]
30
+ results: list[X] = [future.result() for future in tqdm(futures, disable=(not show_tqdm), desc=desc)]
33
31
  return results
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: agi_med_common
3
- Version: 5.1.6
3
+ Version: 5.1.8
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