3
3
# SPDX-License-Identifier: Apache-2.0
4
4
5
5
import json
6
- import warnings
7
6
from dataclasses import asdict , dataclass , field
8
7
from enum import Enum
9
8
from typing import Any , Dict , List , Optional , Sequence , Union
@@ -28,9 +27,6 @@ class ChatRole(str, Enum):
28
27
#: The tool role. A message from a tool contains the result of a Tool invocation.
29
28
TOOL = "tool"
30
29
31
- #: The function role. Deprecated in favor of `TOOL`.
32
- FUNCTION = "function"
33
-
34
30
@staticmethod
35
31
def from_str (string : str ) -> "ChatRole" :
36
32
"""
@@ -128,11 +124,6 @@ def __new__(cls, *args, **kwargs):
128
124
129
125
return super (ChatMessage , cls ).__new__ (cls )
130
126
131
- def __post_init__ (self ):
132
- if self ._role == ChatRole .FUNCTION :
133
- msg = "The `FUNCTION` role has been deprecated in favor of `TOOL` and will be removed in 2.10.0. "
134
- warnings .warn (msg , DeprecationWarning )
135
-
136
127
def __getattribute__ (self , name ):
137
128
"""
138
129
This method is reimplemented to make the `content` attribute removal more visible.
@@ -299,26 +290,6 @@ def from_tool(
299
290
_meta = meta or {},
300
291
)
301
292
302
- @classmethod
303
- def from_function (cls , content : str , name : str ) -> "ChatMessage" :
304
- """
305
- Create a message from a function call. Deprecated in favor of `from_tool`.
306
-
307
- :param content: The text content of the message.
308
- :param name: The name of the function being called.
309
- :returns: A new ChatMessage instance.
310
- """
311
- msg = (
312
- "The `from_function` method is deprecated and will be removed in version 2.10.0. "
313
- "Its behavior has changed: it now attempts to convert legacy function messages to tool messages. "
314
- "This conversion is not guaranteed to succeed in all scenarios. "
315
- "Please migrate to `ChatMessage.from_tool` and carefully verify the results if you "
316
- "continue to use this method."
317
- )
318
- warnings .warn (msg )
319
-
320
- return cls .from_tool (content , ToolCall (id = None , tool_name = name , arguments = {}), error = False )
321
-
322
293
def to_dict (self ) -> Dict [str , Any ]:
323
294
"""
324
295
Converts ChatMessage into a dictionary.
0 commit comments