Prompts with Partial Functions Example
This example demonstrates how to use the langchaingo
library to create a prompt template with partial functions. The program showcases a simple yet powerful feature of dynamic prompt generation.
What This Example Does
-
Prompt Template Creation: The example creates a PromptTemplate
with a template string that includes placeholders for an adjective and a date.
-
Partial Variables: It uses a partial variable for the date, which is a function that returns the current date formatted as "Month Day, Year".
-
Dynamic Date Insertion: Every time the prompt is formatted, it automatically inserts the current date without needing to pass it as an input.
-
User Input: The program allows for the adjective to be provided as an input when formatting the prompt.
-
Prompt Formatting: It demonstrates how to format the prompt with the given input and the dynamically generated date.
-
Output: The formatted prompt is printed to the console.
Key Features
- Dynamic Content: Shows how to include dynamic content (current date) in prompts.
- Partial Functions: Demonstrates the use of partial variables with functions.
- Flexible Templating: Uses Go's template format for creating prompts.
Running the Example
When you run this example, it will output a prompt asking for a joke about the current date. The adjective "funny" is hardcoded in this example, but you could easily modify it to accept user input.
Example output:
Tell me a funny joke about the day March 14, 2024
This example is great for understanding how to create more dynamic and context-aware prompts in your language model applications using langchaingo
.