agi-med-common 5.1.6__py3-none-any.whl → 5.1.8__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/api.py +3 -1
- agi_med_common/file_storage.py +4 -4
- agi_med_common/models/base_config_models/gigachat_config.py +0 -1
- agi_med_common/models/chat.py +25 -3
- agi_med_common/models/chat_item.py +0 -1
- agi_med_common/parallel_map.py +2 -4
- {agi_med_common-5.1.6.dist-info → agi_med_common-5.1.8.dist-info}/METADATA +1 -1
- {agi_med_common-5.1.6.dist-info → agi_med_common-5.1.8.dist-info}/RECORD +11 -11
- {agi_med_common-5.1.6.dist-info → agi_med_common-5.1.8.dist-info}/WHEEL +0 -0
- {agi_med_common-5.1.6.dist-info → agi_med_common-5.1.8.dist-info}/top_level.txt +0 -0
agi_med_common/__init__.py
CHANGED
agi_med_common/api.py
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
from typing import List, Tuple
|
2
2
|
|
3
|
-
from agi_med_common.models import Chat, ChatMessage
|
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
|
|
agi_med_common/file_storage.py
CHANGED
@@ -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
|
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
|
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=
|
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(
|
63
|
+
return rid and rid.rsplit(".")[-1]
|
agi_med_common/models/chat.py
CHANGED
@@ -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:
|
agi_med_common/parallel_map.py
CHANGED
@@ -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,21 +1,21 @@
|
|
1
|
-
agi_med_common/__init__.py,sha256=
|
2
|
-
agi_med_common/api.py,sha256=
|
3
|
-
agi_med_common/file_storage.py,sha256=
|
4
|
-
agi_med_common/parallel_map.py,sha256=
|
1
|
+
agi_med_common/__init__.py,sha256=aXn_rUR5Xf20VlJInpgXkZkzfJQFynJMnlzM8bE-LiU,828
|
2
|
+
agi_med_common/api.py,sha256=aKiqLtliBQfFPGB9Rc46XxrWuf7cI5DgpM0B6p823i8,1874
|
3
|
+
agi_med_common/file_storage.py,sha256=lEh9TyzUu8dS9WkaEcshSUxESXQ1i7PAyXqejdambpg,1802
|
4
|
+
agi_med_common/parallel_map.py,sha256=WuS4x1mbyGnjp6lSvfORoxt0Sh5v3HiX3THB8JzIQ-0,900
|
5
5
|
agi_med_common/type_union.py,sha256=diwmzcnbqkpGFckPHNw9o8zyQ955mOGNvhTlcBJ0RMI,1905
|
6
6
|
agi_med_common/utils.py,sha256=EeeXRv5BjrB-_GtHzI3V5swyVO0KPR-SMpjHRx2r2aM,1560
|
7
7
|
agi_med_common/validators.py,sha256=vMoPN42XzC8re-zdjekk5_lNQYHuTiAWD56YLvj2Z2w,2824
|
8
8
|
agi_med_common/xml_parser.py,sha256=VvLIX_XCZao9i0qqpTVx8nx0vbFXSe8pEbdJdXnj97g,568
|
9
9
|
agi_med_common/models/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
10
10
|
agi_med_common/models/base.py,sha256=mKtXV2x51XVj7W-et9tjGcPMDUUUMelW-BywMgFc2p0,411
|
11
|
-
agi_med_common/models/chat.py,sha256=
|
12
|
-
agi_med_common/models/chat_item.py,sha256=
|
11
|
+
agi_med_common/models/chat.py,sha256=LcmclAC16wBRQJ4YfehM-bLb24RpYQKi5ENz_bcKJWA,12327
|
12
|
+
agi_med_common/models/chat_item.py,sha256=03YW6Exx3pDC4IsI2lsS_3_cYAwbqjYml2l9CpPMHVs,5541
|
13
13
|
agi_med_common/models/enums.py,sha256=J-GNpql9MCnKnWiV9aJRQGI-pAybvV86923RZs99grA,1006
|
14
14
|
agi_med_common/models/tracks.py,sha256=HKDp-BX1p7AlDfSEKfOKCu0TRSK9cD4Dmq1vJt8oRjw,307
|
15
15
|
agi_med_common/models/widget.py,sha256=aJZ2vWx_PTFN02Wz16eokz9IIVrxqNuZYVDqLG36toE,710
|
16
16
|
agi_med_common/models/base_config_models/__init__.py,sha256=KjS_bSCka8BOMsigwcIML-e6eNB2ouMU6gxlhRmzeuY,44
|
17
|
-
agi_med_common/models/base_config_models/gigachat_config.py,sha256=
|
18
|
-
agi_med_common-5.1.
|
19
|
-
agi_med_common-5.1.
|
20
|
-
agi_med_common-5.1.
|
21
|
-
agi_med_common-5.1.
|
17
|
+
agi_med_common/models/base_config_models/gigachat_config.py,sha256=QvKTnp0VioXzd3_PUgNBeYx5RDTZT-45j-Ll-wXEI_o,421
|
18
|
+
agi_med_common-5.1.8.dist-info/METADATA,sha256=UYw1CJGNb4G5ouvAMi4tQLyAUViVVf7ogYl9vIeH-mY,517
|
19
|
+
agi_med_common-5.1.8.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
20
|
+
agi_med_common-5.1.8.dist-info/top_level.txt,sha256=26o565jF_7wYQj7-YJfTedtT9yDxDcf8RNikOYuPq78,15
|
21
|
+
agi_med_common-5.1.8.dist-info/RECORD,,
|
File without changes
|
File without changes
|