From e5c7315e8a066beb26214b21740284c0535036fd Mon Sep 17 00:00:00 2001 From: Karl Cardenas Date: Wed, 13 Dec 2023 17:03:36 -0700 Subject: [PATCH] fix: added confidence level attribute to answers (#19) * fix: added confidence level attribute to answers * chore: removed dubug statement * chore: updated deployment version * chore: fixed version in cluster profile --- Dockerfile | 2 +- deployment/k8s-generic/spectromate.yaml | 2 +- deployment/terraform/inputs.tf | 4 ++-- internal/mendable.go | 1 + internal/types.go | 17 ++++++++++------- slackCmds/ask.go | 16 ++++++++++++++-- 6 files changed, 29 insertions(+), 13 deletions(-) diff --git a/Dockerfile b/Dockerfile index e11f1b6..56803d8 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,7 @@ # Copyright (c) Spectro Cloud # SPDX-License-Identifier: Apache-2.0 -FROM golang:1.21.3-alpine3.18 as builder +FROM golang:1.21.5-alpine3.18 as builder ARG VERSION diff --git a/deployment/k8s-generic/spectromate.yaml b/deployment/k8s-generic/spectromate.yaml index b02b90f..7c39c4c 100644 --- a/deployment/k8s-generic/spectromate.yaml +++ b/deployment/k8s-generic/spectromate.yaml @@ -101,7 +101,7 @@ spec: spec: containers: - name: slackbot - image: ghcr.io/spectrocloud/spectromate:v1.0.2 + image: ghcr.io/spectrocloud/spectromate:v1.0.6 ports: - containerPort: 3000 name: slackbot diff --git a/deployment/terraform/inputs.tf b/deployment/terraform/inputs.tf index 4f539dd..8649ef4 100644 --- a/deployment/terraform/inputs.tf +++ b/deployment/terraform/inputs.tf @@ -10,7 +10,7 @@ variable "project" { variable "app_version" { type = string description = "The version of the Spectromate application profile in Palette." - default = "1.0.5" + default = "1.0.6" } variable "cluster-group-name" { @@ -34,7 +34,7 @@ variable "mendable_api_key" { variable "image" { type = string description = "The Spectromate image to deploy." - default = "ghcr.io/spectrocloud/spectromate:v1.0.5" + default = "ghcr.io/spectrocloud/spectromate:v1.0.6" } variable "cluster_name" { diff --git a/internal/mendable.go b/internal/mendable.go index 019a330..1b21b61 100644 --- a/internal/mendable.go +++ b/internal/mendable.go @@ -170,6 +170,7 @@ func SendDocsQuery(ctx context.Context, query MendableRequestPayload, queryURL, Question: query.Question, Answer: result.Answer.Text, Links: uniqueLinks, + Confidence: fmt.Sprintf("%.2f", result.Confidence), } if mendableResponse.Answer == "" { diff --git a/internal/types.go b/internal/types.go index 62ae55e..f8c79bd 100644 --- a/internal/types.go +++ b/internal/types.go @@ -40,16 +40,18 @@ type MendablePayload struct { Answer struct { Text string `json:"text"` } `json:"answer"` - MessageID int `json:"message_id"` - Sources []MendableSources `json:"sources"` + MessageID int `json:"message_id"` + Sources []MendableSources `json:"sources"` + Confidence float64 `json:"confidence_score"` } type MendableSources struct { - ID int `json:"id"` - Content string `json:"content"` - Score float64 `json:"score"` - Date *string `json:"date"` - Link string `json:"link"` + ID int `json:"id"` + Content string `json:"content"` + Score float64 `json:"score"` + Date *string `json:"date"` + Link string `json:"link"` + RelevancyScore float64 `json:"relevance_score"` } type MendableQueryResponse struct { @@ -58,6 +60,7 @@ type MendableQueryResponse struct { Question string Answer string Links []string + Confidence string } /* diff --git a/slackCmds/ask.go b/slackCmds/ask.go index fbffaf9..33c2cac 100644 --- a/slackCmds/ask.go +++ b/slackCmds/ask.go @@ -157,7 +157,7 @@ func AskCmd(s *SlackAskRequest, isPrivate bool) { q := fmt.Sprintf(`:question: %v`, mendableResponse.Question) - slackReplyPayload, err := askMarkdownPayload(markdownContent, q, linksString, "Docs Answer", mendableResponse.MessageID, isPrivate) + slackReplyPayload, err := askMarkdownPayload(markdownContent, q, linksString, "Docs Answer", mendableResponse.MessageID, isPrivate, mendableResponse.Confidence) if err != nil { log.Info().Err(err).Msg("Error creating markdown payload.") globalErr = &err @@ -174,7 +174,7 @@ func AskCmd(s *SlackAskRequest, isPrivate bool) { } // // createMarkdownPayload creates a Slack payload with a markdown block -func askMarkdownPayload(content, question, links, title, messageId string, isPrivate bool) ([]byte, error) { +func askMarkdownPayload(content, question, links, title, messageId string, isPrivate bool, confidence string) ([]byte, error) { log.Debug().Msgf("Incoming Message: %v", content) var responseType string @@ -227,6 +227,18 @@ func askMarkdownPayload(content, question, links, title, messageId string, isPri { Type: "divider", }, + { + Type: "section", + Fields: []internal.SlackTextObject{ + { + Type: "mrkdwn", + Text: "*Answer Confidence Level:* " + confidence + "%", + }, + }, + }, + { + Type: "divider", + }, { Type: "section", Fields: []internal.SlackTextObject{