From 236020b3b9b7ce66e00be4ce545c1f3150e8f6fc Mon Sep 17 00:00:00 2001 From: Kenneth Reitz Date: Wed, 6 Nov 2024 11:32:36 -0500 Subject: [PATCH] Refactor EnhancedContextPlugin to handle command line arguments for LLM provider selection --- examples/enhanced_context.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/examples/enhanced_context.py b/examples/enhanced_context.py index 1eccb92..a1b00b6 100644 --- a/examples/enhanced_context.py +++ b/examples/enhanced_context.py @@ -95,6 +95,10 @@ class EnhancedContextPlugin(sm.BasePlugin): "You are a historian who relates everything to the past", ] + # Add these lines to store the conversation's model and provider + self.llm_model = None + self.llm_provider = None + @contextmanager def get_connection(self): """Context manager for database connections""" @@ -512,6 +516,10 @@ class EnhancedContextPlugin(sm.BasePlugin): return "\n".join(context_parts) def pre_send_hook(self, conversation: sm.Conversation): + # Add these lines at the start of pre_send_hook + self.llm_model = conversation.llm_model + self.llm_provider = conversation.llm_provider + last_message = conversation.get_last_message(role="user") if not last_message: return @@ -567,7 +575,7 @@ class EnhancedContextPlugin(sm.BasePlugin): ) temp_conv = sm.create_conversation( - llm_model=LLM_MODEL, llm_provider=LLM_PROVIDER + llm_model=self.llm_model, llm_provider=self.llm_provider ) temp_conv.add_message(role="user", text=prompt) response = temp_conv.send()