-
Notifications
You must be signed in to change notification settings - Fork 0
/
modus_postgres.go
76 lines (65 loc) · 1.54 KB
/
modus_postgres.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
65
66
67
68
69
70
71
72
73
74
75
76
package main
import (
"fmt"
"time"
"github.com/hypermodeinc/modus/sdk/go/pkg/postgresql"
)
const connection = "convdb"
type DebateExchange struct {
PartitionKey string `json:"debate_id"`
MessageId int `json:"message_id"`
Speaker string `json:"speaker"`
Message string `json:"message"`
Timestamp time.Time `json:"timestamp"`
}
func StoreExchange(debateID string, exchange DebateExchange) error {
const query = `
INSERT INTO debate_messages (debate_id, speaker, message, timestamp)
VALUES ($1, $2, $3, $4)
`
_, err := postgresql.Execute(
connection,
query,
debateID,
exchange.Speaker,
exchange.Message,
exchange.Timestamp,
)
if err != nil {
return fmt.Errorf("failed to store exchange: %w", err)
}
return nil
}
func GetDebateHistory(debateID string) ([]DebateExchange) {
const query = `
SELECT debate_id, message_id, speaker, message, timestamp
FROM debate_messages
WHERE debate_id = $1
ORDER BY timestamp
`
rows, _, err := postgresql.Query[DebateExchange](connection, query, debateID)
if err != nil {
return rows
}
return rows
}
func RegisterDebate(debateID, model1, model2, persona1, persona2, debateTopic string) error {
const query = `
INSERT INTO debates (debate_id, model1, model2, persona1, persona2, topic)
VALUES ($1, $2, $3, $4, $5, $6)
`
_, err := postgresql.Execute(
connection,
query,
debateID,
model1,
model2,
persona1,
persona2,
debateTopic,
)
if err != nil {
return fmt.Errorf("failed to register debate: %w", err)
}
return nil
}