diff --git a/general/ai/cli.go b/general/ai/cli.go index 0898563e5..e2bfb9a37 100644 --- a/general/ai/cli.go +++ b/general/ai/cli.go @@ -3,6 +3,7 @@ package ai import ( "bufio" "bytes" + "encoding/json" "errors" "fmt" "github.com/jfrog/jfrog-cli-core/v2/utils/coreutils" @@ -29,13 +30,6 @@ type QuestionBody struct { Question string `json:"question"` } -type FeedbackBody struct { - QuestionBody - LlmAnswer string `json:"llm_answer"` - IsAccurate bool `json:"is_accurate"` - ExpectedAnswer string `json:"expected_answer"` -} - func HowCmd(c *cli.Context) error { if show, err := cliutils.ShowCmdHelpIfNeeded(c, c.Args()); show || err != nil { return err @@ -70,15 +64,19 @@ func HowCmd(c *cli.Context) error { } func askQuestion(question string) (response string, err error) { + contentBytes, err := json.Marshal(QuestionBody{Question: question}) + if errorutils.CheckError(err) != nil { + return + } client, err := httpclient.ClientBuilder().Build() if errorutils.CheckError(err) != nil { return } - req, err := http.NewRequest(http.MethodPost, cliAiAskApiPath, bytes.NewBufferString(question)) + req, err := http.NewRequest(http.MethodPost, cliAiAskApiPath, bytes.NewBuffer(contentBytes)) if errorutils.CheckError(err) != nil { return } - req.Header.Set("Content-Type", "text/plain") + req.Header.Set("Content-Type", "application/json") req.Header.Set(apiHeader, "true") log.Debug(fmt.Sprintf("Sending HTTP %s request to: %s", req.Method, req.URL)) resp, err := client.GetClient().Do(req)