30
30
from neo4j_graphrag .tool import Tool
31
31
32
32
from .rate_limit import RateLimitHandler
33
- from .utils import legacy_inputs_to_message_history
33
+ from .utils import legacy_inputs_to_messages
34
34
35
35
36
36
class LLMInterface (ABC ):
@@ -65,10 +65,8 @@ def invoke(
65
65
message_history : Optional [Union [List [LLMMessage ], MessageHistory ]] = None ,
66
66
system_instruction : Optional [str ] = None ,
67
67
) -> LLMResponse :
68
- message_history = legacy_inputs_to_message_history (
69
- input , message_history , system_instruction
70
- )
71
- return self ._invoke (message_history .messages )
68
+ messages = legacy_inputs_to_messages (input , message_history , system_instruction )
69
+ return self ._invoke (messages )
72
70
73
71
@abstractmethod
74
72
def _invoke (
@@ -94,10 +92,8 @@ async def ainvoke(
94
92
message_history : Optional [Union [List [LLMMessage ], MessageHistory ]] = None ,
95
93
system_instruction : Optional [str ] = None ,
96
94
) -> LLMResponse :
97
- message_history = legacy_inputs_to_message_history (
98
- input , message_history , system_instruction
99
- )
100
- return await self ._ainvoke (message_history .messages )
95
+ messages = legacy_inputs_to_messages (input , message_history , system_instruction )
96
+ return await self ._ainvoke (messages )
101
97
102
98
@abstractmethod
103
99
async def _ainvoke (
@@ -142,10 +138,8 @@ def invoke_with_tools(
142
138
LLMGenerationError: If anything goes wrong.
143
139
NotImplementedError: If the LLM provider does not support tool calling.
144
140
"""
145
- history = legacy_inputs_to_message_history (
146
- input , message_history , system_instruction
147
- )
148
- return self ._invoke_with_tools (history .messages , tools )
141
+ messages = legacy_inputs_to_messages (input , message_history , system_instruction )
142
+ return self ._invoke_with_tools (messages , tools )
149
143
150
144
def _invoke_with_tools (
151
145
self , inputs : list [LLMMessage ], tools : Sequence [Tool ]
@@ -177,10 +171,8 @@ async def ainvoke_with_tools(
177
171
LLMGenerationError: If anything goes wrong.
178
172
NotImplementedError: If the LLM provider does not support tool calling.
179
173
"""
180
- history = legacy_inputs_to_message_history (
181
- input , message_history , system_instruction
182
- )
183
- return await self ._ainvoke_with_tools (history .messages , tools )
174
+ messages = legacy_inputs_to_messages (input , message_history , system_instruction )
175
+ return await self ._ainvoke_with_tools (messages , tools )
184
176
185
177
async def _ainvoke_with_tools (
186
178
self , inputs : list [LLMMessage ], tools : Sequence [Tool ]
0 commit comments