Skip to content

Commit

Permalink
adding support for prompts
Browse files Browse the repository at this point in the history
  • Loading branch information
dipjyotimetia committed Feb 21, 2024
1 parent b795759 commit 8e9fcee
Show file tree
Hide file tree
Showing 8 changed files with 156 additions and 23 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# jarvis Test Automation Assistant

A powerful CLI tool powered by Google's Gemini Pro LLM and Gemini Vision Pro to revolutionize software testing. Jarvis aims to streamline test scenario generation and testcase writing directly from API specifications or protocol buffer definitions.
Jarvis is a powerful CLI tool that leverages advanced generative AI technologies (such as Google's Gemini Pro LLM and Gemini Vision Pro) to streamline and enhance various software testing activities. It aims to revolutionize how we approach test case generation and scenario creation.

## Features:

Expand Down
8 changes: 4 additions & 4 deletions cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ var version = "0.0.2"

var rootCmd = &cobra.Command{
Use: "jarvis",
Short: "jarvis is a very fast static site generator",
Short: "A generative AI-driven CLI for testing",
Long: `Jarvis is a powerful toolkit that leverages generative AI to streamline and enhance various testing activities.`,
Version: version,
Long: `Generative ai based cli to perform different testing activity`,
Run: func(cmd *cobra.Command, args []string) {
if len(args) == 0 {
cmd.Help()
_ = cmd.Help()
return
}
},
Expand All @@ -31,7 +31,7 @@ func init() {

func Execute() {
if err := rootCmd.Execute(); err != nil {
fmt.Println(err)
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
}
13 changes: 10 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@ go 1.22
require (
github.com/Azure/azure-sdk-for-go/sdk/ai/azopenai v0.4.1
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.9.2
github.com/briandowns/spinner v1.23.0
github.com/fatih/color v1.16.0
github.com/google/generative-ai-go v0.8.0
github.com/google/go-github/v59 v59.0.0
github.com/manifoldco/promptui v0.9.0
github.com/spf13/cobra v1.8.0
golang.org/x/oauth2 v0.17.0
google.golang.org/api v0.165.0
Expand All @@ -18,6 +21,7 @@ require (
cloud.google.com/go/compute/metadata v0.2.3 // indirect
cloud.google.com/go/longrunning v0.5.5 // indirect
github.com/Azure/azure-sdk-for-go/sdk/internal v1.5.2 // indirect
github.com/chzyer/readline v1.5.1 // indirect
github.com/felixge/httpsnoop v1.0.4 // indirect
github.com/go-logr/logr v1.4.1 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
Expand All @@ -28,6 +32,8 @@ require (
github.com/googleapis/enterprise-certificate-proxy v0.3.2 // indirect
github.com/googleapis/gax-go/v2 v2.12.1 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/spf13/pflag v1.0.5 // indirect
go.opencensus.io v0.24.0 // indirect
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.48.0 // indirect
Expand All @@ -39,12 +45,13 @@ require (
golang.org/x/net v0.21.0 // indirect
golang.org/x/sync v0.6.0 // indirect
golang.org/x/sys v0.17.0 // indirect
golang.org/x/term v0.17.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/time v0.5.0 // indirect
google.golang.org/appengine v1.6.8 // indirect
google.golang.org/genproto v0.0.0-20240213162025-012b6fc9bca9 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20240213162025-012b6fc9bca9 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240213162025-012b6fc9bca9 // indirect
google.golang.org/genproto v0.0.0-20240221002015-b0ce06bbee7c // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20240221002015-b0ce06bbee7c // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240221002015-b0ce06bbee7c // indirect
google.golang.org/grpc v1.61.1 // indirect
google.golang.org/protobuf v1.32.0 // indirect
)
38 changes: 32 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,18 @@ github.com/Azure/azure-sdk-for-go/sdk/internal v1.5.2/go.mod h1:yInRyqWXAuaPrgI7
github.com/AzureAD/microsoft-authentication-library-for-go v1.0.0 h1:OBhqkivkhkMqLPymWEppkm7vgPQY2XsHoEkaMQ0AdZY=
github.com/AzureAD/microsoft-authentication-library-for-go v1.0.0/go.mod h1:kgDmCTgBzIEPFElEF+FK0SdjAor06dRq2Go927dnQ6o=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/briandowns/spinner v1.23.0 h1:alDF2guRWqa/FOZZYWjlMIx2L6H0wyewPxo/CH4Pt2A=
github.com/briandowns/spinner v1.23.0/go.mod h1:rPG4gmXeN3wQV/TsAY4w8lPdIM6RX3yqeBQJSrbXjuE=
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI=
github.com/chzyer/logex v1.2.1 h1:XHDu3E6q+gdHgsdTPH6ImJMIp436vR6MPtH8gP05QzM=
github.com/chzyer/logex v1.2.1/go.mod h1:JLbx6lG2kDbNRFnfkgvh4eRJRPX1QCoOIWomwysCBrQ=
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI=
github.com/chzyer/readline v1.5.1 h1:upd/6fQk4src78LMRzh5vItIt361/o4uq553V8B5sGI=
github.com/chzyer/readline v1.5.1/go.mod h1:Eh+b79XXUwfKfcPLepksvw2tcLE/Ct21YObkaSkeBlk=
github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU=
github.com/chzyer/test v1.0.0 h1:p3BQDXSxOhOG0P9z6/hGnII4LGiEPOYBhs8asl/fC04=
github.com/chzyer/test v1.0.0/go.mod h1:2JlltgoNkt4TW/z9V/IzDdFaMTM2JPIi26O1pF38GC8=
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc=
github.com/cncf/xds/go v0.0.0-20231109132714-523115ebc101 h1:7To3pQ+pZo0i3dsWEbinPNFs5gPSBOsJtx3wTT94VBY=
Expand All @@ -35,6 +46,8 @@ github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1m
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
github.com/envoyproxy/protoc-gen-validate v1.0.2 h1:QkIBuU5k+x7/QXPvPPnWXWlCdaBFApVqftFV6k087DA=
github.com/envoyproxy/protoc-gen-validate v1.0.2/go.mod h1:GpiZQP3dDbg4JouG/NNS7QWXpgx6x8QiMKdmN72jogE=
github.com/fatih/color v1.16.0 h1:zmkK9Ngbjj+K0yRhTVONQh1p/HknKYSlNT+vZCzyokM=
github.com/fatih/color v1.16.0/go.mod h1:fL2Sau1YI5c0pdGEVCbKQbLXB6edEj1ZgiY4NijnWvE=
github.com/felixge/httpsnoop v1.0.4 h1:NFTV2Zj1bL4mc9sqWACXbQFVBBg2W3GPvqp8/ESS2Wg=
github.com/felixge/httpsnoop v1.0.4/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U=
github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
Expand Down Expand Up @@ -93,6 +106,13 @@ github.com/joho/godotenv v1.3.0 h1:Zjp+RcGpHhGlrMbJzXTrZZPrWj+1vfm90La1wgB6Bhc=
github.com/joho/godotenv v1.3.0/go.mod h1:7hK45KPybAkOC6peb+G5yklZfMxEjkZhHbwpqxOKXbg=
github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc=
github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw=
github.com/manifoldco/promptui v0.9.0 h1:3V4HzJk1TtXW1MTZMP7mdlwbBpIinw3HztaIlYthEiA=
github.com/manifoldco/promptui v0.9.0/go.mod h1:ka04sppxSGFAtxX0qhlYQjISsg9mR4GWtQEhdbn6Pgg=
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8 h1:KoWmjvw+nsYOo29YJK9vDA65RGE3NrOnUtO7a+RF9HU=
github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8/go.mod h1:HKlIX3XHQyzLZPlr7++PzdhaXEj94dEiJgZDTsxEqUI=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
Expand Down Expand Up @@ -155,17 +175,23 @@ golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJ
golang.org/x/sync v0.6.0 h1:5BMeUDZ7vkXGfEr1x9B4bRcTH4lpkTkpdh0T/J+qjbQ=
golang.org/x/sync v0.6.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20181122145206-62eef0e2fa9b/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220310020820-b874c991c1a5/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.17.0 h1:25cE3gD+tdBA7lp7QfhuV+rJiE9YXTcS3VG1SqssI/Y=
golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/term v0.17.0 h1:mkTF7LCd6WGJNL3K1Ad7kwxNfYAW6a8a8QqtMblp/4U=
golang.org/x/term v0.17.0/go.mod h1:lLRBjIVuehSbZlaOtGMbcMncT+aqLLLmKrsjNrUguwk=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
Expand All @@ -192,12 +218,12 @@ google.golang.org/appengine v1.6.8/go.mod h1:1jJ3jBArFh5pcgW8gCtRJnepW8FzD1V44FJ
google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc=
google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc=
google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013/go.mod h1:NbSheEEYHJ7i3ixzK3sjbqSGDJWnxyFXZblF3eUsNvo=
google.golang.org/genproto v0.0.0-20240213162025-012b6fc9bca9 h1:9+tzLLstTlPTRyJTh+ah5wIMsBW5c4tQwGTN3thOW9Y=
google.golang.org/genproto v0.0.0-20240213162025-012b6fc9bca9/go.mod h1:mqHbVIp48Muh7Ywss/AD6I5kNVKZMmAa/QEW58Gxp2s=
google.golang.org/genproto/googleapis/api v0.0.0-20240213162025-012b6fc9bca9 h1:4++qSzdWBUy9/2x8L5KZgwZw+mjJZ2yDSCGMVM0YzRs=
google.golang.org/genproto/googleapis/api v0.0.0-20240213162025-012b6fc9bca9/go.mod h1:PVreiBMirk8ypES6aw9d4p6iiBNSIfZEBqr3UGoAi2E=
google.golang.org/genproto/googleapis/rpc v0.0.0-20240213162025-012b6fc9bca9 h1:hZB7eLIaYlW9qXRfCq/qDaPdbeY3757uARz5Vvfv+cY=
google.golang.org/genproto/googleapis/rpc v0.0.0-20240213162025-012b6fc9bca9/go.mod h1:YUWgXUFRPfoYK1IHMuxH5K6nPEXSCzIMljnQ59lLRCk=
google.golang.org/genproto v0.0.0-20240221002015-b0ce06bbee7c h1:Zmyn5CV/jxzKnF+3d+xzbomACPwLQqVpLTpyXN5uTaQ=
google.golang.org/genproto v0.0.0-20240221002015-b0ce06bbee7c/go.mod h1:VUhTRKeHn9wwcdrk73nvdC9gF178Tzhmt/qyaFcPLSo=
google.golang.org/genproto/googleapis/api v0.0.0-20240221002015-b0ce06bbee7c h1:9g7erC9qu44ks7UK4gDNlnk4kOxZG707xKm4jVniy6o=
google.golang.org/genproto/googleapis/api v0.0.0-20240221002015-b0ce06bbee7c/go.mod h1:5iCWqnniDlqZHrd3neWVTOwvh/v6s3232omMecelax8=
google.golang.org/genproto/googleapis/rpc v0.0.0-20240221002015-b0ce06bbee7c h1:NUsgEN92SQQqzfA+YtqYNqYmB3DMMYLlIwUZAQFVFbo=
google.golang.org/genproto/googleapis/rpc v0.0.0-20240221002015-b0ce06bbee7c/go.mod h1:H4O17MA/PE9BsGx3w+a+W2VOLLD1Qf7oJneAoU6WktY=
google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c=
google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg=
google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQciAY=
Expand Down
41 changes: 38 additions & 3 deletions pkg/commands/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@ package commands

import (
"context"
"time"

"github.com/briandowns/spinner"
"github.com/dipjyotimetia/jarvis/pkg/engine/files"
"github.com/dipjyotimetia/jarvis/pkg/engine/gemini"
"github.com/dipjyotimetia/jarvis/pkg/engine/prompt"
"github.com/spf13/cobra"
)

Expand All @@ -27,6 +30,25 @@ func GenerateTestModule() *cobra.Command {
specPath, _ := cmd.Flags().GetString("path")
outputPath, _ := cmd.Flags().GetString("output")

s := spinner.New(spinner.CharSets[36], 100*time.Millisecond)
s.Color("green")
s.Suffix = " Generating Tests..."
s.FinalMSG = "Tests Generated Successfully!\n"

languageContent := prompt.PromptContent{
ErrorMsg: "Please provide a valid language.",
Label: "What programming lanaguage would you like to use?",
ItemType: "language",
}
language := prompt.SelectLanguage(languageContent)

specContent := prompt.PromptContent{
ErrorMsg: "Please provide a valid spec.",
Label: "What spec would you like to use?",
ItemType: "spec",
}
spec := prompt.SelectLanguage(specContent)

ctx := context.Background()

ai, err := gemini.New(ctx)
Expand All @@ -42,10 +64,14 @@ func GenerateTestModule() *cobra.Command {
if err != nil {
panic(err)
}
err = ai.GenerateTextStreamWriter(ctx, reader, outputPath)

s.Start()

err = ai.GenerateTextStreamWriter(ctx, reader, outputPath, language, spec)
if err != nil {
panic(err)
}
s.Stop()
return nil
},
}
Expand All @@ -62,8 +88,15 @@ func GenerateTestScenarios() *cobra.Command {
RunE: func(cmd *cobra.Command, args []string) error {
specPath, _ := cmd.Flags().GetString("path")

ctx := context.Background()
specContent := prompt.PromptContent{
ErrorMsg: "Please provide a valid spec.",
Label: "What spec would you like to use?",
ItemType: "spec",
}

spec := prompt.SelectLanguage(specContent)

ctx := context.Background()
ai, err := gemini.New(ctx)
if err != nil {
panic(err)
Expand All @@ -73,11 +106,13 @@ func GenerateTestScenarios() *cobra.Command {
if err != nil {
panic(err)
}

reader, err := files.ReadFile(file[0])
if err != nil {
panic(err)
}
err = ai.GenerateTextStream(ctx, reader)

err = ai.GenerateTextStream(ctx, reader, spec)
if err != nil {
panic(err)
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/engine/gemini/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ var apiKey = os.Getenv("API_KEY")

type Client interface {
GenerateText(ctx context.Context, prompt string) (*genai.GenerateContentResponse, error)
GenerateTextStream(ctx context.Context, specs []genai.Text) error
GenerateTextStreamWriter(ctx context.Context, specs []genai.Text, outputFolder string) error
GenerateTextStream(ctx context.Context, specs []genai.Text, specType string) error
GenerateTextStreamWriter(ctx context.Context, specs []genai.Text, language, specType string, outputFolder string) error
GenerateVision(ctx context.Context, promptPart []genai.Part) (*genai.GenerateContentResponse, error)
CompareImage(ctx context.Context, promptParts []string, search string) (*genai.GenerateContentResponse, error)
GenerateVisionStream(ctx context.Context, prompt string) (*genai.GenerateContentResponseIterator, error)
Expand Down
8 changes: 4 additions & 4 deletions pkg/engine/gemini/text.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ func (c *client) GenerateText(ctx context.Context, prompt string) (*genai.Genera
}

// GenerateTextStream GenerateContentStream
func (c *client) GenerateTextStream(ctx context.Context, specs []genai.Text) error {
func (c *client) GenerateTextStream(ctx context.Context, specs []genai.Text, specType string) error {
var prompts []genai.Part
for _, spec := range specs {
prompts = append(prompts, spec)
}
prompts = append(prompts, genai.Text("what are possible test cases for the provided openapi spec file."))
prompts = append(prompts, genai.Text(fmt.Sprintf("what are possible test scenarios for the provided %s spec file.", specType)))

resp := c.ProModel().GenerateContentStream(ctx, prompts...)
for {
Expand All @@ -50,12 +50,12 @@ func (c *client) GenerateTextStream(ctx context.Context, specs []genai.Text) err
return nil
}

func (c *client) GenerateTextStreamWriter(ctx context.Context, specs []genai.Text, outputFolder string) error {
func (c *client) GenerateTextStreamWriter(ctx context.Context, specs []genai.Text, language, specType string, outputFolder string) error {
var prompts []genai.Part
for _, spec := range specs {
prompts = append(prompts, spec)
}
prompts = append(prompts, genai.Text("write golang testcases based on the above openapi spec."))
prompts = append(prompts, genai.Text(fmt.Sprintf("generate %s tests based for this %s spec.", language, specType)))

ct := time.Now().Format("2006-01-02-15-04-05")
files.CheckDirectryExists(outputFolder)
Expand Down
65 changes: 65 additions & 0 deletions pkg/engine/prompt/prompt.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@ package prompt

import (
"fmt"
"os"

"github.com/fatih/color"
"github.com/google/generative-ai-go/genai"
"github.com/manifoldco/promptui"
)

type specType string
Expand All @@ -13,6 +16,12 @@ const PROTOBUF specType = "protobuf"
const SWAGGER specType = "swagger"
const OAS3 specType = "OpenAPI 3"

type PromptContent struct {
ErrorMsg string
Label string
ItemType string
}

// CompareSpecFiles returns a prompt to compare two spec files
func CompareSpecFiles(file1, file2 genai.Part, specType specType) []genai.Part {
prompt := []genai.Part{
Expand All @@ -23,3 +32,59 @@ func CompareSpecFiles(file1, file2 genai.Part, specType specType) []genai.Part {

return prompt
}

func SelectLanguage(pc PromptContent) string {
var items []string
switch pc.ItemType {
case "language":
items = []string{"Go", "Python", "JavaScript", "java", "TypeScript"}
case "spec":
items = []string{"avro", "protobuf", "swagger", "OpenAPI3"}
default:
items = []string{}
fmt.Println("Invalid prompt type")
}
index := -1
var result string
var err error

for index < 0 {
prompt := promptui.SelectWithAdd{
Label: pc.Label,
Items: items,
AddLabel: "Other",
}

index, result, err = prompt.Run()

if index == -1 {
items = append(items, result)
}
}

if err != nil {
color.Red(pc.ErrorMsg)
os.Exit(1)
}

color.Green("Input: %s\n", result)

return result
}

func getFrameworksForLanguage(language string) []string {
switch language {
case "Go":
return []string{"Gin", "Echo", "Fiber", "gRPC"}
case "Python":
return []string{"Django", "Flask", "FastAPI", "gRPC"}
case "java":
return []string{"Spring", "JAX-RS", "restassured", "gRPC"}
case "JavaScript":
return []string{"supertest", "axios", "http", "gRPC"}
case "TypeScript":
return []string{"supertest", "axios", "http"}
default:
return []string{}
}
}

0 comments on commit 8e9fcee

Please sign in to comment.