unique_toolkit 0.5.28__py3-none-any.whl → 0.5.31__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.
- unique_toolkit/language_model/schemas.py +43 -7
- unique_toolkit/language_model/service.py +5 -5
- {unique_toolkit-0.5.28.dist-info → unique_toolkit-0.5.31.dist-info}/METADATA +11 -2
- {unique_toolkit-0.5.28.dist-info → unique_toolkit-0.5.31.dist-info}/RECORD +6 -6
- {unique_toolkit-0.5.28.dist-info → unique_toolkit-0.5.31.dist-info}/LICENSE +0 -0
- {unique_toolkit-0.5.28.dist-info → unique_toolkit-0.5.31.dist-info}/WHEEL +0 -0
@@ -9,6 +9,7 @@ from pydantic import (
|
|
9
9
|
Field,
|
10
10
|
RootModel,
|
11
11
|
field_validator,
|
12
|
+
model_serializer,
|
12
13
|
model_validator,
|
13
14
|
)
|
14
15
|
|
@@ -32,27 +33,54 @@ class LanguageModelFunction(BaseModel):
|
|
32
33
|
|
33
34
|
id: Optional[str] = None
|
34
35
|
name: str
|
35
|
-
arguments: Optional[dict[str,
|
36
|
+
arguments: Optional[dict[str, Any] | str] = None # type: ignore
|
36
37
|
|
37
38
|
@field_validator("arguments", mode="before")
|
38
39
|
def set_arguments(cls, value):
|
39
|
-
|
40
|
+
if isinstance(value, str):
|
41
|
+
return json.loads(value)
|
42
|
+
return value
|
43
|
+
|
44
|
+
@model_serializer()
|
45
|
+
def serialize_model(self):
|
46
|
+
seralization = {}
|
47
|
+
if self.id:
|
48
|
+
seralization["id"] = self.id
|
49
|
+
seralization["name"] = self.name
|
50
|
+
if self.arguments:
|
51
|
+
seralization["arguments"] = json.dumps(self.arguments)
|
52
|
+
return seralization
|
40
53
|
|
41
54
|
|
42
55
|
class LanguageModelFunctionCall(BaseModel):
|
43
56
|
model_config = model_config
|
44
57
|
|
45
|
-
id: str
|
58
|
+
id: Optional[str] = None
|
46
59
|
type: Optional[str] = None
|
47
60
|
function: LanguageModelFunction
|
48
61
|
|
62
|
+
@staticmethod
|
63
|
+
def create_assistant_message_from_tool_calls(
|
64
|
+
tool_calls: list[LanguageModelFunction],
|
65
|
+
):
|
66
|
+
assistant_message = LanguageModelAssistantMessage(
|
67
|
+
content="",
|
68
|
+
tool_calls=[
|
69
|
+
LanguageModelFunctionCall(
|
70
|
+
id=tool_call.id,
|
71
|
+
type="function",
|
72
|
+
function=tool_call,
|
73
|
+
)
|
74
|
+
for tool_call in tool_calls
|
75
|
+
],
|
76
|
+
)
|
77
|
+
return assistant_message
|
78
|
+
|
49
79
|
|
50
80
|
class LanguageModelMessage(BaseModel):
|
51
81
|
model_config = model_config
|
52
|
-
|
53
82
|
role: LanguageModelMessageRole
|
54
83
|
content: Optional[str | list[dict]] = None
|
55
|
-
name: Optional[str] = None
|
56
84
|
tool_calls: Optional[list[LanguageModelFunctionCall]] = None
|
57
85
|
|
58
86
|
|
@@ -82,6 +110,8 @@ class LanguageModelAssistantMessage(LanguageModelMessage):
|
|
82
110
|
|
83
111
|
class LanguageModelToolMessage(LanguageModelMessage):
|
84
112
|
role: LanguageModelMessageRole = LanguageModelMessageRole.TOOL
|
113
|
+
name: str
|
114
|
+
tool_call_id: str
|
85
115
|
|
86
116
|
@field_validator("role", mode="before")
|
87
117
|
def set_role(cls, value):
|
@@ -89,7 +119,13 @@ class LanguageModelToolMessage(LanguageModelMessage):
|
|
89
119
|
|
90
120
|
|
91
121
|
class LanguageModelMessages(RootModel):
|
92
|
-
root: list[
|
122
|
+
root: list[
|
123
|
+
LanguageModelMessage
|
124
|
+
| LanguageModelToolMessage
|
125
|
+
| LanguageModelAssistantMessage
|
126
|
+
| LanguageModelSystemMessage
|
127
|
+
| LanguageModelUserMessage
|
128
|
+
]
|
93
129
|
|
94
130
|
def __iter__(self):
|
95
131
|
return iter(self.root)
|
@@ -182,7 +218,7 @@ class LanguageModelToolParameters(BaseModel):
|
|
182
218
|
class LanguageModelTool(BaseModel):
|
183
219
|
name: str = Field(
|
184
220
|
...,
|
185
|
-
pattern=r"^[a-zA-
|
221
|
+
pattern=r"^[a-zA-Z1-9_-]+$",
|
186
222
|
description="Name must adhere to the pattern ^[a-zA-Z_-]+$",
|
187
223
|
)
|
188
224
|
description: str
|
@@ -52,6 +52,7 @@ class LanguageModelService(BaseService):
|
|
52
52
|
LanguageModelResponse: The LanguageModelResponse object.
|
53
53
|
"""
|
54
54
|
options = self._add_tools_to_options({}, tools)
|
55
|
+
options["temperature"] = temperature
|
55
56
|
messages = messages.model_dump(exclude_none=True)
|
56
57
|
model = (
|
57
58
|
model_name.name if isinstance(model_name, LanguageModelName) else model_name
|
@@ -67,7 +68,6 @@ class LanguageModelService(BaseService):
|
|
67
68
|
messages,
|
68
69
|
),
|
69
70
|
timeout=timeout,
|
70
|
-
temperature=temperature,
|
71
71
|
options=options, # type: ignore
|
72
72
|
)
|
73
73
|
return LanguageModelResponse(**response)
|
@@ -109,6 +109,7 @@ class LanguageModelService(BaseService):
|
|
109
109
|
Exception: If an error occurs during the request, an exception is raised and logged.
|
110
110
|
"""
|
111
111
|
options = cls._add_tools_to_options({}, tools)
|
112
|
+
options["temperature"] = temperature
|
112
113
|
messages = messages.model_dump(exclude_none=True, exclude={"tool_calls"})
|
113
114
|
model = (
|
114
115
|
model_name.name if isinstance(model_name, LanguageModelName) else model_name
|
@@ -122,12 +123,11 @@ class LanguageModelService(BaseService):
|
|
122
123
|
messages,
|
123
124
|
),
|
124
125
|
timeout=timeout,
|
125
|
-
temperature=temperature,
|
126
126
|
options=options, # type: ignore
|
127
127
|
)
|
128
128
|
return LanguageModelResponse(**response)
|
129
129
|
except Exception as e:
|
130
|
-
logger.error(f"Error completing: {e}")
|
130
|
+
logger.error(f"Error completing: {e}") # type: ignore
|
131
131
|
raise e
|
132
132
|
|
133
133
|
async def complete_async(
|
@@ -198,7 +198,7 @@ class LanguageModelService(BaseService):
|
|
198
198
|
options = self._add_tools_to_options({}, tools)
|
199
199
|
options["temperature"] = temperature
|
200
200
|
search_context = self._to_search_context(content_chunks)
|
201
|
-
messages = messages.model_dump(exclude_none=True)
|
201
|
+
messages = messages.model_dump(exclude_none=True, by_alias=True)
|
202
202
|
model = (
|
203
203
|
model_name.name if isinstance(model_name, LanguageModelName) else model_name
|
204
204
|
)
|
@@ -259,7 +259,7 @@ class LanguageModelService(BaseService):
|
|
259
259
|
options = self._add_tools_to_options({}, tools)
|
260
260
|
options["temperature"] = temperature
|
261
261
|
search_context = self._to_search_context(content_chunks)
|
262
|
-
messages = messages.model_dump(exclude_none=True,
|
262
|
+
messages = messages.model_dump(exclude_none=True, by_alias=True)
|
263
263
|
model = (
|
264
264
|
model_name.name if isinstance(model_name, LanguageModelName) else model_name
|
265
265
|
)
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: unique_toolkit
|
3
|
-
Version: 0.5.
|
3
|
+
Version: 0.5.31
|
4
4
|
Summary:
|
5
5
|
License: Proprietary
|
6
6
|
Author: Martin Fadler
|
@@ -100,8 +100,17 @@ 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.31] - 2024-10-29
|
104
|
+
- Adding support for function calling. Assistant message for tool calls can be directly created with `LanguageModelFunctionCall.create_assistant_message_from_tool_calls`. Better separation of schemas for different types of `LanguageModelMessages`.
|
105
|
+
|
106
|
+
## [0.5.30] - 2024-10-28
|
107
|
+
- Correctly use `temperature` parameter in `LanguageModelService.complete` and `LanguageModelService.complete_async` methods
|
108
|
+
|
109
|
+
## [0.5.29] - 2024-10-28
|
110
|
+
- Allow numbers in `LanguageModelTool` name
|
111
|
+
|
103
112
|
## [0.5.28] - 2024-10-23
|
104
|
-
- Correctly use `temperature` parameter in `LanguageModelService.
|
113
|
+
- Correctly use `temperature` parameter in `LanguageModelService.stream_complete` and `LanguageModelService.stream_complete_async` methods
|
105
114
|
|
106
115
|
## [0.5.27] - 2024-10-22
|
107
116
|
- Add encoder_name to to language model info
|
@@ -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=Oxkr9_6s8gFubxjox-iCm1GSs1RCAQQ5t8oh20izlC0,12002
|
40
|
-
unique_toolkit/language_model/schemas.py,sha256=
|
41
|
-
unique_toolkit/language_model/service.py,sha256=
|
40
|
+
unique_toolkit/language_model/schemas.py,sha256=CLMnhUQeBlsm-XX7Sy54_Gxeqfa7M0z-P7xMwOzfqTg,6089
|
41
|
+
unique_toolkit/language_model/service.py,sha256=s5X6EStyYumiYqlD9gkW4GANif18d9QZOMysmUSfv8M,13433
|
42
42
|
unique_toolkit/language_model/utils.py,sha256=WBPj1XKkDgxy_-T8HCZvsfkkSzj_1w4UZzNmyvdbBLY,1081
|
43
|
-
unique_toolkit-0.5.
|
44
|
-
unique_toolkit-0.5.
|
45
|
-
unique_toolkit-0.5.
|
46
|
-
unique_toolkit-0.5.
|
43
|
+
unique_toolkit-0.5.31.dist-info/LICENSE,sha256=GlN8wHNdh53xwOPg44URnwag6TEolCjoq3YD_KrWgss,193
|
44
|
+
unique_toolkit-0.5.31.dist-info/METADATA,sha256=vPlMZjvxDXjkByH7-W7H19nyGgzUA-pFOryUlGb3sPE,12944
|
45
|
+
unique_toolkit-0.5.31.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
|
46
|
+
unique_toolkit-0.5.31.dist-info/RECORD,,
|
File without changes
|
File without changes
|