-
Notifications
You must be signed in to change notification settings - Fork 12
/
ai_prompt_log_repository.go
64 lines (49 loc) · 1.68 KB
/
ai_prompt_log_repository.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package repository
import (
"github.com/openline-ai/openline-customer-os/packages/server/customer-os-postgres-repository/entity"
"github.com/sirupsen/logrus"
"gorm.io/gorm"
)
type AiPromptLogRepository interface {
Store(aiPrompt entity.AiPromptLog) (string, error)
UpdateResponse(id string, rawResponse string) error
UpdateError(id string, postProcessErrorMessage string) error
}
type aiPromptLogRepositoryImpl struct {
gormDb *gorm.DB
}
func NewAiPromptLogRepository(gormDb *gorm.DB) AiPromptLogRepository {
return &aiPromptLogRepositoryImpl{gormDb: gormDb}
}
func (repo *aiPromptLogRepositoryImpl) Store(aiPrompt entity.AiPromptLog) (string, error) {
err := repo.gormDb.Save(&aiPrompt).Error
if err != nil {
logrus.Errorf("Failed storing aiPromptResponse: %v", aiPrompt)
return "", err
}
return aiPrompt.ID, nil
}
func (repo *aiPromptLogRepositoryImpl) UpdateResponse(id string, rawResponse string) error {
err := repo.gormDb.Model(&entity.AiPromptLog{}).Where("id = ?", id).Update("raw_response", rawResponse).Error
if err != nil {
logrus.Errorf("Failed marking email as sent to event store: %v", id)
return err
}
return nil
}
func (repo *aiPromptLogRepositoryImpl) UpdateError(id string, postProcessErrorMessage string) error {
tx := repo.gormDb.Model(&entity.AiPromptLog{}).Where("id = ?", id)
if postProcessErrorMessage != "" {
tx.Update("post_process_error", true)
tx.Update("post_process_error_message", postProcessErrorMessage)
} else {
tx.Update("post_process_error", false)
tx.Update("post_process_error_message", nil)
}
err := tx.Error
if err != nil {
logrus.Errorf("Failed marking email as sent to event store: %v", id)
return err
}
return nil
}