Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: fix bug that clears original message status while sending suggession hit of AI message #944

Merged
merged 1 commit into from
Aug 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion controllers/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ func (c *ApiController) GetMessage() {
// @router /update-message [post]
func (c *ApiController) UpdateMessage() {
id := c.Input().Get("id")
isHitOnly := c.Input().Get("isHitOnly")

var message object.Message
err := json.Unmarshal(c.Ctx.Input.RequestBody, &message)
Expand All @@ -155,7 +156,7 @@ func (c *ApiController) UpdateMessage() {
message.NeedNotify = false
}

success, err := object.UpdateMessage(id, &message)
success, err := object.UpdateMessage(id, &message, isHitOnly == "true")
if err != nil {
c.ResponseError(err.Error())
return
Expand Down
4 changes: 2 additions & 2 deletions controllers/message_answer.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ func (c *ApiController) GetMessageAnswer() {
questionMessage.Price = embeddingResult.Price
questionMessage.Currency = embeddingResult.Currency

_, err = object.UpdateMessage(questionMessage.GetId(), questionMessage)
_, err = object.UpdateMessage(questionMessage.GetId(), questionMessage, false)
if err != nil {
c.ResponseErrorStream(message, err.Error())
return
Expand Down Expand Up @@ -248,7 +248,7 @@ func (c *ApiController) GetMessageAnswer() {

message.ModelProvider = modelProvider
message.VectorScores = vectorScores
_, err = object.UpdateMessage(message.GetId(), message)
_, err = object.UpdateMessage(message.GetId(), message, false)
if err != nil {
c.ResponseErrorStream(message, err.Error())
return
Expand Down
2 changes: 1 addition & 1 deletion controllers/message_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func (c *ApiController) ResponseErrorStream(message *object.Message, errorText s
if message.ErrorText != errorText || !message.IsAlerted || err != nil {
message.ErrorText = errorText
message.IsAlerted = true
_, err = object.UpdateMessage(message.GetId(), message)
_, err = object.UpdateMessage(message.GetId(), message, false)
if err != nil {
errorText = fmt.Sprintf("%s\n%s", errorText, err.Error())
}
Expand Down
8 changes: 6 additions & 2 deletions object/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ func GetMessage(id string) (*Message, error) {
return getMessage(owner, name)
}

func UpdateMessage(id string, message *Message) (bool, error) {
func UpdateMessage(id string, message *Message, isHitOnly bool) (bool, error) {
owner, name := util.GetOwnerAndNameFromId(id)
originMessage, err := getMessage(owner, name)
if err != nil {
Expand All @@ -165,7 +165,11 @@ func UpdateMessage(id string, message *Message) (bool, error) {
message.TextTokenCount = size
}

_, err = adapter.engine.ID(core.PK{owner, name}).AllCols().Update(message)
if isHitOnly {
_, err = adapter.engine.ID(core.PK{owner, name}).Cols("suggestions").Update(message)
} else {
_, err = adapter.engine.ID(core.PK{owner, name}).AllCols().Update(message)
}
if err != nil {
return false, err
}
Expand Down
2 changes: 1 addition & 1 deletion web/src/ChatBox.js
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ class ChatBox extends React.Component {
}} onClick={() => {
this.props.sendMessage(suggestionText, "");
message.suggestions[index].isHit = true;
updateMessage(message.owner, message.name, message);
updateMessage(message.owner, message.name, message, true);
}}
>{suggestionText}</Button>
);
Expand Down
4 changes: 2 additions & 2 deletions web/src/backend/MessageBackend.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,9 @@ export function getMessage(owner, name) {
}).then(res => res.json());
}

export function updateMessage(owner, name, message) {
export function updateMessage(owner, name, message, isHitOnly = false) {
const newMessage = Setting.deepCopy(message);
return fetch(`${Setting.ServerUrl}/api/update-message?id=${owner}/${encodeURIComponent(name)}`, {
return fetch(`${Setting.ServerUrl}/api/update-message?id=${owner}/${encodeURIComponent(name)}&isHitOnly=${isHitOnly}`, {
method: "POST",
credentials: "include",
headers: {
Expand Down
Loading