Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jinja support? #82

Open
samuelcolvin opened this issue Nov 21, 2024 · 4 comments
Open

Jinja support? #82

samuelcolvin opened this issue Nov 21, 2024 · 4 comments
Labels
enhancement New feature or request

Comments

@samuelcolvin
Copy link
Member

Instructor (and other libraries) support jinja templates for system prompt building, see here.

It would be pretty easily for us to support, then again it doesn't need to be build into the library, it just be implemented by the user.

We should at least add an example of how to do this.

Should we add formal support for it? If so what should the API be?

@samuelcolvin
Copy link
Member Author

Worth saying that Jinja is inherently not type-safe, and you can often get the same result with type safe code, e.g.

    ...
    return f"""
blah
blah blah
{'\n'.join(thing.foo for thing in deps.things}
...
"""

@BeautyyuYanli
Copy link

BeautyyuYanli commented Dec 2, 2024

I'm exiting to find your work so that I can get rid of other tedious agent frameworks! And I'd like to introduce my work Prompt-Bottle which do the same as the Instructor proposal.

However it can render not only string, but the whole message history!
Which means there are no difference among "system" "history" "new message", just give in how you store things and let template to render.It would be convenient if I want to render the memory in some complicated way like roleplay bot with multiple NPC.

And it also supports multimodal message by using placeholder to put them in string text.

looking forward to hearing from you 😉

@sydney-runkle sydney-runkle added the enhancement New feature or request label Dec 5, 2024
@SamBroomy
Copy link

Would be really interested in some form of templating feature in pydantic-ai.

I have also had an attempt at something like this with typed-prompt.

It tries to tie your template and the data that populates the template together.
It validates templates at definition time, so missing or unused variables in the template are caught right away.

This is my interpretation of the problem, but any support for templating in pydantic-ai would be greatly appreciated!

@samuelcolvin
Copy link
Member Author

Honestly I think #93 should cover 99% of cases.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants