guidance
guidance copied to clipboard
stack overflow in .serialize() of substring()
The following:
from guidance import substring
b = ("Hello " + substring("foobar baz " * 100)).serialize()
print(len(b))
Throw stack overflow exception:
Traceback (most recent call last):
File "/Users/michal/test.py", line 3, in <module>
b = ("Hello " + substring("foobar baz " * 100)).serialize()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/michal/src/ai/guidance/guidance/_grammar.py", line 212, in serialize
self._rec_create_index_map(index_map) # gives all the nodes an index
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/michal/src/ai/guidance/guidance/_grammar.py", line 222, in _rec_create_index_map
value._rec_create_index_map(index_map)
File "/Users/michal/src/ai/guidance/guidance/_grammar.py", line 222, in _rec_create_index_map
value._rec_create_index_map(index_map)
File "/Users/michal/src/ai/guidance/guidance/_grammar.py", line 222, in _rec_create_index_map
value._rec_create_index_map(index_map)
[Previous line repeated 995 more times]
RecursionError: maximum recursion depth exceeded
It looks like you would need an explicit TODO queue/stack in _rec_create_index_map and _rec_serialize
Yeah I think a stack based approach in both the _rec functions is likely to do the trick. I'll play with this. Thanks for the catch Michal :).