Skip to content

Commit c3009c6

Browse files
committed
fix: dynamic prompt change
1 parent 383105b commit c3009c6

File tree

3 files changed

+17
-10
lines changed

3 files changed

+17
-10
lines changed

server/app.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -153,11 +153,11 @@ async def on_message(message):
153153
"nodes": nodes_info
154154
}
155155
channel.send(json.dumps(response))
156-
elif params.get("type") == "update_prompt":
157-
if "prompt" not in params:
156+
elif params.get("type") == "update_prompts":
157+
if "prompts" not in params:
158158
logger.warning("[Control] Missing prompt in update_prompt message")
159159
return
160-
await pipeline.update_prompts(params["prompt"])
160+
await pipeline.update_prompts(params["prompts"])
161161
response = {
162162
"type": "prompts_updated",
163163
"success": True

server/pipeline.py

+6
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,12 @@ async def set_prompts(self, prompts: Union[Dict[Any, Any], List[Dict[Any, Any]]]
3838
else:
3939
await self.client.set_prompts([prompts])
4040

41+
async def update_prompts(self, prompts: Union[Dict[Any, Any], List[Dict[Any, Any]]]):
42+
if isinstance(prompts, list):
43+
await self.client.update_prompts(prompts)
44+
else:
45+
await self.client.update_prompts([prompts])
46+
4147
async def put_video_frame(self, frame: av.VideoFrame):
4248
inp_tensor = self.video_preprocess(frame)
4349
self.client.put_video_input(inp_tensor)

ui/src/components/control-panel.tsx

+8-7
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ const InputControl = ({
109109

110110
export const ControlPanel = ({ panelState, onStateChange }: ControlPanelProps) => {
111111
const { controlChannel } = usePeerContext();
112-
const { currentPrompt, setCurrentPrompt } = usePrompt();
112+
const { currentPrompts, setCurrentPrompts } = usePrompt();
113113
const [availableNodes, setAvailableNodes] = useState<Record<string, NodeInfo>>({});
114114

115115
// Add ref to track last sent value and timeout
@@ -139,7 +139,7 @@ export const ControlPanel = ({ panelState, onStateChange }: ControlPanelProps) =
139139
const data = JSON.parse(event.data);
140140
if (data.type === "nodes_info") {
141141
setAvailableNodes(data.nodes);
142-
} else if (data.type === "prompt_updated") {
142+
} else if (data.type === "prompts_updated") {
143143
if (!data.success) {
144144
console.error("[ControlPanel] Failed to update prompt");
145145
}
@@ -171,7 +171,7 @@ export const ControlPanel = ({ panelState, onStateChange }: ControlPanelProps) =
171171
// Modify the effect that sends updates with debouncing
172172
useEffect(() => {
173173
const currentInput = panelState.nodeId && panelState.fieldName ? availableNodes[panelState.nodeId]?.inputs[panelState.fieldName] : null;
174-
if (!currentInput || !currentPrompt) return;
174+
if (!currentInput || !currentPrompts) return;
175175

176176
let isValidValue = true;
177177
let processedValue: any = panelState.value;
@@ -218,6 +218,7 @@ export const ControlPanel = ({ panelState, onStateChange }: ControlPanelProps) =
218218
// Set a new timeout for the update
219219
updateTimeoutRef.current = setTimeout(() => {
220220
// Create updated prompt while maintaining current structure
221+
const currentPrompt = currentPrompts[0];
221222
const updatedPrompt = JSON.parse(JSON.stringify(currentPrompt)); // Deep clone
222223
if (updatedPrompt[panelState.nodeId] && updatedPrompt[panelState.nodeId].inputs) {
223224
updatedPrompt[panelState.nodeId].inputs[panelState.fieldName] = processedValue;
@@ -231,17 +232,17 @@ export const ControlPanel = ({ panelState, onStateChange }: ControlPanelProps) =
231232

232233
// Send the full prompt update
233234
const message = JSON.stringify({
234-
type: "update_prompt",
235-
prompt: updatedPrompt
235+
type: "update_prompts",
236+
prompts: [updatedPrompt]
236237
});
237238
controlChannel.send(message);
238239

239240
// Only update current prompt after sending
240-
setCurrentPrompt(updatedPrompt);
241+
setCurrentPrompts([updatedPrompt]);
241242
}
242243
}, currentInput.type.toLowerCase() === 'number' ? 100 : 300); // Shorter delay for numbers, longer for text
243244
}
244-
}, [panelState.value, panelState.nodeId, panelState.fieldName, panelState.isAutoUpdateEnabled, controlChannel, availableNodes, currentPrompt, setCurrentPrompt]);
245+
}, [panelState.value, panelState.nodeId, panelState.fieldName, panelState.isAutoUpdateEnabled, controlChannel, availableNodes, currentPrompts, setCurrentPrompts]);
245246

246247
const toggleAutoUpdate = () => {
247248
onStateChange({ isAutoUpdateEnabled: !panelState.isAutoUpdateEnabled });

0 commit comments

Comments
 (0)