diff --git a/simplemind/models.py b/simplemind/models.py index 1f92757..4a85c99 100644 --- a/simplemind/models.py +++ b/simplemind/models.py @@ -41,6 +41,7 @@ class Conversation(SMBaseModel): messages: List[Message] = [] llm_model: Optional[str] = None llm_provider: Optional[str] = None + plugins: List[Any] = [] def __str__(self): return f"" @@ -53,8 +54,15 @@ class Conversation(SMBaseModel): self, llm_model: Optional[str] = None, llm_provider: Optional[str] = None ) -> Message: """Send the conversation to the LLM.""" + for plugin in self.plugins: + plugin.send_hook(self) + provider = find_provider(llm_provider or self.llm_provider) response = provider.send_conversation(self) self.add_message(role="assistant", text=response.text, meta=response.meta) return response + + def add_plugin(self, plugin: Any): + """Add a plugin to the conversation.""" + self.plugins.append(plugin) diff --git a/t.py b/t.py index fac4751..503cfe0 100644 --- a/t.py +++ b/t.py @@ -1,11 +1,28 @@ import simplemind as sm +class SimpleMemoryPlugin: + def __init__(self): + self.memories = [ + "the earth has fictionally beeen destroyed.", + "the moon is made of cheese.", + ] + + def yield_memories(self): + return (m for m in self.memories) + + def send_hook(self, conversation: sm.Conversation): + for m in self.yield_memories(): + conversation.add_message(role="system", text=m) + + conversation = sm.create_conversation(llm_model="grok-beta", llm_provider="xai") +conversation.add_plugin(SimpleMemoryPlugin()) + conversation.add_message( role="user", - text="Write a poem about working at dominoes", + text="Write a poem about the moon", ) r = conversation.send()