Skip to content

Commit

Permalink
feat(completion): add subcommand parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
jigsaw373 committed Apr 21, 2023
1 parent 0154ff3 commit 296072e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
4 changes: 2 additions & 2 deletions cmd/cli/completion.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func newOAIClients() (oaiClients, error) {
return clients, nil
}

func gptCompletion(ctx context.Context, client oaiClients, prompts []string, deploymentName string) (string, error) {
func completion(ctx context.Context, client oaiClients, prompts []string, deploymentName string, subcommand string) (string, error) {
temp := float32(*sensitivity)

maxTokens, err := calculateMaxTokens(prompts, deploymentName)
Expand All @@ -68,7 +68,7 @@ func gptCompletion(ctx context.Context, client oaiClients, prompts []string, dep
}

var prompt strings.Builder
_, err = fmt.Fprintf(&prompt, "You are a Terraform HCL generator, only generate valid Terraform HCL templates.")
_, err = fmt.Fprint(&prompt, subcommand)

if err != nil {
return "", fmt.Errorf("error prompt string builder: %w", err)
Expand Down
7 changes: 5 additions & 2 deletions cmd/cli/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ import (
"github.com/walles/env"
)

const version = "0.0.1"
const (
version = "0.0.1"
applySubCommand = "You are a Terraform HCL generator, only generate valid Terraform HCL without provider templates."
)

var (
openAIDeploymentName = flag.String("openai-deployment-name", env.GetOr("OPENAI_DEPLOYMENT_NAME", env.String, "text-davinci-003"), "The deployment name used for the model in OpenAI service.")
Expand Down Expand Up @@ -69,7 +72,7 @@ func run(args []string) error {
return fmt.Errorf("error run command: %w", err)
}

completion, err := gptCompletion(ctx, oaiClients, args, *openAIDeploymentName)
completion, err := completion(ctx, oaiClients, args, *openAIDeploymentName, applySubCommand)
if err != nil {
return err
}
Expand Down

0 comments on commit 296072e

Please sign in to comment.