@@ -21,6 +21,7 @@ import (
2121	"context" 
2222	"errors" 
2323	"fmt" 
24+ 	"io/fs" 
2425	"log/slog" 
2526	"os" 
2627	"os/signal" 
@@ -46,6 +47,7 @@ type Genkit struct {
4647type  genkitOptions  struct  {
4748	DefaultModel  string        // Default model to use if no other model is specified. 
4849	PromptDir     string        // Directory where dotprompts are stored. Will be loaded automatically on initialization. 
50+ 	PromptFS      fs.FS         // Filesystem that will be used for PromptDir lookup. 
4951	Plugins       []api.Plugin  // Plugin to initialize automatically. 
5052}
5153
@@ -69,6 +71,13 @@ func (o *genkitOptions) apply(gOpts *genkitOptions) error {
6971		gOpts .PromptDir  =  o .PromptDir 
7072	}
7173
74+ 	if  o .PromptFS  !=  nil  {
75+ 		if  gOpts .PromptFS  !=  nil  {
76+ 			return  errors .New ("cannot set prompt filesystem more than once (WithPromptFS)" )
77+ 		}
78+ 		gOpts .PromptFS  =  o .PromptFS 
79+ 	}
80+ 
7281	if  len (o .Plugins ) >  0  {
7382		if  gOpts .Plugins  !=  nil  {
7483			return  errors .New ("cannot set plugins more than once (WithPlugins)" )
@@ -106,6 +115,12 @@ func WithPromptDir(dir string) GenkitOption {
106115	return  & genkitOptions {PromptDir : dir }
107116}
108117
118+ // WithPromptFS is a more generic version of `WithPromptDir` and accepts a filesytem 
119+ // instead of directory path 
120+ func  WithPromptFS (fsys  fs.FS ) GenkitOption  {
121+ 	return  & genkitOptions {PromptFS : fsys }
122+ }
123+ 
109124// Init creates and initializes a new [Genkit] instance with the provided options. 
110125// It sets up the registry, initializes plugins ([WithPlugins]), loads prompts 
111126// ([WithPromptDir]), and configures other settings like the default model 
@@ -184,7 +199,11 @@ func Init(ctx context.Context, opts ...GenkitOption) *Genkit {
184199
185200	ai .ConfigureFormats (r )
186201	ai .DefineGenerateAction (ctx , r )
187- 	ai .LoadPromptDir (r , gOpts .PromptDir , "" )
202+ 	if  gOpts .PromptFS  ==  nil  {
203+ 		ai .LoadPromptDir (r , gOpts .PromptDir , "" )
204+ 	} else  {
205+ 		ai .LoadPromptFS (r , gOpts .PromptFS , gOpts .PromptDir , "" )
206+ 	}
188207
189208	r .RegisterValue (api .DefaultModelKey , gOpts .DefaultModel )
190209	r .RegisterValue (api .PromptDirKey , gOpts .PromptDir )
0 commit comments