Skip to content

Commit

Permalink
[Go] update dotprompt model strings to use provider/model (#94)
Browse files Browse the repository at this point in the history
* [Go] update dotprompt model strings to use provider/model

Also update coffee-shop to use GOOGLE_GENAI_API_KEY rather than GEMINI_API_KEY.
  • Loading branch information
ianlancetaylor authored May 9, 2024
1 parent 6946d0b commit 8275117
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
4 changes: 2 additions & 2 deletions go/ai/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ type generatorActionType = genkit.Action[*GenerateRequest, *GenerateResponse, *C

// LookupGeneratorAction looks up an action registered by [RegisterGenerator]
// and returns a generator that invokes the action.
func LookupGeneratorAction(name string) (Generator, error) {
action := genkit.LookupAction(genkit.ActionTypeModel, name, name)
func LookupGeneratorAction(provider, name string) (Generator, error) {
action := genkit.LookupAction(genkit.ActionTypeModel, provider, name)
if action == nil {
return nil, fmt.Errorf("LookupGeneratorAction: no generator action named %q", name)
}
Expand Down
6 changes: 5 additions & 1 deletion go/genkit/dotprompt/genkit.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,12 @@ func (p *Prompt) Execute(ctx context.Context, input *ActionInput) (*ai.GenerateR
if model == "" {
return nil, errors.New("dotprompt action: model not specified")
}
provider, name, found := strings.Cut(model, "/")
if !found {
return nil, errors.New("dotprompt model not in provider/name format")
}

generator, err = ai.LookupGeneratorAction(model)
generator, err = ai.LookupGeneratorAction(provider, name)
if err != nil {
return nil, err
}
Expand Down
8 changes: 4 additions & 4 deletions go/samples/coffee-shop/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,9 @@ type testAllCoffeeFlowsOutput struct {
}

func main() {
apiKey := os.Getenv("GEMINI_API_KEY")
apiKey := os.Getenv("GOOGLE_GENAI_API_KEY")
if apiKey == "" {
fmt.Fprintln(os.Stderr, "coffee-shop example requires setting GEMINI_API_KEY in the environment.")
fmt.Fprintln(os.Stderr, "coffee-shop example requires setting GOOGLE_GENAI_API_KEY in the environment.")
fmt.Fprintln(os.Stderr, "You can get an API key at https://ai.google.dev.")
os.Exit(1)
}
Expand All @@ -86,7 +86,7 @@ func main() {
simpleGreetingPrompt, err := dotprompt.Define("simpleGreeting",
&dotprompt.Frontmatter{
Name: "simpleGreeting",
Model: "google-genai",
Model: "google-genai/gemini-1.0-pro",
Input: dotprompt.FrontmatterInput{
Schema: jsonschema.Reflect(simpleGreetingInput{}),
},
Expand Down Expand Up @@ -121,7 +121,7 @@ func main() {
greetingWithHistoryPrompt, err := dotprompt.Define("greetingWithHistory",
&dotprompt.Frontmatter{
Name: "greetingWithHistory",
Model: "google-genai",
Model: "google-genai/gemini-1.0-pro",
Input: dotprompt.FrontmatterInput{
Schema: jsonschema.Reflect(customerTimeAndHistoryInput{}),
},
Expand Down

0 comments on commit 8275117

Please sign in to comment.