mmar-mapi 1.0.6__tar.gz → 1.0.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.
Potentially problematic release.
This version of mmar-mapi might be problematic. Click here for more details.
- {mmar_mapi-1.0.6 → mmar_mapi-1.0.8}/PKG-INFO +1 -1
- {mmar_mapi-1.0.6 → mmar_mapi-1.0.8}/pyproject.toml +2 -1
- mmar_mapi-1.0.8/src/mmar_mapi/__init__.py +47 -0
- {mmar_mapi-1.0.6 → mmar_mapi-1.0.8}/src/mmar_mapi/models/chat.py +36 -9
- {mmar_mapi-1.0.6 → mmar_mapi-1.0.8}/src/mmar_mapi/models/widget.py +20 -0
- mmar_mapi-1.0.6/src/mmar_mapi/__init__.py +0 -12
- mmar_mapi-1.0.6/src/mmar_mapi/models/base_config_models/__init__.py +0 -1
- mmar_mapi-1.0.6/src/mmar_mapi/models/base_config_models/gigachat_config.py +0 -14
- {mmar_mapi-1.0.6 → mmar_mapi-1.0.8}/LICENSE +0 -0
- {mmar_mapi-1.0.6 → mmar_mapi-1.0.8}/README.md +0 -0
- {mmar_mapi-1.0.6 → mmar_mapi-1.0.8}/src/mmar_mapi/api.py +0 -0
- {mmar_mapi-1.0.6 → mmar_mapi-1.0.8}/src/mmar_mapi/file_storage.py +0 -0
- {mmar_mapi-1.0.6 → mmar_mapi-1.0.8}/src/mmar_mapi/models/__init__.py +0 -0
- {mmar_mapi-1.0.6 → mmar_mapi-1.0.8}/src/mmar_mapi/models/base.py +0 -0
- {mmar_mapi-1.0.6 → mmar_mapi-1.0.8}/src/mmar_mapi/models/chat_item.py +0 -0
- {mmar_mapi-1.0.6 → mmar_mapi-1.0.8}/src/mmar_mapi/models/enums.py +0 -0
- {mmar_mapi-1.0.6 → mmar_mapi-1.0.8}/src/mmar_mapi/models/tracks.py +0 -0
- {mmar_mapi-1.0.6 → mmar_mapi-1.0.8}/src/mmar_mapi/type_union.py +0 -0
- {mmar_mapi-1.0.6 → mmar_mapi-1.0.8}/src/mmar_mapi/utils.py +0 -0
- {mmar_mapi-1.0.6 → mmar_mapi-1.0.8}/src/mmar_mapi/xml_parser.py +0 -0
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "mmar-mapi"
|
|
3
3
|
# dynamic version is not supported yet on uv_build
|
|
4
|
-
version = "1.0.
|
|
4
|
+
version = "1.0.8"
|
|
5
5
|
description = "Common pure/IO utilities for multi-modal architectures team"
|
|
6
6
|
authors = [{name = "Eugene Tagin", email = "tagin@airi.net"}]
|
|
7
7
|
license = "MIT"
|
|
@@ -51,6 +51,7 @@ ci = [
|
|
|
51
51
|
"mypy>=1.10",
|
|
52
52
|
"types-markdown>=3.6",
|
|
53
53
|
"types-pyyaml>=6.0",
|
|
54
|
+
"more-itertools>=10.8.0",
|
|
54
55
|
]
|
|
55
56
|
|
|
56
57
|
[tool.uv]
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
from .file_storage import FileStorage, ResourceId
|
|
2
|
+
from .models.base import Base
|
|
3
|
+
from .models.chat import (
|
|
4
|
+
Chat,
|
|
5
|
+
Context,
|
|
6
|
+
ChatMessage,
|
|
7
|
+
AIMessage,
|
|
8
|
+
HumanMessage,
|
|
9
|
+
MiscMessage,
|
|
10
|
+
make_content,
|
|
11
|
+
Content,
|
|
12
|
+
BaseMessage,
|
|
13
|
+
)
|
|
14
|
+
from .models.chat_item import ChatItem, OuterContextItem, InnerContextItem, ReplicaItem
|
|
15
|
+
from .models.enums import MTRSLabelEnum, DiagnosticsXMLTagEnum, MTRSXMLTagEnum, DoctorChoiceXMLTagEnum
|
|
16
|
+
from .models.tracks import TrackInfo, DomainInfo
|
|
17
|
+
from .models.widget import Widget
|
|
18
|
+
from .utils import make_session_id
|
|
19
|
+
from .xml_parser import XMLParser
|
|
20
|
+
|
|
21
|
+
__all__ = [
|
|
22
|
+
"AIMessage",
|
|
23
|
+
"Base",
|
|
24
|
+
"BaseMessage",
|
|
25
|
+
"Chat",
|
|
26
|
+
"ChatItem",
|
|
27
|
+
"ChatMessage",
|
|
28
|
+
"Content",
|
|
29
|
+
"Context",
|
|
30
|
+
"DiagnosticsXMLTagEnum",
|
|
31
|
+
"DoctorChoiceXMLTagEnum",
|
|
32
|
+
"DomainInfo",
|
|
33
|
+
"FileStorage",
|
|
34
|
+
"HumanMessage",
|
|
35
|
+
"InnerContextItem",
|
|
36
|
+
"MTRSLabelEnum",
|
|
37
|
+
"MTRSXMLTagEnum",
|
|
38
|
+
"MiscMessage",
|
|
39
|
+
"OuterContextItem",
|
|
40
|
+
"ReplicaItem",
|
|
41
|
+
"ResourceId",
|
|
42
|
+
"TrackInfo",
|
|
43
|
+
"Widget",
|
|
44
|
+
"XMLParser",
|
|
45
|
+
"make_content",
|
|
46
|
+
"make_session_id",
|
|
47
|
+
]
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import warnings
|
|
2
|
+
from collections.abc import Callable
|
|
2
3
|
from copy import deepcopy
|
|
3
4
|
from datetime import datetime
|
|
4
5
|
from typing import Any, Literal, TypeVar
|
|
5
|
-
from collections.abc import Callable
|
|
6
6
|
|
|
7
7
|
from mmar_mapi.models.chat_item import ChatItem, ReplicaItem, OuterContextItem
|
|
8
8
|
from mmar_mapi.models.widget import Widget
|
|
9
9
|
from mmar_mapi.type_union import TypeUnion
|
|
10
|
-
from pydantic import Field, ValidationError
|
|
10
|
+
from pydantic import Field, ValidationError
|
|
11
11
|
|
|
12
12
|
from .base import Base
|
|
13
13
|
|
|
@@ -146,10 +146,6 @@ class BaseMessage(Base):
|
|
|
146
146
|
def widget(self) -> Widget | None:
|
|
147
147
|
return _get_widget(self.content)
|
|
148
148
|
|
|
149
|
-
@staticmethod
|
|
150
|
-
def DATETIME_FORMAT() -> str:
|
|
151
|
-
return _DT_FORMAT
|
|
152
|
-
|
|
153
149
|
def with_now_datetime(self):
|
|
154
150
|
return self.model_copy(update=dict(date_time=now_pretty()))
|
|
155
151
|
|
|
@@ -161,6 +157,21 @@ class BaseMessage(Base):
|
|
|
161
157
|
def is_human(self):
|
|
162
158
|
return self.type == "human"
|
|
163
159
|
|
|
160
|
+
@staticmethod
|
|
161
|
+
def DATETIME_FORMAT() -> str:
|
|
162
|
+
return _DT_FORMAT
|
|
163
|
+
|
|
164
|
+
@staticmethod
|
|
165
|
+
def find_resource_id(msg: "BaseMessage", ext: str | None = None, type: str=None) -> str | None:
|
|
166
|
+
resource_id = msg.resource_id
|
|
167
|
+
if type and type != msg.type:
|
|
168
|
+
return None
|
|
169
|
+
if not resource_id:
|
|
170
|
+
return None
|
|
171
|
+
if ext and not resource_id.endswith(ext):
|
|
172
|
+
return None
|
|
173
|
+
return resource_id
|
|
174
|
+
|
|
164
175
|
|
|
165
176
|
class HumanMessage(BaseMessage):
|
|
166
177
|
type: Literal["human"] = "human"
|
|
@@ -182,15 +193,18 @@ class MiscMessage(BaseMessage):
|
|
|
182
193
|
ChatMessage = TypeUnion[HumanMessage, AIMessage, MiscMessage]
|
|
183
194
|
|
|
184
195
|
|
|
196
|
+
def find_in_messages(messages: list[ChatMessage], func: Callable[[ChatMessage], T | None]) -> T | None:
|
|
197
|
+
return next(filter(None, map(func, messages)), None)
|
|
198
|
+
|
|
199
|
+
|
|
185
200
|
class Chat(Base):
|
|
186
201
|
context: Context = Field(default_factory=Context)
|
|
187
202
|
messages: list[ChatMessage] = Field(default_factory=list)
|
|
188
203
|
|
|
189
|
-
|
|
190
|
-
extra = Extra.ignore
|
|
204
|
+
model_config = {"extra": "ignore"}
|
|
191
205
|
|
|
192
206
|
def __init__(self, **data):
|
|
193
|
-
extra_fields = set(data.keys()) - set(self.
|
|
207
|
+
extra_fields = set(data.keys()) - set(type(self).model_fields.keys())
|
|
194
208
|
if extra_fields:
|
|
195
209
|
warnings.warn(f"Chat initialization: extra fields will be ignored: {extra_fields}")
|
|
196
210
|
super().__init__(**data)
|
|
@@ -222,6 +236,19 @@ class Chat(Base):
|
|
|
222
236
|
return message.state
|
|
223
237
|
return default
|
|
224
238
|
|
|
239
|
+
def find_in_messages(self, func: Callable[[ChatMessage], T | None]) -> T | None:
|
|
240
|
+
return find_in_messages(self.messages, func)
|
|
241
|
+
|
|
242
|
+
def rfind_in_messages(self, func: Callable[[ChatMessage], T | None]) -> T | None:
|
|
243
|
+
return find_in_messages(self.messages[::-1], func)
|
|
244
|
+
|
|
245
|
+
def get_last_user_message(self) -> HumanMessage | None:
|
|
246
|
+
messages = self.messages
|
|
247
|
+
if not messages:
|
|
248
|
+
return []
|
|
249
|
+
message = messages[-1]
|
|
250
|
+
return message if isinstance(message, HumanMessage) else None
|
|
251
|
+
|
|
225
252
|
|
|
226
253
|
def make_content(
|
|
227
254
|
text: str | None = None,
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
from typing import Self, Literal
|
|
2
2
|
|
|
3
|
+
from more_itertools import chunked
|
|
3
4
|
from pydantic import BaseModel, model_validator
|
|
4
5
|
|
|
5
6
|
|
|
@@ -20,3 +21,22 @@ class Widget(BaseModel):
|
|
|
20
21
|
continue
|
|
21
22
|
raise ValueError(f"Expected buttons like `<callback>:<caption>`, found: {btn}")
|
|
22
23
|
return self
|
|
24
|
+
|
|
25
|
+
@staticmethod
|
|
26
|
+
def make_inline_buttons(ibuttons: dict[str, str], by=1) -> "Widget":
|
|
27
|
+
return _make_inline_buttons(ibuttons=ibuttons, by=by)
|
|
28
|
+
|
|
29
|
+
@staticmethod
|
|
30
|
+
def make_buttons(buttons: list[str], by=1) -> "Widget":
|
|
31
|
+
return _make_buttons(buttons=buttons, by=1)
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def _make_inline_buttons(ibuttons: dict[str, str], by=1) -> "Widget":
|
|
35
|
+
ibs0 = [f"{key}:{val}" for key, val in ibuttons.items()]
|
|
36
|
+
res = Widget(ibuttons=list(chunked(ibs0, n=by)))
|
|
37
|
+
return res
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def _make_buttons(buttons: list[str], by=1) -> "Widget":
|
|
41
|
+
res = Widget(buttons=list(chunked(buttons, n=by)))
|
|
42
|
+
return res
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
__version__ = "5.2.4"
|
|
2
|
-
|
|
3
|
-
from .file_storage import FileStorage, ResourceId
|
|
4
|
-
from .models.base import Base
|
|
5
|
-
from .models.base_config_models import GigaChatConfig
|
|
6
|
-
from .models.chat import Chat, Context, ChatMessage, AIMessage, HumanMessage, MiscMessage, make_content, Content
|
|
7
|
-
from .models.chat_item import ChatItem, OuterContextItem, InnerContextItem, ReplicaItem
|
|
8
|
-
from .models.enums import MTRSLabelEnum, DiagnosticsXMLTagEnum, MTRSXMLTagEnum, DoctorChoiceXMLTagEnum
|
|
9
|
-
from .models.tracks import TrackInfo, DomainInfo
|
|
10
|
-
from .models.widget import Widget
|
|
11
|
-
from .utils import make_session_id
|
|
12
|
-
from .xml_parser import XMLParser
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
from .gigachat_config import GigaChatConfig
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
from typing import Self
|
|
2
|
-
|
|
3
|
-
from pydantic import BaseModel, model_validator, SecretStr
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
class GigaChatConfig(BaseModel):
|
|
7
|
-
client_id: SecretStr = SecretStr("")
|
|
8
|
-
client_secret: SecretStr = SecretStr("")
|
|
9
|
-
|
|
10
|
-
@model_validator(mode="after")
|
|
11
|
-
def empty_validator(self) -> Self:
|
|
12
|
-
if not (self.client_id and self.client_secret):
|
|
13
|
-
raise ValueError("creds for gigachat is not filled")
|
|
14
|
-
return self
|
|
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
|
|
File without changes
|
|
File without changes
|