agi-med-common 3.2.1__tar.gz → 3.3.1__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.
- {agi_med_common-3.2.1 → agi_med_common-3.3.1}/PKG-INFO +1 -1
- {agi_med_common-3.2.1 → agi_med_common-3.3.1}/src/agi_med_common/__init__.py +3 -4
- {agi_med_common-3.2.1 → agi_med_common-3.3.1}/src/agi_med_common/logger/logger.py +1 -1
- {agi_med_common-3.2.1 → agi_med_common-3.3.1}/src/agi_med_common/models/__init__.py +1 -1
- {agi_med_common-3.2.1 → agi_med_common-3.3.1}/src/agi_med_common/models/chat_item/__init__.py +1 -1
- agi_med_common-3.3.1/src/agi_med_common/models/chat_item/chat_item.py +34 -0
- {agi_med_common-3.2.1 → agi_med_common-3.3.1}/src/agi_med_common/models/chat_item/inner_context_item.py +3 -0
- {agi_med_common-3.2.1 → agi_med_common-3.3.1}/src/agi_med_common/models/chat_item/outer_context_item.py +9 -3
- agi_med_common-3.3.1/src/agi_med_common/models/chat_item/replica_item.py +35 -0
- agi_med_common-3.3.1/src/agi_med_common/xml_parser.py +17 -0
- {agi_med_common-3.2.1 → agi_med_common-3.3.1}/src/agi_med_common.egg-info/PKG-INFO +1 -1
- {agi_med_common-3.2.1 → agi_med_common-3.3.1}/src/agi_med_common.egg-info/SOURCES.txt +1 -4
- agi_med_common-3.2.1/src/agi_med_common/models/chat_item/chat_item.py +0 -9
- agi_med_common-3.2.1/src/agi_med_common/models/chat_item/replica_item.py +0 -31
- agi_med_common-3.2.1/src/agi_med_common/models/chat_item_with_state/__init__.py +0 -3
- agi_med_common-3.2.1/src/agi_med_common/models/chat_item_with_state/chat_with_state.py +0 -8
- agi_med_common-3.2.1/src/agi_med_common/models/chat_item_with_state/inner_context_with_state.py +0 -8
- agi_med_common-3.2.1/src/agi_med_common/models/chat_item_with_state/replica_with_state.py +0 -8
- {agi_med_common-3.2.1 → agi_med_common-3.3.1}/README.md +0 -0
- {agi_med_common-3.2.1 → agi_med_common-3.3.1}/pyproject.toml +0 -0
- {agi_med_common-3.2.1 → agi_med_common-3.3.1}/requirements.txt +0 -0
- {agi_med_common-3.2.1 → agi_med_common-3.3.1}/setup.cfg +0 -0
- {agi_med_common-3.2.1 → agi_med_common-3.3.1}/src/agi_med_common/logger/__init__.py +0 -0
- {agi_med_common-3.2.1 → agi_med_common-3.3.1}/src/agi_med_common/logger/log_level_enum.py +0 -0
- {agi_med_common-3.2.1 → agi_med_common-3.3.1}/src/agi_med_common/models/_base.py +0 -0
- {agi_med_common-3.2.1 → agi_med_common-3.3.1}/src/agi_med_common/models/base_config_models/__init__.py +0 -0
- {agi_med_common-3.2.1 → agi_med_common-3.3.1}/src/agi_med_common/models/base_config_models/gigachat_config.py +0 -0
- {agi_med_common-3.2.1 → agi_med_common-3.3.1}/src/agi_med_common/models/enums/__init__.py +0 -0
- {agi_med_common-3.2.1 → agi_med_common-3.3.1}/src/agi_med_common/models/enums/action_enum.py +0 -0
- {agi_med_common-3.2.1 → agi_med_common-3.3.1}/src/agi_med_common/models/enums/moderation_label_enum.py +0 -0
- {agi_med_common-3.2.1 → agi_med_common-3.3.1}/src/agi_med_common/models/enums/mtrs_label_enum.py +0 -0
- {agi_med_common-3.2.1 → agi_med_common-3.3.1}/src/agi_med_common/models/enums/state_enum.py +0 -0
- {agi_med_common-3.2.1 → agi_med_common-3.3.1}/src/agi_med_common/models/enums/track_id_enum.py +0 -0
- {agi_med_common-3.2.1 → agi_med_common-3.3.1}/src/agi_med_common/utils.py +0 -0
- {agi_med_common-3.2.1 → agi_med_common-3.3.1}/src/agi_med_common/validators.py +0 -0
- {agi_med_common-3.2.1 → agi_med_common-3.3.1}/src/agi_med_common.egg-info/dependency_links.txt +0 -0
- {agi_med_common-3.2.1 → agi_med_common-3.3.1}/src/agi_med_common.egg-info/requires.txt +0 -0
- {agi_med_common-3.2.1 → agi_med_common-3.3.1}/src/agi_med_common.egg-info/top_level.txt +0 -0
@@ -1,4 +1,4 @@
|
|
1
|
-
__version__ = "3.
|
1
|
+
__version__ = "3.3.1"
|
2
2
|
|
3
3
|
from .logger import LogLevelEnum, logger_init
|
4
4
|
from .models import (
|
@@ -11,9 +11,8 @@ from .models import (
|
|
11
11
|
InnerContextItem,
|
12
12
|
OuterContextItem,
|
13
13
|
ReplicaItem,
|
14
|
-
|
15
|
-
InnerContextWithState,
|
16
|
-
ReplicaWithState,
|
14
|
+
ReplicaItemPair,
|
17
15
|
)
|
18
16
|
from .utils import make_session_id, read_json, replace_n
|
19
17
|
from .validators import is_file_exist, validate_prompt
|
18
|
+
from .xml_parser import XMLParser
|
@@ -7,7 +7,7 @@ from . import LogLevelEnum
|
|
7
7
|
|
8
8
|
def logger_init(log_level: LogLevelEnum) -> None:
|
9
9
|
logger.remove()
|
10
|
-
extra = {"request_id": "
|
10
|
+
extra = {"request_id": "SYSTEM_REQUEST"}
|
11
11
|
format_ = "{time:DD-MM-YYYY HH:mm:ss} | <level>{level: <8}</level> | {extra[request_id]}"
|
12
12
|
format_ = f"{format_} | <level>{{message}}</level>"
|
13
13
|
logger.add(sys.stdout, colorize=True, format=format_, level=log_level)
|
@@ -1,5 +1,5 @@
|
|
1
1
|
from ._base import _Base
|
2
2
|
from .enums import TrackIdEnum, StateEnum, MTRSLabelEnum, ActionEnum, ModerationLabelEnum
|
3
|
-
from .chat_item import ChatItem, OuterContextItem, InnerContextItem, ReplicaItem
|
3
|
+
from .chat_item import ChatItem, OuterContextItem, InnerContextItem, ReplicaItem, ReplicaItemPair
|
4
4
|
from .chat_item_with_state import ChatItemWithState, InnerContextWithState, ReplicaWithState
|
5
5
|
from .base_config_models import GigaChatConfig
|
@@ -0,0 +1,34 @@
|
|
1
|
+
from pydantic import Field
|
2
|
+
from typing import Any
|
3
|
+
|
4
|
+
from . import OuterContextItem, InnerContextItem, ReplicaItemPair
|
5
|
+
from ..enums import ActionEnum
|
6
|
+
from .. import _Base
|
7
|
+
|
8
|
+
|
9
|
+
class ChatItem(_Base):
|
10
|
+
outer_context: OuterContextItem = Field(alias="OuterContext")
|
11
|
+
inner_context: InnerContextItem = Field(alias="InnerContext")
|
12
|
+
|
13
|
+
def create_id(self, short: bool = False, clean: bool = False) -> str:
|
14
|
+
return self.outer_context.create_id(short, clean)
|
15
|
+
|
16
|
+
def to_dict(self) -> dict[str, Any]:
|
17
|
+
return self.model_dump(by_alias=True)
|
18
|
+
|
19
|
+
def update(self, replica_pair: ReplicaItemPair) -> None:
|
20
|
+
self.inner_context.replicas.append(replica_pair.user_replica)
|
21
|
+
self.inner_context.replicas.append(replica_pair.model_replica)
|
22
|
+
|
23
|
+
def count_questions(self) -> int:
|
24
|
+
return len(
|
25
|
+
list(
|
26
|
+
filter(
|
27
|
+
lambda replica: replica.role and replica.action == ActionEnum.QUESTION,
|
28
|
+
self.inner_context.replicas,
|
29
|
+
)
|
30
|
+
)
|
31
|
+
)
|
32
|
+
|
33
|
+
def zip_history(self, field: str) -> list[Any]:
|
34
|
+
return [replica.to_dict().get(field, None) for replica in self.inner_context.replicas]
|
@@ -1,4 +1,5 @@
|
|
1
1
|
from pydantic import Field
|
2
|
+
from typing import Any
|
2
3
|
|
3
4
|
from .. import _Base
|
4
5
|
from ..enums import TrackIdEnum
|
@@ -10,9 +11,14 @@ class OuterContextItem(_Base):
|
|
10
11
|
user_id: str = Field("", alias="UserId", examples=["123456789"])
|
11
12
|
session_id: str = Field("", alias="SessionId", examples=["987654321"])
|
12
13
|
client_id: str = Field("", alias="ClientId", examples=["543216789"])
|
13
|
-
track_id: TrackIdEnum = Field(TrackIdEnum.
|
14
|
+
track_id: TrackIdEnum = Field(TrackIdEnum.CONSULTATION, alias="TrackId")
|
14
15
|
|
15
|
-
def create_id(self, short: bool = False) -> str:
|
16
|
+
def create_id(self, short: bool = False, clean: bool = False) -> str:
|
16
17
|
if short:
|
17
18
|
return f"{self.user_id}_{self.session_id}_{self.client_id}"
|
18
|
-
|
19
|
+
if not clean:
|
20
|
+
return f"user_{self.user_id}_session_{self.session_id}_client_{self.client_id}"
|
21
|
+
return f"user_{self.user_id}_session_{self.session_id}_client_{self.client_id}_clean"
|
22
|
+
|
23
|
+
def to_dict(self) -> dict[str, Any]:
|
24
|
+
return self.model_dump(by_alias=True)
|
@@ -0,0 +1,35 @@
|
|
1
|
+
from datetime import datetime
|
2
|
+
from typing import Any
|
3
|
+
|
4
|
+
from pydantic import Field
|
5
|
+
|
6
|
+
from .. import _Base
|
7
|
+
from ..enums import StateEnum, ActionEnum
|
8
|
+
|
9
|
+
_TIME_FORMAT: str = "%Y-%m-%d-%H-%M-%S"
|
10
|
+
_EXAMPLE_DATETIME: str = datetime(1970, 1, 1, 0, 0, 0).strftime(_TIME_FORMAT)
|
11
|
+
|
12
|
+
|
13
|
+
class ReplicaItem(_Base):
|
14
|
+
body: str = Field("", alias="Body", examples=["Привет"])
|
15
|
+
role: bool = Field(False, alias="Role", description="True = ai, False = client", examples=[False])
|
16
|
+
date_time: str = Field(
|
17
|
+
_EXAMPLE_DATETIME,
|
18
|
+
alias="DateTime",
|
19
|
+
examples=[_EXAMPLE_DATETIME],
|
20
|
+
description=f"Format: {_TIME_FORMAT}",
|
21
|
+
)
|
22
|
+
state: StateEnum = Field(
|
23
|
+
StateEnum.EMPTY, alias="State", description="chat manager fsm state", examples=[StateEnum.COLLECTION]
|
24
|
+
)
|
25
|
+
action: ActionEnum = Field(
|
26
|
+
ActionEnum.START, alias="Action", description="chat manager fsm action", examples=[ActionEnum.DIAGNOSIS]
|
27
|
+
)
|
28
|
+
|
29
|
+
def to_dict(self) -> dict[str, Any]:
|
30
|
+
return self.model_dump(by_alias=True)
|
31
|
+
|
32
|
+
|
33
|
+
class ReplicaItemPair(_Base):
|
34
|
+
user_replica: ReplicaItem = Field(alias="UserReplica")
|
35
|
+
model_replica: ReplicaItem = Field(alias="ModelReplica")
|
@@ -0,0 +1,17 @@
|
|
1
|
+
import re
|
2
|
+
|
3
|
+
|
4
|
+
class XMLParser:
|
5
|
+
@staticmethod
|
6
|
+
def make_xml(body: str, tag: str) -> str:
|
7
|
+
return f"<{tag}>{body}</{tag}>"
|
8
|
+
|
9
|
+
@staticmethod
|
10
|
+
def remove_xml(text: str) -> str:
|
11
|
+
re_xml = re.compile(r"<(.*?)>")
|
12
|
+
return re.sub(re_xml, "", text).replace(" ", " ").strip()
|
13
|
+
|
14
|
+
@staticmethod
|
15
|
+
def get_tag_list(response: str, tag: str) -> list[str]:
|
16
|
+
tag_content = re.findall(f"<{tag}>(.*?)</{tag}>", response, re.DOTALL)
|
17
|
+
return [content.lower().strip() for content in tag_content]
|
@@ -4,6 +4,7 @@ requirements.txt
|
|
4
4
|
src/agi_med_common/__init__.py
|
5
5
|
src/agi_med_common/utils.py
|
6
6
|
src/agi_med_common/validators.py
|
7
|
+
src/agi_med_common/xml_parser.py
|
7
8
|
src/agi_med_common.egg-info/PKG-INFO
|
8
9
|
src/agi_med_common.egg-info/SOURCES.txt
|
9
10
|
src/agi_med_common.egg-info/dependency_links.txt
|
@@ -21,10 +22,6 @@ src/agi_med_common/models/chat_item/chat_item.py
|
|
21
22
|
src/agi_med_common/models/chat_item/inner_context_item.py
|
22
23
|
src/agi_med_common/models/chat_item/outer_context_item.py
|
23
24
|
src/agi_med_common/models/chat_item/replica_item.py
|
24
|
-
src/agi_med_common/models/chat_item_with_state/__init__.py
|
25
|
-
src/agi_med_common/models/chat_item_with_state/chat_with_state.py
|
26
|
-
src/agi_med_common/models/chat_item_with_state/inner_context_with_state.py
|
27
|
-
src/agi_med_common/models/chat_item_with_state/replica_with_state.py
|
28
25
|
src/agi_med_common/models/enums/__init__.py
|
29
26
|
src/agi_med_common/models/enums/action_enum.py
|
30
27
|
src/agi_med_common/models/enums/moderation_label_enum.py
|
@@ -1,31 +0,0 @@
|
|
1
|
-
from datetime import datetime
|
2
|
-
|
3
|
-
from pydantic import Field, field_validator, field_serializer
|
4
|
-
|
5
|
-
from .. import _Base
|
6
|
-
|
7
|
-
_TIME_FORMAT: str = "%Y-%m-%d-%H-%M-%S"
|
8
|
-
_EXAMPLE_DATETIME: datetime = datetime(1970, 1, 1, 0, 0, 0)
|
9
|
-
|
10
|
-
|
11
|
-
class ReplicaItem(_Base):
|
12
|
-
body: str = Field("", alias="Body", examples=["Привет"])
|
13
|
-
role: bool = Field(False, alias="Role", description="True = ai, False = client", examples=[False])
|
14
|
-
date_time: datetime = Field(
|
15
|
-
_EXAMPLE_DATETIME,
|
16
|
-
alias="DateTime",
|
17
|
-
examples=[_EXAMPLE_DATETIME.strftime(_TIME_FORMAT)],
|
18
|
-
description=f"Format: {_TIME_FORMAT}",
|
19
|
-
)
|
20
|
-
previous_score: float | None = Field(None, alias="PreviousScore", exclude=True, deprecated=True)
|
21
|
-
|
22
|
-
@field_validator("date_time", mode="before")
|
23
|
-
@classmethod
|
24
|
-
def convert_date_time(cls, timestamp: str | datetime) -> datetime:
|
25
|
-
if isinstance(timestamp, datetime):
|
26
|
-
return timestamp
|
27
|
-
return datetime.strptime(timestamp, _TIME_FORMAT)
|
28
|
-
|
29
|
-
@field_serializer("date_time")
|
30
|
-
def serialize_date_time(self, timestamp: datetime) -> str:
|
31
|
-
return timestamp.strftime(_TIME_FORMAT)
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
{agi_med_common-3.2.1 → agi_med_common-3.3.1}/src/agi_med_common/models/enums/action_enum.py
RENAMED
File without changes
|
File without changes
|
{agi_med_common-3.2.1 → agi_med_common-3.3.1}/src/agi_med_common/models/enums/mtrs_label_enum.py
RENAMED
File without changes
|
File without changes
|
{agi_med_common-3.2.1 → agi_med_common-3.3.1}/src/agi_med_common/models/enums/track_id_enum.py
RENAMED
File without changes
|
File without changes
|
File without changes
|
{agi_med_common-3.2.1 → agi_med_common-3.3.1}/src/agi_med_common.egg-info/dependency_links.txt
RENAMED
File without changes
|
File without changes
|
File without changes
|