-
Notifications
You must be signed in to change notification settings - Fork 0
/
ai_api_logs.go
47 lines (40 loc) · 1.11 KB
/
ai_api_logs.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
package store
import (
"context"
sq "github.com/Masterminds/squirrel"
"github.com/l-orlov/slim-fairy/bot/internal/model"
)
// CreateAIAPILog creates model.AIAPILogs
func (s *Storage) CreateAIAPILog(ctx context.Context, record *model.AIAPILog) error {
query := psql().
Insert(record.DbTable()).
SetMap(aiAPILogAttrs(record)).
Suffix("RETURNING " + asteriskAIAPILogs)
err := Getx(ctx, s.pool, record, query)
if err != nil {
return dbError(err)
}
return nil
}
// UpdateAIAPILog updates model.AIAPILog
func (s *Storage) UpdateAIAPILog(ctx context.Context, record *model.AIAPILog) error {
query := psql().
Update(record.DbTable()).
Where(sq.Eq{"id": record.ID}).
SetMap(aiAPILogAttrs(record)).
Suffix("RETURNING " + asteriskChatBotDialogs)
err := Getx(ctx, s.pool, record, query)
if err != nil {
return dbError(err)
}
return nil
}
func aiAPILogAttrs(record *model.AIAPILog) map[string]interface{} {
return map[string]interface{}{
"prompt": record.Prompt,
"response": record.Response,
"user_id": record.UserID,
"source_id": record.SourceID,
"source_type": record.SourceType,
}
}