-
Notifications
You must be signed in to change notification settings - Fork 50
Description
Summary
Add support for using Go's embed.FS as a search directory source in dotprompt, allowing prompts to be embedded directly into Go binaries at compile time.
Motivation
Currently, dotprompt requires prompts to be loaded from the filesystem at runtime. This creates several challenges:
- Deployment complexity: Prompts must be distributed alongside binaries
- Runtime dependencies: Applications depend on external files being present
- Distribution concerns: Risk of missing or modified prompt files in production
- Binary portability: Single-file deployments are not possible when prompts are external
Using embed.FS would allow developers to bundle prompts directly into their Go binaries, eliminating these issues and enabling truly self-contained applications.
Proposed Solution
Add a new method or configuration option that accepts an embed.FS parameter as the search directory source.
API Design Options
Option 1: New constructor method
//go:embed prompts/*.prompt
var promptFS embed.FS
// New method accepting embed.FS
// NewPromptManagerFromEmbedFS(fs.FS, string) dotprompt.PromptManager
promptManager := dotprompt.NewPromptManagerFromEmbedFS(promptFS, "prompts")Implementation Considerations
embed.FSimplements thefs.FSinterface, so usingfs.FSas the parameter type would provide maximum flexibility- The embedded filesystem is read-only, which aligns well with production use cases
- Path handling should work consistently between regular filesystem and embedded filesystem
Use Cases
- Production deployments: Single binary with all prompts embedded
- Containerized applications: Smaller, simpler container images
- CLI tools: Self-contained executables with embedded prompt templates
- Testing: Reliable test fixtures that don't depend on external files
Example Usage
package main
import (
_ "embed"
"github.com/firebase/genkit/go/dotprompt"
)
//go:embed prompts/*.prompt
var prompts embed.FS
func main() {
promptManager := dotprompt.NewPromptManagerFromEmbedFS(prompts, "prompts")
promptFile := promptManager.GetPromptFile("example")
// Use prompt...
}Acceptance Criteria
- Support for
embed.FSas a prompt source - Consistent API with existing filesystem-based loading
- Proper error handling for embedded filesystem operations
- Documentation and examples showing embed.FS usage
- Compatibility with existing filesystem-based usage
- Unit tests covering embedded filesystem scenarios
Additional Notes
This feature would complement the existing filesystem-based approach rather than replace it. Developers could choose the approach that best fits their deployment model - embedded for production, filesystem-based for development with hot-reloading.