Skip to content

Commit

Permalink
Improve AI assistant feedback (#2711)
Browse files Browse the repository at this point in the history
  • Loading branch information
sverdlov93 authored Oct 6, 2024
1 parent 15d405d commit 3c61cc4
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 12 deletions.
23 changes: 16 additions & 7 deletions general/ai/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,15 @@ func HowCmd(c *cli.Context) error {
}
log.Output(coreutils.PrintLink("This AI-powered interface converts natural language inputs into AI-generated JFrog CLI commands.\n" +
"For more information about this interface, see https://docs.jfrog-applications.jfrog.io/jfrog-applications/jfrog-cli/cli-ai\n" +
"NOTE: This is an experimental version and it supports mostly Artifactory and Xray commands.\n"))
"Note: JFrog AI Assistant is in beta and currently supports primarily Artifactory and Xray commands.\n"))

// Ask the user to agree to the terms and conditions. If the user does not agree, the command will not proceed.
// Ask this only once per JFrog CLI installation, unless the terms are updated.
if agreed, err := handleAiTermsAgreement(); err != nil || !agreed {
if agreed, err := handleAiTermsAgreement(); err != nil {
return err
} else if !agreed {
// If the user does not agree to the terms, the command will not proceed.
return reportTermsDisagreement()
}

for {
Expand Down Expand Up @@ -82,7 +85,7 @@ func HowCmd(c *cli.Context) error {
// If the response is a valid JFrog CLI command, ask the user for feedback.
if validResponse {
log.Output()
if err = sendFeedback(); err != nil {
if err = handleResponseFeedback(); err != nil {
return err
}
}
Expand All @@ -100,16 +103,22 @@ func askQuestion(question string) (response string, err error) {
}

type feedbackBody struct {
IsGoodResponse bool `json:"is_good_response"`
IsGoodResponse bool `json:"is_good_response,omitempty"`
IsAgreedTerms bool `json:"is_agreed_terms,omitempty"`
}

func sendFeedback() (err error) {
func handleResponseFeedback() (err error) {
isGoodResponse, err := getUserFeedback()
if err != nil {
return err
return
}
_, err = sendRestAPI(feedback, feedbackBody{IsGoodResponse: isGoodResponse})
return err
return
}

func reportTermsDisagreement() (err error) {
_, err = sendRestAPI(feedback, feedbackBody{IsAgreedTerms: false})
return
}

func getUserFeedback() (bool, error) {
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ replace (
)

require (
github.com/agnivade/levenshtein v1.1.1
github.com/agnivade/levenshtein v1.2.0
github.com/buger/jsonparser v1.1.1
github.com/docker/docker v27.3.1+incompatible
github.com/gocarina/gocsv v0.0.0-20240520201108-78e41c74b4b1
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -621,8 +621,8 @@ github.com/VividCortex/ewma v1.2.0 h1:f58SaIzcDXrSy3kWaHNvuJgJ3Nmz59Zji6XoJR/q1o
github.com/VividCortex/ewma v1.2.0/go.mod h1:nz4BbCtbLyFDeC9SUHbtcT5644juEuWfUAUnGx7j5l4=
github.com/acarl005/stripansi v0.0.0-20180116102854-5a71ef0e047d h1:licZJFw2RwpHMqeKTCYkitsPqHNxTmd4SNR5r94FGM8=
github.com/acarl005/stripansi v0.0.0-20180116102854-5a71ef0e047d/go.mod h1:asat636LX7Bqt5lYEZ27JNDcqxfjdBQuJ/MM4CN/Lzo=
github.com/agnivade/levenshtein v1.1.1 h1:QY8M92nrzkmr798gCo3kmMyqXFzdQVpxLlGPRBij0P8=
github.com/agnivade/levenshtein v1.1.1/go.mod h1:veldBMzWxcCG2ZvUTKD2kJNRdCk5hVbJomOvKkmgYbo=
github.com/agnivade/levenshtein v1.2.0 h1:U9L4IOT0Y3i0TIlUIDJ7rVUziKi/zPbrJGaFrtYH3SY=
github.com/agnivade/levenshtein v1.2.0/go.mod h1:QVVI16kDrtSuwcpd0p1+xMC6Z/VfhtCyDIjcwga4/DU=
github.com/ajstarks/deck v0.0.0-20200831202436-30c9fc6549a9/go.mod h1:JynElWSGnm/4RlzPXRlREEwqTHAN3T56Bv2ITsFT3gY=
github.com/ajstarks/deck/generate v0.0.0-20210309230005-c3f852c02e19/go.mod h1:T13YZdzov6OU0A1+RfKZiZN9ca6VeKdBdyDV+BY97Tk=
github.com/ajstarks/svgo v0.0.0-20180226025133-644b8db467af/go.mod h1:K08gAheRH3/J6wwsYMMT4xOr94bZjxIelGM0+d/wbFw=
Expand Down Expand Up @@ -703,8 +703,8 @@ github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM=
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/dgryski/trifles v0.0.0-20200323201526-dd97f9abfb48 h1:fRzb/w+pyskVMQ+UbP35JkH8yB7MYb4q/qhBarqZE6g=
github.com/dgryski/trifles v0.0.0-20200323201526-dd97f9abfb48/go.mod h1:if7Fbed8SFyPtHLHbg49SI7NAdJiC5WIA09pe59rfAA=
github.com/dgryski/trifles v0.0.0-20230903005119-f50d829f2e54 h1:SG7nF6SRlWhcT7cNTs5R6Hk4V2lcmLz2NsG2VnInyNo=
github.com/dgryski/trifles v0.0.0-20230903005119-f50d829f2e54/go.mod h1:if7Fbed8SFyPtHLHbg49SI7NAdJiC5WIA09pe59rfAA=
github.com/distribution/reference v0.6.0 h1:0IXCQ5g4/QMHHkarYzh5l+u8T3t73zM5QvfrDyIgxBk=
github.com/distribution/reference v0.6.0/go.mod h1:BbU0aIcezP1/5jX/8MP0YiH4SdvB5Y4f/wlDRiLyi3E=
github.com/docker/docker v27.3.1+incompatible h1:KttF0XoteNTicmUtBO0L2tP+J7FGRFTjaEF4k6WdhfI=
Expand Down

0 comments on commit 3c61cc4

Please sign in to comment.