ChatPromptTemplate
The ChatPromptTemplate class provides utilities for managing prompts, prompt templates, and conversation memory for AI interactions. It helps structure and format prompts for various AI tasks and maintain conversation context.
datapizza.modules.prompt.ChatPromptTemplate
Bases: Prompt
It takes as input a Memory, Chunks, Prompt and creates a Memory with all existing messages + the user's qry + function_call_retrieval + chunks retrieval. args: user_prompt_template: str # The user prompt jinja template retrieval_prompt_template: str # The retrieval prompt jinja template
format
Creates a new memory object that includes: - Existing memory messages - User's query - Function call retrieval results - Chunks retrieval results
Parameters:
Name | Type | Description | Default |
---|---|---|---|
memory
|
Memory | None
|
The memory object to add the new messages to. |
None
|
chunks
|
list[Chunk] | None
|
The chunks to add to the memory. |
None
|
user_prompt
|
str
|
The user's query. |
''
|
retrieval_query
|
str
|
The query to search the vectorstore for. |
''
|
Returns:
Type | Description |
---|---|
Memory
|
A new memory object with the new messages. |
Overview
The ChatPromptTemplate module provides utilities for managing prompts and prompt templates in AI pipelines.
Features:
- Prompt template management and formatting
- Context-aware prompt construction
- Integration with memory systems for conversation history
- Structured prompt formatting for different AI tasks
Usage Examples
Basic Prompt Management
import uuid
from datapizza.modules.prompt import ChatPromptTemplate
from datapizza.type import Chunk
# Create structured prompts for different tasks
system_prompt = ChatPromptTemplate(
user_prompt_template="You are helping with data analysis tasks, this is the user prompt: {{ user_prompt }}",
retrieval_prompt_template="Retrieved content:\n{% for chunk in chunks %}{{ chunk.text }}\n{% endfor %}"
)
print(system_prompt.format(user_prompt="Hello, how are you?", chunks=[Chunk(id=str(uuid.uuid4()), text="This is a chunk"), Chunk(id=str(uuid.uuid4()), text="This is another chunk")]))