Skip to content

[FR] Add embed.FS Support for Search Directory in the Go implementation #314

@jdfergason

Description

@jdfergason

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.FS implements the fs.FS interface, so using fs.FS as 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

  1. Production deployments: Single binary with all prompts embedded
  2. Containerized applications: Smaller, simpler container images
  3. CLI tools: Self-contained executables with embedded prompt templates
  4. 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.FS as 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions