Skip to content

Commit 2f6bb83

Browse files
manage override preset on override_llm invocation
1 parent f12bf50 commit 2f6bb83

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

lwe/backends/api/backend.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ def __init__(self, config=None):
3333
self.message = MessageManager(self.config)
3434
self.current_user = None
3535
self.override_provider = None
36+
self.override_preset = None
3637
self.override_llm = None
3738
self.plugin_manager = PluginManager(self.config, self, additional_plugins=ADDITIONAL_PLUGINS)
3839
self.provider_manager = ProviderManager(self.config, self.plugin_manager)
@@ -135,17 +136,19 @@ def set_override_llm(self, preset_name=None):
135136
customizations = self.expand_functions(customizations)
136137
success, provider, user_message = self.provider_manager.load_provider(metadata['provider'])
137138
if success:
138-
self.override_provider = provider
139139
if self.stream and self.should_stream():
140140
self.log.debug("Adding streaming-specific customizations to LLM request")
141141
customizations.update(self.streaming_args(interrupt_handler=True))
142142
self.override_llm = provider.make_llm(customizations, use_defaults=True)
143+
self.override_provider = provider
144+
self.override_preset = preset
143145
message = f"Set override LLM based on preset {preset_name}"
144146
self.log.debug(message)
145147
return True, self.override_llm, message
146148
return False, None, user_message
147149
else:
148150
self.log.debug("Unsetting override LLM")
151+
self.override_preset = None
149152
self.override_provider = None
150153
self.override_llm = None
151154
message = "Unset override LLM"
@@ -329,8 +332,9 @@ def extract_system_message_from_overrides(self, request_overrides):
329332
return system_message, request_overrides
330333

331334
def should_return_on_function_call(self):
332-
if self.active_preset:
333-
metadata, _customizations = self.active_preset
335+
preset = self.override_preset or self.active_preset
336+
if preset:
337+
metadata, _customizations = preset
334338
if 'return_on_function_call' in metadata and metadata['return_on_function_call']:
335339
return True
336340
return False
@@ -339,8 +343,9 @@ def is_function_response_message(self, message):
339343
return message['message_type'] == 'function_response'
340344

341345
def check_return_on_function_response(self, new_messages):
342-
if self.active_preset:
343-
metadata, _customizations = self.active_preset
346+
preset = self.override_preset or self.active_preset
347+
if preset:
348+
metadata, _customizations = preset
344349
if 'return_on_function_response' in metadata and metadata['return_on_function_response']:
345350
# NOTE: In order to allow for multiple function calling and
346351
# returning on the LAST function response, we need to allow

0 commit comments

Comments
 (0)