Add InspirationPlugin to examples/inspiration_plugin.py and allow extra fields in BasePlugin's Config

This commit is contained in:
2024-11-06 07:54:11 -05:00
parent 1528dc2a21
commit 48e6ef2a43
2 changed files with 40 additions and 0 deletions
+37
View File
@@ -0,0 +1,37 @@
import random
from _context import simplemind as sm
class InspirationPlugin(sm.BasePlugin):
# Define inspirations as a class variable
inspirations: list[str] = [
"The only limit to our realization of tomorrow is our doubts of today.",
"Imagine beyond the edges of what you know.",
"What if the stars could speak? What stories would they tell?",
"Creativity is intelligence having fun.",
"Think not only with your mind but with your heart.",
"Let every answer be a doorway to another question.",
"The universe is in constant dialogue with those who listen.",
]
def __init__(self):
super().__init__() # Make sure to call parent class's __init__
def get_inspiration(self):
# Randomly select an inspirational quote or prompt
return random.choice(self.inspirations)
def pre_send_hook(self, conversation: sm.Conversation):
# Inject an inspirational message as a system prompt
inspiration = self.get_inspiration()
conversation.add_message(role="system", text=inspiration)
# Create a conversation and add the plugin
conversation = sm.create_conversation(llm_model="gpt-4o-mini", llm_provider="openai")
conversation.add_plugin(InspirationPlugin())
# Add a user message and send the conversation
conversation.add_message(role="user", text="Tell me something inspiring.")
response = conversation.send()
print(response)
+3
View File
@@ -28,6 +28,9 @@ class BasePlugin(SMBaseModel):
# Plugin metadata.
meta: Dict[str, Any] = {}
class Config:
extra = "allow"
def initialize_hook(self, conversation: "Conversation") -> Any:
"""Initialize a hook for the plugin."""
raise NotImplementedError