Skip to content

Commit 3ba9327

Browse files
feat: in vue template, support event_foo and foo, to avoid llm confusion
1 parent cd1beab commit 3ba9327

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

solara/components/component_vue.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,21 @@ def _widget_from_signature(
3131
for name, param in parameters.items():
3232
if name.startswith("event_"):
3333
event_name = name[6:]
34+
event_name_full = name # LLM's are quick stubborn in wanting to call `event_foo` instead of `foo`
3435

3536
def event_handler(self, data, buffers=None, event_name=event_name, param=param):
3637
callback = self._event_callbacks.get(event_name, param.default)
38+
if not callback:
39+
# support 'event_foo'
40+
callback = self._event_callbacks.get(event_name_full, None)
3741
if callback:
3842
if buffers:
3943
callback(data, buffers)
4044
else:
4145
callback(data)
4246

4347
classprops[f"vue_{event_name}"] = event_handler
48+
classprops[f"vue_{event_name_full}"] = event_handler
4449
elif name.startswith("on_") and name[3:] in parameters:
4550
# callback, will be handled by reacton
4651
continue
@@ -100,7 +105,10 @@ def component_vue(
100105
the vue template.
101106
102107
Arguments of the form `event_foo` should be callbacks that can be called from the vue template. They are
103-
available as the function `foo` in the vue template.
108+
available as the function `foo` and `event_foo` in the vue template.
109+
110+
Note that `foo` was kept for backwards compatibility, but LLM's have a tendency to use `event_foo`, so this was
111+
changed to `event_foo`.
104112
105113
[See the vue v2 api](https://v2.vuejs.org/v2/api/) for more information on how to use Vue, like `watch`,
106114
`methods` and lifecycle hooks such as `mounted` and `destroyed`.

tests/unit/component_frontend_test.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,3 +79,6 @@ def ComponentVueTest(event_foo=None):
7979
mock.assert_called_once_with(42)
8080
widget._handle_event(None, {"event": "foo", "data": 42}, [b"bar"])
8181
mock.assert_called_with(42, [b"bar"])
82+
83+
widget._handle_event(None, {"event": "event_foo", "data": 43}, [b"bar2"])
84+
mock.assert_called_with(43, [b"bar2"])

0 commit comments

Comments
 (0)