unique_toolkit 0.8.7__py3-none-any.whl → 0.8.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.
@@ -2,6 +2,16 @@ from datetime import datetime
2
2
  from enum import StrEnum
3
3
 
4
4
  from humps import camelize
5
+ from openai.types.chat import (
6
+ ChatCompletionAssistantMessageParam,
7
+ ChatCompletionUserMessageParam,
8
+ )
9
+ from openai.types.chat.chat_completion_message_function_tool_call_param import (
10
+ ChatCompletionMessageFunctionToolCallParam,
11
+ )
12
+ from openai.types.chat.chat_completion_message_function_tool_call_param import (
13
+ Function as OpenAIFunction,
14
+ )
5
15
  from pydantic import (
6
16
  BaseModel,
7
17
  ConfigDict,
@@ -14,14 +24,15 @@ from unique_toolkit.content.schemas import ContentReference
14
24
 
15
25
  # set config to convert camelCase to snake_case
16
26
  model_config = ConfigDict(
17
- alias_generator=camelize, populate_by_name=True, arbitrary_types_allowed=True
27
+ alias_generator=camelize,
28
+ populate_by_name=True,
18
29
  )
19
30
 
20
31
 
21
32
  class ChatMessageRole(StrEnum):
22
33
  USER = "user"
23
34
  ASSISTANT = "assistant"
24
- TOOL = "tool"
35
+ TOOL = "tool" # TODO: Unused according @unique-fabian. To be removed in separate PR
25
36
 
26
37
 
27
38
  class Function(BaseModel):
@@ -30,6 +41,12 @@ class Function(BaseModel):
30
41
  name: str
31
42
  arguments: str
32
43
 
44
+ def to_openai(self) -> OpenAIFunction:
45
+ return OpenAIFunction(
46
+ arguments=self.arguments,
47
+ name=self.name,
48
+ )
49
+
33
50
 
34
51
  class ToolCall(BaseModel):
35
52
  model_config = model_config
@@ -38,8 +55,16 @@ class ToolCall(BaseModel):
38
55
  type: str
39
56
  function: Function
40
57
 
58
+ def to_openai_param(self) -> ChatCompletionMessageFunctionToolCallParam:
59
+ return ChatCompletionMessageFunctionToolCallParam(
60
+ id=self.id,
61
+ function=self.function.to_openai(),
62
+ type="function",
63
+ )
64
+
41
65
 
42
66
  class ChatMessage(BaseModel):
67
+ # TODO: The below seems not to be True anymore @irina-unique. To be checked in separate PR
43
68
  # This model should strictly meets https://github.com/Unique-AG/monorepo/blob/master/node/apps/node-chat/src/public-api/2023-12-06/dtos/message/public-message.dto.ts
44
69
  model_config = model_config
45
70
 
@@ -71,6 +96,27 @@ class ChatMessage(BaseModel):
71
96
  raise ValueError("tool_call_ids is required when role is 'tool'")
72
97
  return self
73
98
 
99
+ def to_openai_param(self):
100
+ match self.role:
101
+ case ChatMessageRole.USER:
102
+ return ChatCompletionUserMessageParam(
103
+ role="user",
104
+ content=self.content or "",
105
+ )
106
+
107
+ case ChatMessageRole.ASSISTANT:
108
+ return ChatCompletionAssistantMessageParam(
109
+ role="assistant",
110
+ audio=None,
111
+ content=self.content or "",
112
+ function_call=None,
113
+ refusal=None,
114
+ tool_calls=[t.to_openai_param() for t in self.tool_calls or []],
115
+ )
116
+
117
+ case ChatMessageRole.TOOL:
118
+ raise NotImplementedError
119
+
74
120
 
75
121
  class ChatMessageAssessmentStatus(StrEnum):
76
122
  PENDING = "PENDING"
@@ -329,9 +329,9 @@ class ChatService:
329
329
 
330
330
  Args:
331
331
  content (str): The new content for the message.
332
- references (list[ContentReference]): list of ContentReference objects. Defaults to [].
333
- debug_info (dict[str, Any]]]): Debug information. Defaults to {}.
334
- message_id (str, optional): The message ID. Defaults to None, then the ChatState user message id is used.
332
+ references (list[ContentReference]): list of ContentReference objects.
333
+ debug_info (dict[str, Any]]]): Debug information.
334
+ message_id (str, optional): The message ID, if not specified the last user message is edited.
335
335
  set_completed_at (Optional[bool]): Whether to set the completedAt field with the current date time. Defaults to False.
336
336
 
337
337
  Returns:
@@ -5,6 +5,11 @@ from typing import Any, Self
5
5
  from uuid import uuid4
6
6
 
7
7
  from humps import camelize
8
+ from openai.types.chat import ChatCompletionAssistantMessageParam
9
+ from openai.types.chat.chat_completion_message_function_tool_call_param import (
10
+ ChatCompletionMessageFunctionToolCallParam,
11
+ Function,
12
+ )
8
13
  from openai.types.chat.chat_completion_tool_param import ChatCompletionToolParam
9
14
  from openai.types.shared_params.function_definition import FunctionDefinition
10
15
  from pydantic import (
@@ -88,9 +93,7 @@ class LanguageModelFunction(BaseModel):
88
93
  return seralization
89
94
 
90
95
  def __eq__(self, other: Self) -> bool:
91
- """
92
- Compare two tool calls based on name and arguments.
93
- """
96
+ """Compare two tool calls based on name and arguments."""
94
97
  if not isinstance(other, LanguageModelFunction):
95
98
  return False
96
99
 
@@ -105,6 +108,19 @@ class LanguageModelFunction(BaseModel):
105
108
 
106
109
  return True
107
110
 
111
+ def to_openai_param(self) -> ChatCompletionMessageFunctionToolCallParam:
112
+ arguments = ""
113
+ if isinstance(self.arguments, dict):
114
+ arguments = json.dumps(self.arguments)
115
+ elif isinstance(self.arguments, str):
116
+ arguments = self.arguments
117
+
118
+ return ChatCompletionMessageFunctionToolCallParam(
119
+ type="function",
120
+ id=self.id or "unknown_id",
121
+ function=Function(name=self.name, arguments=arguments),
122
+ )
123
+
108
124
 
109
125
  # This is tailored to the unique backend
110
126
  class LanguageModelStreamResponse(BaseModel):
@@ -113,6 +129,16 @@ class LanguageModelStreamResponse(BaseModel):
113
129
  message: LanguageModelStreamResponseMessage
114
130
  tool_calls: list[LanguageModelFunction] | None = None
115
131
 
132
+ def to_openai_param(self) -> ChatCompletionAssistantMessageParam:
133
+ return ChatCompletionAssistantMessageParam(
134
+ role="assistant",
135
+ audio=None,
136
+ content=self.message.text,
137
+ function_call=None,
138
+ refusal=None,
139
+ tool_calls=[t.to_openai_param() for t in self.tool_calls or []],
140
+ )
141
+
116
142
 
117
143
  class LanguageModelFunctionCall(BaseModel):
118
144
  model_config = model_config
@@ -126,7 +152,7 @@ class LanguageModelFunctionCall(BaseModel):
126
152
  @staticmethod
127
153
  def create_assistant_message_from_tool_calls(
128
154
  tool_calls: list[LanguageModelFunction],
129
- ):
155
+ ) -> "LanguageModelAssistantMessage":
130
156
  assistant_message = LanguageModelAssistantMessage(
131
157
  content="",
132
158
  tool_calls=[
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: unique_toolkit
3
- Version: 0.8.7
3
+ Version: 0.8.8
4
4
  Summary:
5
5
  License: Proprietary
6
6
  Author: Martin Fadler
@@ -114,6 +114,9 @@ All notable changes to this project will be documented in this file.
114
114
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
115
115
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
116
116
 
117
+ ## [0.8.8] - 2025-08-11
118
+ - Make chat service openai stream response openai compatible
119
+ - Make `ChatMessage` openai compatible
117
120
 
118
121
  ## [0.8.7] - 2025-08-11
119
122
  - Make chat service openai compatible
@@ -16,8 +16,8 @@ unique_toolkit/app/verification.py,sha256=GxFFwcJMy25fCA_Xe89wKW7bgqOu8PAs5y8QpH
16
16
  unique_toolkit/chat/__init__.py,sha256=LRs2G-JTVuci4lbtHTkVUiNcZcSR6uqqfnAyo7af6nY,619
17
17
  unique_toolkit/chat/constants.py,sha256=05kq6zjqUVB2d6_P7s-90nbljpB3ryxwCI-CAz0r2O4,83
18
18
  unique_toolkit/chat/functions.py,sha256=I6r81PpWNu-j9DvHxNFKN3V6T5E5q42FhW9kF8pJJSY,29950
19
- unique_toolkit/chat/schemas.py,sha256=abPPeDtUIeEyKDnLhIqgIyqTsFANxh3j44EYrITBlHw,2786
20
- unique_toolkit/chat/service.py,sha256=dB36KCfeowQ9EgiRscK2UK7WOnGhklVNawC_t8MTaZA,37803
19
+ unique_toolkit/chat/schemas.py,sha256=0tWzu5_F_-PRK5A6MUsdpNqCfNAIMEAuQ26wIgP2pYs,4415
20
+ unique_toolkit/chat/service.py,sha256=LNZm9JS17M-MWcVRR3o2HpQFgDkIkxnGMUCoYmz9vzA,37759
21
21
  unique_toolkit/chat/state.py,sha256=Cjgwv_2vhDFbV69xxsn7SefhaoIAEqLx3ferdVFCnOg,1445
22
22
  unique_toolkit/chat/utils.py,sha256=ihm-wQykBWhB4liR3LnwPVPt_qGW6ETq21Mw4HY0THE,854
23
23
  unique_toolkit/content/__init__.py,sha256=EdJg_A_7loEtCQf4cah3QARQreJx6pdz89Rm96YbMVg,940
@@ -58,7 +58,7 @@ unique_toolkit/language_model/functions.py,sha256=qi4KGa4hLUXy0KwkkGmtGBM1IuYfJq
58
58
  unique_toolkit/language_model/infos.py,sha256=mnUnbjDQNOIuPS2VE1SsgyKOxdRulo-9Z5k7_S1Q8Cw,37631
59
59
  unique_toolkit/language_model/prompt.py,sha256=JSawaLjQg3VR-E2fK8engFyJnNdk21zaO8pPIodzN4Q,3991
60
60
  unique_toolkit/language_model/reference.py,sha256=nkX2VFz-IrUz8yqyc3G5jUMNwrNpxITBrMEKkbqqYoI,8583
61
- unique_toolkit/language_model/schemas.py,sha256=q7jZNijgy6xu3tHrr2Eqs1jglI_YkqH1RrBt5bCXn-8,15181
61
+ unique_toolkit/language_model/schemas.py,sha256=p95cAwrYmEBupI8f7JZY17aJTKEHvtqF88hMIzS5r_k,16259
62
62
  unique_toolkit/language_model/service.py,sha256=zlvC_t9T1wixwcGDPRxl6yYniaKl2725NxWrbW51jUs,11290
63
63
  unique_toolkit/language_model/utils.py,sha256=bPQ4l6_YO71w-zaIPanUUmtbXC1_hCvLK0tAFc3VCRc,1902
64
64
  unique_toolkit/protocols/support.py,sha256=V15WEIFKVMyF1QCnR8vIi4GrJy4dfTCB6d6JlqPZ58o,2341
@@ -82,7 +82,7 @@ unique_toolkit/tools/utils/execution/execution.py,sha256=vjG2Y6awsGNtlvyQAGCTthQ
82
82
  unique_toolkit/tools/utils/source_handling/schema.py,sha256=pvNhtL2daDLpCVIQpfdn6R35GvKmITVLXjZNLAwpgUE,871
83
83
  unique_toolkit/tools/utils/source_handling/source_formatting.py,sha256=C7uayNbdkNVJdEARA5CENnHtNY1SU6etlaqbgHNyxaQ,9152
84
84
  unique_toolkit/tools/utils/source_handling/tests/test_source_formatting.py,sha256=zu3AJnYH9CMqZPrxKEH3IgI-fM3nlvIBuspJG6W6B18,6978
85
- unique_toolkit-0.8.7.dist-info/LICENSE,sha256=GlN8wHNdh53xwOPg44URnwag6TEolCjoq3YD_KrWgss,193
86
- unique_toolkit-0.8.7.dist-info/METADATA,sha256=ybNaWfFpNt6HHOd3aMPvcvUAwust7t6VV23dfZlOk4Q,26524
87
- unique_toolkit-0.8.7.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
88
- unique_toolkit-0.8.7.dist-info/RECORD,,
85
+ unique_toolkit-0.8.8.dist-info/LICENSE,sha256=GlN8wHNdh53xwOPg44URnwag6TEolCjoq3YD_KrWgss,193
86
+ unique_toolkit-0.8.8.dist-info/METADATA,sha256=AUly1ya9VxSfPCq8ivY1kAq4MrClSRQ-fm8_9BZr0oI,26649
87
+ unique_toolkit-0.8.8.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
88
+ unique_toolkit-0.8.8.dist-info/RECORD,,