-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
443 additions
and
162 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package cmd | ||
|
||
import ( | ||
"context" | ||
"os" | ||
|
||
"github.com/hupe1980/genie/pkg/codegen" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
// anthropicOptions holds the command-line flags for the anthropic command. | ||
type anthropicOptions struct { | ||
apiKey string | ||
model string | ||
temperature float64 | ||
maxTokens int | ||
} | ||
|
||
// newAnthropicCmd creates a Cobra command for running codegen provided by Anthropc. | ||
func newAnthropicCmd(globalOpts *globalOptions) *cobra.Command { | ||
opts := &anthropicOptions{} | ||
|
||
cmd := &cobra.Command{ | ||
Use: "anthropic", | ||
Short: "Run codegen provided by anthropic", | ||
SilenceUsage: true, | ||
SilenceErrors: true, | ||
Example: `genie anthropic -p "Create a python hello world" | ||
genie anthropic -p prompt.txt`, | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
apiKey := opts.apiKey | ||
if apiKey == "" { | ||
apiKey = os.Getenv("ANTHROPIC_API_KEY") | ||
} | ||
|
||
cg, err := codegen.NewAnthropic(apiKey, func(o *codegen.AnthropicOptions) { | ||
o.ModelName = opts.model | ||
o.Temperature = opts.temperature | ||
o.MaxTokens = opts.maxTokens | ||
}) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if err := run(context.Background(), globalOpts, cg); err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
}, | ||
} | ||
|
||
cmd.Flags().StringVarP(&opts.apiKey, "api-key", "", "", "anthropic api key") | ||
cmd.Flags().StringVarP(&opts.model, "model", "m", codegen.DefaultAnthropicModelName, "model to use") | ||
cmd.Flags().IntVarP(&opts.maxTokens, "max-tokens", "", codegen.DefaultOpenAIMaxTokens, "max tokens to use") | ||
cmd.Flags().Float64VarP(&opts.temperature, "temperature", "t", codegen.DefaultAnthropicTemperature, "temperature to use") | ||
|
||
return cmd | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package cmd | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"os" | ||
|
||
"github.com/hupe1980/genie/pkg/codegen" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
// openAIOptions holds the command-line flags for the openAI command. | ||
type openAIOptions struct { | ||
apiKey string | ||
model string | ||
temperature float32 | ||
maxTokens int | ||
} | ||
|
||
// newOpenAICmd creates a Cobra command for running codegen provided by OpenAI. | ||
func newOpenAICmd(globalOpts *globalOptions) *cobra.Command { | ||
opts := &openAIOptions{} | ||
|
||
cmd := &cobra.Command{ | ||
Use: "openai", | ||
Short: "Run codegen provided by openAI", | ||
SilenceUsage: true, | ||
SilenceErrors: true, | ||
Example: `genie openai -p "Create a python hello world" | ||
genie openai -p prompt.txt`, | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
apiKey := opts.apiKey | ||
if apiKey == "" { | ||
apiKey = os.Getenv("OPENAI_API_KEY") | ||
} | ||
|
||
cg, err := codegen.NewOpenAI(apiKey, func(o *codegen.OpenAIOptions) { | ||
o.ModelName = opts.model | ||
o.Temperature = opts.temperature | ||
o.MaxTokens = opts.maxTokens | ||
}) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if err := run(context.Background(), globalOpts, cg); err != nil { | ||
return err | ||
} | ||
|
||
fmt.Println() | ||
fmt.Println(cg.Info()) | ||
|
||
return nil | ||
}, | ||
} | ||
|
||
cmd.Flags().StringVarP(&opts.apiKey, "api-key", "", "", "openAI api key") | ||
cmd.Flags().StringVarP(&opts.model, "model", "m", codegen.DefaultOpenAIModelName, "model to use") | ||
cmd.Flags().IntVarP(&opts.maxTokens, "max-tokens", "", codegen.DefaultOpenAIMaxTokens, "max tokens to use") | ||
cmd.Flags().Float32VarP(&opts.temperature, "temperature", "t", codegen.DefaultOpenAITemperature, "temperature to use") | ||
|
||
return cmd | ||
} |
Oops, something went wrong.