michaelmagan / hydraai

a dev tool for generative UI that adapts to user context in real-time
https://usehydra.ai
MIT License
114 stars 8 forks source link

Add component tool definition and calling #21

Closed MichaelMilstead closed 1 month ago

MichaelMilstead commented 1 month ago

Allows package users to define data fetching functions, or "tools", for each component with parameters.

Updates registerComponent to store the function definitions. Updates generateComponent to let AI decide when to use the tools.

To enable this, generateComponent is split into two parts: 1: choose component (or decide no component should be used) 2: hydrate component

hydrate component passes the chosen component and any of its tools to AI, and lets AI either create props, or request that one of the tools be called to collect more data.

Currently, the tool needs to be called clientside where it is defined. So if AI decides to run a tool, that decision is passed back to the client, the client runs the tool to get the extra context data, and then calls hydrate component, passing the tool run results, so the AI can finally generate props for the chosen component, and return it back to the client.

This also means that we should be using fewer tokens and generation should be faster, since each component's context function doesn't need to be run each time we generate a component.

Some things to note: