A reactive notebook for Python — run reproducible experiments, query with SQL, execute as a script, deploy as an app, and version with git. Stored as pure Python. All in a modern, AI-native editor.
Python artificial-intelligencedagdata-sciencedata-visualizationdataflowdeveloper-toolsmachine-learningnotebookspipelinepythonreactivesqlweb-app
example: add simplemind (#2752)
Myles Scolnick762978c71dfe
diff --git a/examples/ai/chat/simplemind_example.py b/examples/ai/chat/simplemind_example.pynew file mode 100644index 0000000000..42a529fa60--- /dev/null+++ b/examples/ai/chat/simplemind_example.py@@ -0,0 +1,112 @@+# /// script+# requires-python = ">=3.12"+# dependencies = [+# "marimo",+# "simplemind==0.1.3",+# ]+# ///++import marimo++__generated_with = "0.9.14"+app = marimo.App(width="full")++[email protected](hide_code=True)+def __(mo):+ mo.md(r"""## Using [simplemind](https://github.com/kennethreitz/simplemind) with `mo.ui.chat()`""")+ return++[email protected](hide_code=True)+def __():+ import marimo as mo+ import os+ import simplemind as sm+ return mo, os, sm++[email protected](hide_code=True)+def __(__file__, mo, os):+ has_set_env = os.environ.get("OPENAI_API_KEY") is not None+ mo.md(f"""+ Missing OpenAI API key. Re-run this notebook with the following command:++ ```bash+ export OPENAI_API_KEY='sk-'+ marimo edit {__file__}+ ```+ """).callout("warn") if not has_set_env else ""+ return (has_set_env,)+++def __(mo):+ get_logs, set_logs = mo.state([], allow_self_loops=True)+ return get_logs, set_logs+++def __(set_logs, sm):+ def add_log(value):+ return set_logs(lambda logs: logs + [value])+++ class LoggingPlugin(sm.BasePlugin):+ def pre_send_hook(self, conversation):+ add_log(+ f"Sending conversation with {len(conversation.messages)} messages"+ )++ def add_message_hook(self, conversation, message):+ add_log(f"Adding message to conversation: {message.text}")++ def cleanup_hook(self, conversation):+ add_log(+ f"Cleaning up conversation with {len(conversation.messages)} messages"+ )++ def initialize_hook(self, conversation):+ add_log("Initializing conversation")++ def post_send_hook(self, conversation, response):+ add_log(f"Received response: {response.text}")+ return LoggingPlugin, add_log+++def __(LoggingPlugin, mo, sm):+ conversation = sm.create_conversation(+ llm_model="gpt-4o", llm_provider="openai"+ )+ conversation.add_plugin(LoggingPlugin())+++ def on_message(messages):+ conversation.add_message("user", messages[-1].content)+ return conversation.send().text+++ chat = mo.ui.chat(on_message)+ return chat, conversation, on_message+++def __(chat, get_logs, mo):+ logs = list(reversed(get_logs()))++ mo.hstack(+ [chat, mo.ui.table(logs, selection=None)],+ widths="equal",+ )+ return (logs,)+++def __(chat):+ chat.value+ return+++if __name__ == "__main__":+ app.run()diff --git a/frontend/src/plugins/impl/chat/chat-ui.tsx b/frontend/src/plugins/impl/chat/chat-ui.tsxindex 3f4b12fb36..d413af708d 100644--- a/frontend/src/plugins/impl/chat/chat-ui.tsx+++ b/frontend/src/plugins/impl/chat/chat-ui.tsx@@ -206,7 +206,7 @@ export const Chatbot: React.FC<Props> = (props) => {return (<div- className="flex flex-col h-full bg-[var(--slate-1)] rounded-lg shadow border border-[var(--slate-6)] overflow-hidden"+ className="flex flex-col h-full bg-[var(--slate-1)] rounded-lg shadow border border-[var(--slate-6)] overflow-hidden relative"style={{ maxHeight: props.maxHeight }}><div className="absolute top-0 right-0 flex justify-end z-10 border border-[var(--slate-6)] bg-inherit rounded-bl-lg">