1414# limitations under the License.
1515from __future__ import annotations
1616
17- from abc import ABC , abstractmethod
17+ import warnings
1818from typing import Any , List , Optional , Sequence , Union
1919
2020from pydantic import ValidationError
3636from ..exceptions import LLMGenerationError
3737
3838
39- class LLMInterface ( ABC ) :
39+ class LLMInterface :
4040 """Interface for large language models.
4141
4242 Args:
@@ -68,6 +68,16 @@ def invoke(
6868 message_history : Optional [Union [List [LLMMessage ], MessageHistory ]] = None ,
6969 system_instruction : Optional [str ] = None ,
7070 ) -> LLMResponse :
71+ if message_history :
72+ warnings .warn (
73+ "Using 'message_history' in the llm.invoke method is deprecated. Please use invoke(list[LLMMessage]) instead." ,
74+ DeprecationWarning ,
75+ )
76+ if system_instruction :
77+ warnings .warn (
78+ "Using 'system_instruction' in the llm.invoke method is deprecated. Please use invoke(list[LLMMessage]) instead." ,
79+ DeprecationWarning ,
80+ )
7181 try :
7282 messages = legacy_inputs_to_messages (
7383 input , message_history , system_instruction
@@ -76,7 +86,6 @@ def invoke(
7686 raise LLMGenerationError ("Input validation failed" ) from e
7787 return self ._invoke (messages )
7888
79- @abstractmethod
8089 def _invoke (
8190 self ,
8291 input : list [LLMMessage ],
@@ -92,6 +101,7 @@ def _invoke(
92101 Raises:
93102 LLMGenerationError: If anything goes wrong.
94103 """
104+ raise NotImplementedError ()
95105
96106 @async_rate_limit_handler
97107 async def ainvoke (
@@ -100,10 +110,19 @@ async def ainvoke(
100110 message_history : Optional [Union [List [LLMMessage ], MessageHistory ]] = None ,
101111 system_instruction : Optional [str ] = None ,
102112 ) -> LLMResponse :
113+ if message_history :
114+ warnings .warn (
115+ "Using 'message_history' in the llm.ainvoke method is deprecated. Please use invoke(list[LLMMessage]) instead." ,
116+ DeprecationWarning ,
117+ )
118+ if system_instruction :
119+ warnings .warn (
120+ "Using 'system_instruction' in the llm.ainvoke method is deprecated. Please use invoke(list[LLMMessage]) instead." ,
121+ DeprecationWarning ,
122+ )
103123 messages = legacy_inputs_to_messages (input , message_history , system_instruction )
104124 return await self ._ainvoke (messages )
105125
106- @abstractmethod
107126 async def _ainvoke (
108127 self ,
109128 input : list [LLMMessage ],
@@ -119,6 +138,7 @@ async def _ainvoke(
119138 Raises:
120139 LLMGenerationError: If anything goes wrong.
121140 """
141+ raise NotImplementedError ()
122142
123143 @rate_limit_handler
124144 def invoke_with_tools (
0 commit comments