How To Do AI Prompt Templating

preview_player
Показать описание

In this video, I'll show you how to use Jinja2 for AI prompt templates. While Jinja2 is commonly used for generating HTML pages, it's also incredibly effective for tools designed to interact with Large Language Models (LLMs).

🔖 Chapters:
0:00 Intro
1:12 OpenAI helper function
2:57 Jinja2 template
4:31 Main file
6:36 Outro

#arjancodes #softwaredesign #python
Рекомендации по теме
Комментарии
Автор

I’d give Langchain another look. Once your prompts get more complex, you swap LLMs frequently or start rolling in RAG, loops, etc etc, simple API calls and jinja templates will become unmanageable. Even without all of that, Langsmith makes it worthwhile.

Mjhapp
Автор

In the 60s some professors raised a chimp in a human family enviroment. Hoping the chimp become more human. The oposite happen the child becames more chimp. Here you exemplify this perfectly, in the hope of get more context information from the machine, you satart being less human and more machine like. Obviusly you are the inteligent part. Love your channel.

adrianojordao
Автор

Funny, was just facing the same questions and was playing around. As some others here suggested, I stuck with f-strings for now, as it removes a fairly big dependency and when developing I like to see the prompt as I am playing around with it. But in Production this can be a huge cleanup in the code!

the.droetker
Автор

I'd be interested in more about your setup and Jinja.

hermandekoning
Автор

Jinja2 is great when you can re-use your special formatting over several templates. It is a bit restrictive but that makes writing correct templates easier.

I use templates a lot for code generation, where the templates have almost no overlap, meaning there is very little re-use of special formatting filters. In that case, Mako is more powerful. But Mako is harder to debug.

TheEvertw
Автор

I have been using txt files, and they have worked perfectly for me

emperorsixpacks
Автор

I've started using Jinja for my prompts mainly because I found myself converting lists into strings with a line break just to be well-formatted. Another problem it solved was that my IDE always complained about lines over 79 characters, which is pretty common for prompts. I know it is possible to break the strings into multiple lines, but I think it is too much work when the prompt starts getting bigger. F-strings don't work well if you have to put some examples of JSON into the prompt, a common use if you are using the LLM to extract data from an unstructured text.

muriloozol
Автор

In my company we use jinga2 for code generation, it's also very nice for that

loic
Автор

marvin, pydantic, instructor, langchain and now I'm going to try jinj2 in that mix

plaskut
Автор

For those that are going to use Jinja, please note that it breaks easily, if anything changes. So make a FULL requirements.txt file, AND note the python version you have tested it with. I cannot count how many times I come back to a Jinja script a month later, and it does not work because something has been updated...

tacozmacleo
Автор

How is this different from storing a format string as a file, then reading it and using prompt.format(...)? It seems overkill to use a whole templating engine for something so simple.

maleldil
Автор

I have a similar setup to this but I use functions with f strings. It's not entirely easy to read but I like that each prompt it a function that I can put behind a factory. I might pivot to jinja though for some things. Langchain however is a complicated mess and I hate it

CharleswoodSpudzyofficial
Автор

curious, why not use yield and streaming response to give a better user experience ?

MicheleHjorleifsson
Автор

It just hurts that the image showcase a shinobi (aka ninja) instead of a shrine (jinja). The words are not even related at all...

AlejandroMéndez-jj
Автор

0:34 please do a langchain roast video. I've also been using it for my stuff and getting both frustrated and confused the MORE familiar I become with it, which feels backwards.

DaveParr
Автор

Not to sound mean but it doesn't really convince me to use Jinja now. the same thing can be achieved using something like "{hello}".format(hello="sup") and no matter where you keep the string template. What'd work better is showing off some smart features Jinja does (of which i am not aware tho).

andrewmenshicov
Автор

f-strings work fine for me but i don't have conditional logic (yet!)

dankprole