unique_toolkit 0.5.37__py3-none-any.whl → 0.5.38__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.
@@ -14,6 +14,8 @@ from pydantic import (
14
14
  model_validator,
15
15
  )
16
16
 
17
+ from unique_toolkit.language_model.utils import format_message
18
+
17
19
  # set config to convert camelCase to snake_case
18
20
  model_config = ConfigDict(
19
21
  alias_generator=camelize,
@@ -88,6 +90,9 @@ class LanguageModelMessage(BaseModel):
88
90
  content: Optional[str | list[dict]] = None
89
91
  tool_calls: Optional[list[LanguageModelFunctionCall]] = None
90
92
 
93
+ def __str__(self):
94
+ return format_message(self.role.capitalize(), message=self.content, num_tabs=1)
95
+
91
96
 
92
97
  class LanguageModelSystemMessage(LanguageModelMessage):
93
98
  role: LanguageModelMessageRole = LanguageModelMessageRole.SYSTEM
@@ -118,6 +123,13 @@ class LanguageModelToolMessage(LanguageModelMessage):
118
123
  name: str
119
124
  tool_call_id: str
120
125
 
126
+ def __str__(self):
127
+ return format_message(
128
+ user=self.role.capitalize(),
129
+ message=f"{self.name}, {self.tool_call_id}, {self.content}",
130
+ num_tabs=1,
131
+ )
132
+
121
133
  @field_validator("role", mode="before")
122
134
  def set_role(cls, value):
123
135
  return LanguageModelMessageRole.TOOL
@@ -132,6 +144,9 @@ class LanguageModelMessages(RootModel):
132
144
  | LanguageModelUserMessage
133
145
  ]
134
146
 
147
+ def __str__(self):
148
+ return "\n\n".join([str(message) for message in self.root])
149
+
135
150
  def __iter__(self):
136
151
  return iter(self.root)
137
152
 
@@ -42,3 +42,27 @@ def find_last_json_object(text: str) -> str | None:
42
42
  return matches[-1]
43
43
  else:
44
44
  return None
45
+
46
+
47
+ def format_message(user: str, message: str, num_tabs: int = 1) -> str:
48
+ """
49
+ Formats a message from a user by indenting each line with a specified number of tabs.
50
+
51
+ Args:
52
+ user (str): The name of the user sending the message.
53
+ message (str): The message content that may include multiple lines.
54
+ num_tabs (int): The number of tabs to use for indenting each line. Default is 1 tab.
55
+
56
+ Returns:
57
+ str: A formatted string with user and indented message lines.
58
+
59
+ Example:
60
+ >>> format_message("Alice", "Hello\nWorld", 2)
61
+ Alice:
62
+ \t\tHello
63
+ \t\tWorld
64
+ """
65
+ indentation = "\t" * num_tabs
66
+ indented_message = message.replace("\n", "\n" + indentation)
67
+ formatted_message = f"{user}:\n{indentation}{indented_message}"
68
+ return formatted_message
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: unique_toolkit
3
- Version: 0.5.37
3
+ Version: 0.5.38
4
4
  Summary:
5
5
  License: Proprietary
6
6
  Author: Martin Fadler
@@ -100,6 +100,9 @@ All notable changes to this project will be documented in this file.
100
100
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
101
101
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
102
102
 
103
+ ## [0.5.38] - 2024-11-26
104
+ - Added string representation to `LanguageModelMessage` and `LanguageModelMessages` class
105
+
103
106
  ## [0.5.37] - 2024-11-26
104
107
  - `content` parameter in `ChatService.modify_assistant_message` and `ChatService.modify_assistant_message_async` is now optional
105
108
  - Added optional parameter `original_content` to `ChatService.modify_assistant_message` and `ChatService.modify_assistant_message_async`
@@ -37,10 +37,10 @@ unique_toolkit/evaluators/output_parser.py,sha256=eI72qkzK1dZyUvnfP2SOAQCGBj_-Pw
37
37
  unique_toolkit/evaluators/schemas.py,sha256=Jaue6Uhx75X1CyHKWj8sT3RE1JZXTqoLtfLt2xQNCX8,2507
38
38
  unique_toolkit/language_model/__init__.py,sha256=YuhyczGPj6w9xX-sOVUhmozvzIFxcckHFEkeMBecr5s,1784
39
39
  unique_toolkit/language_model/infos.py,sha256=kQK6F3r8xTN7oT6b39J7rxW-Y4iPXjx_Fr9bCOVQdm0,12509
40
- unique_toolkit/language_model/schemas.py,sha256=0pMLM1cCplw1OlM-eLqldZtYMObGr7tjHKXSHQP7hwE,6216
40
+ unique_toolkit/language_model/schemas.py,sha256=wg_ly66UvLOVNdrq8xr-0uN0HPY41UIk5mVPxdG-VGs,6687
41
41
  unique_toolkit/language_model/service.py,sha256=s5X6EStyYumiYqlD9gkW4GANif18d9QZOMysmUSfv8M,13433
42
- unique_toolkit/language_model/utils.py,sha256=WBPj1XKkDgxy_-T8HCZvsfkkSzj_1w4UZzNmyvdbBLY,1081
43
- unique_toolkit-0.5.37.dist-info/LICENSE,sha256=GlN8wHNdh53xwOPg44URnwag6TEolCjoq3YD_KrWgss,193
44
- unique_toolkit-0.5.37.dist-info/METADATA,sha256=3-Ejv450nzyLOaJQN28zS0o6TefCijU7F2lCAmxYKik,14064
45
- unique_toolkit-0.5.37.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
46
- unique_toolkit-0.5.37.dist-info/RECORD,,
42
+ unique_toolkit/language_model/utils.py,sha256=bPQ4l6_YO71w-zaIPanUUmtbXC1_hCvLK0tAFc3VCRc,1902
43
+ unique_toolkit-0.5.38.dist-info/LICENSE,sha256=GlN8wHNdh53xwOPg44URnwag6TEolCjoq3YD_KrWgss,193
44
+ unique_toolkit-0.5.38.dist-info/METADATA,sha256=gjQLXWLmCmcvUCIEAF6k2_LKj8muzzR6r2m9BvOQxqQ,14180
45
+ unique_toolkit-0.5.38.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
46
+ unique_toolkit-0.5.38.dist-info/RECORD,,