marvin.prompts
Prompt system for Marvin.
This module provides a flexible prompt system that supports:
- Prompts defined as strings or paths to template files
- Static type checking of prompt variables
- Dynamic prompt creation from function docstrings and signatures
- Serialization of prompts and their required attributes
Classes
Prompt
-
from_fn
Create a Prompt class from a function’s docstring and signature. Args: fn: The function to create a prompt from. The function’s docstring will be used as the template, and its signature will define the required attributes. Example: def greet(name: str, age: int): ''' SYSTEM: You are a friendly assistant. USER: Hi , how old are you? ASSISTANT: I’m an AI, but you’re years old! ''' pass GreetPrompt = Prompt.from_fn(greet) prompt = GreetPrompt(name=“Alice”, age=30) messages = prompt.to_messages() -
to_messages
Convert the prompt to a list of messages with roles. The template can contain role markers (SYSTEM:, USER:, ASSISTANT:) to indicate message roles. Text without a role marker is treated as a user message. Example template: ''' SYSTEM: You are a helpful assistant. USER: Hi ! ASSISTANT: Hello ! How can I help you? '''
Template
render
Render the template with variables.
Parent Module:
marvin