Skip to content

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.

fixes chat config not updating (#7808)

Shahmir Varqhaa677f48baf4f
diff --git a/examples/ai/chat/pydantic-ai-chat.py b/examples/ai/chat/pydantic-ai-chat.py
index 3e197e2917..e5d6f1b520 100644
--- a/examples/ai/chat/pydantic-ai-chat.py
+++ b/examples/ai/chat/pydantic-ai-chat.py
@@ -1,6 +1,6 @@
import marimo
-__generated_with = "0.18.4"
+__generated_with = "0.19.2"
app = marimo.App(width="medium")
with app.setup(hide_code=True):
@@ -168,7 +168,7 @@ def _(
@app.cell
-def _(agent):
+def _(agent, model_name):
chatbot = mo.ui.chat(
mo.ai.llm.pydantic_ai(agent),
prompts=[
@@ -179,6 +179,7 @@ def _(agent):
],
allow_attachments=True,
show_configuration_controls=True,
+ config={"top_p": None} if model_name.startswith("claude") else None,
)
chatbot
return (chatbot,)
diff --git a/frontend/src/plugins/impl/chat/chat-ui.tsx b/frontend/src/plugins/impl/chat/chat-ui.tsx
index 505b3e12f0..e68cf7d8a4 100644
--- a/frontend/src/plugins/impl/chat/chat-ui.tsx
+++ b/frontend/src/plugins/impl/chat/chat-ui.tsx
@@ -75,12 +75,26 @@ interface Props extends PluginFunctions {
export const Chatbot: React.FC<Props> = (props) => {
const [input, setInput] = useState("");
const [config, setConfig] = useState<ChatConfig>(props.config);
+ const [prevPropsConfig, setPrevPropsConfig] = useState<ChatConfig>(
+ props.config,
+ );
const [files, setFiles] = useState<File[] | undefined>(undefined);
const fileInputRef = useRef<HTMLInputElement>(null);
const formRef = useRef<HTMLFormElement>(null);
const codeMirrorInputRef = useRef<ReactCodeMirrorRef>(null);
const scrollContainerRef = useRef<HTMLDivElement>(null);
+ const configChanged = Object.keys(props.config).some(
+ (key) =>
+ props.config[key as keyof ChatConfig] !==
+ prevPropsConfig[key as keyof ChatConfig],
+ );
+
+ if (configChanged) {
+ setConfig(props.config);
+ setPrevPropsConfig(props.config);
+ }
+
// Use a ref to avoid stale closure in the fetch callback
const configRef = useRef<ChatConfig>(config);
configRef.current = config;
@@ -739,7 +753,6 @@ const ConfigPopup: React.FC<{
config: ChatConfig;
onChange: (newConfig: ChatConfig) => void;
}> = ({ config, onChange }) => {
- const [localConfig, setLocalConfig] = useState<ChatConfig>(config);
const [open, setOpen] = useState(false);
const handleChange = (key: keyof ChatConfig, value: number | null) => {
@@ -754,8 +767,7 @@ const ConfigPopup: React.FC<{
finalValue = clampedValue;
}
- const newConfig = { ...localConfig, [key]: finalValue };
- setLocalConfig(newConfig);
+ const newConfig = { ...config, [key]: finalValue };
onChange(newConfig);
};
@@ -782,7 +794,7 @@ const ConfigPopup: React.FC<{
<PopoverContent className="w-70 border">
<div className="grid gap-3">
<h4 className="font-bold leading-none">Configuration</h4>
- {Objects.entries(localConfig).map(([key, value]) => (
+ {Objects.entries(config).map(([key, value]) => (
<div key={key} className="grid grid-cols-3 items-center gap-1">
<Label
htmlFor={key}