Skip to content
This repository has been archived by the owner on Jun 22, 2024. It is now read-only.

Commit

Permalink
fix: added confidence level attribute to answers (#19)
Browse files Browse the repository at this point in the history
* fix: added confidence level attribute to answers

* chore: removed dubug statement

* chore: updated deployment version

* chore: fixed version in cluster profile
  • Loading branch information
karl-cardenas-coding authored Dec 14, 2023
1 parent a66cead commit e5c7315
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 13 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -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

Expand Down
2 changes: 1 addition & 1 deletion deployment/k8s-generic/spectromate.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions deployment/terraform/inputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand All @@ -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" {
Expand Down
1 change: 1 addition & 0 deletions internal/mendable.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 == "" {
Expand Down
17 changes: 10 additions & 7 deletions internal/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -58,6 +60,7 @@ type MendableQueryResponse struct {
Question string
Answer string
Links []string
Confidence string
}

/*
Expand Down
16 changes: 14 additions & 2 deletions slackCmds/ask.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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{
Expand Down

0 comments on commit e5c7315

Please sign in to comment.