SylphAI-Inc / AdalFlow

AdalFlow: The library to build & auto-optimize any LLM task.
http://adalflow.sylph.ai/
MIT License
1.63k stars 146 forks source link

Arbitrary deep prompt_kwargs #229

Open mrdrprofuroboros opened 6 days ago

mrdrprofuroboros commented 6 days ago

Is your feature request related to a problem? Please describe. I want to use a dict of Parameters that are inserted into the Prompt at runtime, e.g.

{{ params[used] }}
prompt_kwargs={
    "params": {
        "foo": Parameter(...),
        "bar": Parameter(...),
    },
    "used": "foo",
}

but right now they are not

  1. casted to text during rendering, only the top level params do: https://github.com/SylphAI-Inc/AdalFlow/blob/main/adalflow/adalflow/core/prompt_builder.py#L167
  2. they do not get registered in the component and I have to manually setattr them

Describe the solution you'd like I want to be able to register some sort of a dict in a component that would register such dynamic parameters and allow to pick them from this dict at Prompt rendering time. Something similar to nn.Embedding in pytorch maybe

Describe alternatives you've considered Right now I have to

for name, param in self.params.items():
    param.set_peers([self.params[p] for p in self.params if p != name])
    setattr(self, name, param)

and then manually put those that will be used in the Prompt to the top level of the prompt_kwargs so they make it to the graph

Additional context .

liyin2015 commented 5 days ago

@mrdrprofuroboros You are right! Right now arguments of GradComponents get traced and usually it is the value to be registered as a parameter such as an int or a dict. Generator's prompt_kwargs is already a special case where the value of the key is registered. Right now I dont see real use case where we would want such deep parameter registration.

Would you tell me more about your use case and if it is a must to support recursive parameter? This relates to the prompt_template. And then we can decide if we need to support recursive parameter registration