microsoft / vscode-prompt-tsx

MIT License
34 stars 1 forks source link

feat: add Expandable elements #105

Closed connor4312 closed 3 weeks ago

connor4312 commented 3 weeks ago

Expandable can be used like so, providing a callback which returns a string or a promise to a string:

<Expandable value={async sizing => {
  let data = 'hi';
  while (true) {
    const more = getMoreUsefulData();
    if (await sizing.countTokens(data + more) > sizing.tokenBudget) { break }
    data += more;
  }
  }
  return data;
}} />

After the prompt is rendered, the renderer sums up the tokens used by all messages. If there is unused budget, then any <Expandable /> elements' values are called again with their PromptSizing is increased by the token excess.

If there are multiple <Expandable /> elements, then they're re-called in the order in which they were initially rendered. Because they're designed to fill up any remaining space, it usually makes sense to have at most one <Expandable /> element per prompt.