Previously, priority was global within the entire prompt. This made
composition difficult since a child component might not know the range
of 'good' priorities in which is should act. Mistakes are also easy to
make because the default priority is MAX_SAFE_INTEGER.
This PR refactors the world so that priority is local in each tree
node. For example the tree of nodes...
...would be pruned in the order B->A->D->C. If two sibling elements
share the same priority, the renderer looks ahead at their direct
children and picks whichever one has a child with the lowest priority:
if the SystemMessage and UserMessage in the above example did not
declare priorities, the pruning order would be B->D->A->C.
Internally this involved some refactoring so that we preserve the tree
of elements during the render and incrementally remove elements from it
until we reach our budget. I was also able to remove much of the special
treatment of implicit line breaks with this new representation.
We may have a need for a priorityPassThru attribute in the future
to allow for logical wrapper elements.
In reworking this I also added a local meta property to represent
metadata that is local to an element and should be removed when the
element is pruned, which resolves #51. References are now just local
metadata that retain some special treatment in how they're returned
from the render method.
Previously,
priority
was global within the entire prompt. This made composition difficult since a child component might not know the range of 'good' priorities in which is should act. Mistakes are also easy to make because the default priority isMAX_SAFE_INTEGER
.This PR refactors the world so that
priority
is local in each tree node. For example the tree of nodes......would be pruned in the order
B->A->D->C
. If two sibling elements share the same priority, the renderer looks ahead at their direct children and picks whichever one has a child with the lowest priority: if theSystemMessage
andUserMessage
in the above example did not declare priorities, the pruning order would beB->D->A->C
.Internally this involved some refactoring so that we preserve the tree of elements during the render and incrementally remove elements from it until we reach our budget. I was also able to remove much of the special treatment of implicit line breaks with this new representation.
We may have a need for a
priorityPassThru
attribute in the future to allow for logical wrapper elements.In reworking this I also added a
local
meta property to represent metadata that is local to an element and should be removed when the element is pruned, which resolves #51. References are now just local metadata that retain some special treatment in how they're returned from the render method.