Prompts with Partial Example
Hello there! 👋 Welcome to this fun little Go example that showcases how to use prompts with partial variables using the langchaingo
library. Let's dive in and see what this code does!
What's This All About?
This example demonstrates how to create a prompt template with both regular input variables and partial variables. It's a great way to see how flexible and powerful prompt templates can be!
The Magic Explained
Here's what's happening in our code:
-
We create a PromptTemplate
with the following properties:
- A template string:
"{{.foo}}{{.bar}}"
- An input variable:
"bar"
- A partial variable:
"foo"
with the value "foo"
- The template format is set to Go's template format
-
We then format the prompt by providing a value for the "bar"
variable.
-
Finally, we print the result!
What to Expect
When you run this code, you'll see the output:
foobaz
Isn't that neat? The "foo"
comes from our partial variable, and "baz"
is the value we provided for the "bar"
input variable.
Why This Matters
This example shows how you can create flexible templates with some pre-defined parts (partial variables) and other parts that can be filled in later (input variables). It's super useful for creating dynamic prompts in various applications!
Give It a Try!
Feel free to play around with the code. Try changing the template, adding more variables, or experimenting with different values. The world of prompt templates is your oyster! 🦪
Happy coding, and may your prompts always be perfectly formatted! 🚀✨