Replies: 2 comments 2 replies
-
@kmheckel One way to do something like this is using @e2b-dev and provide the model a tool to use to execute python code in an E2B sandbox. See the magentic cookbook here https://github.com/e2b-dev/e2b-cookbook/blob/1bd110b03748751bfeac1e8509cf91c037f59814/examples/magentic-code-interpreter/magentic_code_interpreter.ipynb (not recommended) A DIY version of doing this more natively would be to create a prompt-function returning a I've been thinking about how higher-order functions might work in magentic. I think you would ideally be able to write prompt-functions with return types
For prompt-functions returning Pydantic has an For prompt-functions returning I'm very interested to hear how this goes for you! |
Beta Was this translation helpful? Give feedback.
-
Thanks for the timely reply @jackmpcollins ! The possibility of higher-order functionality is exciting and something I'd be really interested in, such as the ability to create a promptchain with relevant functions and execute it. It would be powerful too if the functions could be retrieved as well as added to/updated over time, enabling approaches such as Voyager where the system compositionally builds tools to work with an environment. Returning a prompt function seems straightforward except for how to incorporate the added functions - everything else seems easy to read/write in the FunctionSchema. My current solution involves using I've looked at Trace (https://github.com/microsoft/trace) to see how they handle working with code since it has a similar idea of generating and executing code, there might be some pointers there on how to do things. |
Beta Was this translation helpful? Give feedback.
-
Hi, I was wondering if there is a best practice for generating python functions/Callables directly from LLMs as part of structured outputs? I tried adding Callables as part of a pydantic model but didn't have much luck so I've tried using a wrapper class which I registered using the guide (https://magentic.dev/examples/registering_custom_type/).
Is there a better way to go about this? I'd like to generate python tools dynamically to use as part of the workflow. I know there's issues with imports and scope and other things but wanted to ask.
Beta Was this translation helpful? Give feedback.
All reactions