2 ms·
Curious as to why you chose to do it as a decorator instead of just a function call?
by jedberg 3y ago
Curious as to why you chose to do it as a decorator instead of just a function call?
- dragonwriter 3y agoLooking at the code, it looks like it is a way to support typing; just making it a function with the string template would let you return a dynamically-defined function but I think would make it harder to get static typing.
- jackmpcollins 3y agoI found this was the most compact way to represent what I wanted to define, and makes it easy to keep the type hints for parameters. If you look inside `@prompt` it's creating a `PromptFunction` instance which I think would be a similar API to what you would end up with without using decorators https://github.com/jackmpcollins/magentic/blob/afdb22513385b5f81e9f17fb3387cd61b77e98e2/src/magentic/prompt_function.py#L160-L167 https://github.com/jackmpcollins/magentic/blob/afdb22513385b...
- 3abiton 3y agoI never got on board of decorators in python, but you sold me on it.
- jwestbury 3y agoAnother really good use is performance metrics -- decorators to track execution time, for instance, with the ability to specify things like function groups, logic concepts, etc. It makes it trivial to add this sort of observability to your code.