+29
-14
handle_post.go
+29
-14
handle_post.go
···
2
3
import (
4
"context"
5
-
"errors"
6
"fmt"
7
"time"
8
···
16
return nil
17
}
18
19
-
if post.Reply == nil {
20
-
return nil
21
}
22
23
-
if post.Reply.Parent == nil {
24
-
return errors.New("badly formatted reply ref (no parent)")
25
}
26
27
-
atUri, err := syntax.ParseATURI(post.Reply.Parent.Uri)
28
if err != nil {
29
return fmt.Errorf("failed to parse parent aturi: %w", err)
30
}
···
46
return nil
47
}
48
49
-
parent, err := dsmt.getPost(ctx, post.Reply.Parent.Uri)
50
if err != nil {
51
return fmt.Errorf("failed to get parent post: %w", err)
52
}
···
54
ctx, cancel := context.WithTimeout(ctx, 30*time.Second)
55
defer cancel()
56
57
-
isBadFaith, err := dsmt.lmstudioc.GetIsBadFaith(ctx, parent.Text, post.Text)
58
if err != nil {
59
return fmt.Errorf("failed to check bad faith: %w", err)
60
}
61
62
-
if !isBadFaith {
63
-
logger.Info("determined that reply was not bad faith")
64
-
return nil
65
}
66
67
-
if err := dsmt.emitLabel(ctx, uri, LabelBadFaith); err != nil {
68
-
return fmt.Errorf("failed to label post: %w", err)
69
}
70
71
-
logger.Info("determined that reply was bad faith and emitted label")
72
73
return nil
74
}
···
2
3
import (
4
"context"
5
"fmt"
6
"time"
7
···
15
return nil
16
}
17
18
+
var parentUri string
19
+
20
+
if post.Reply != nil && post.Reply.Parent != nil {
21
+
parentUri = post.Reply.Parent.Uri
22
+
} else if post.Embed != nil && post.Embed.EmbedRecord != nil && post.Embed.EmbedRecord.Record != nil {
23
+
parentUri = post.Embed.EmbedRecord.Record.Uri
24
+
} else if post.Embed != nil && post.Embed.EmbedRecordWithMedia != nil && post.Embed.EmbedRecordWithMedia.Record != nil && post.Embed.EmbedRecordWithMedia.Record.Record != nil {
25
+
parentUri = post.Embed.EmbedRecordWithMedia.Record.Record.Uri
26
}
27
28
+
if parentUri == "" {
29
+
return nil
30
}
31
32
+
atUri, err := syntax.ParseATURI(parentUri)
33
if err != nil {
34
return fmt.Errorf("failed to parse parent aturi: %w", err)
35
}
···
51
return nil
52
}
53
54
+
parent, err := dsmt.getPost(ctx, parentUri)
55
if err != nil {
56
return fmt.Errorf("failed to get parent post: %w", err)
57
}
···
59
ctx, cancel := context.WithTimeout(ctx, 30*time.Second)
60
defer cancel()
61
62
+
results, err := dsmt.lmstudioc.GetIsBadFaith(ctx, parent.Text, post.Text)
63
if err != nil {
64
return fmt.Errorf("failed to check bad faith: %w", err)
65
}
66
67
+
if results.BadFaith {
68
+
if err := dsmt.emitLabel(ctx, uri, LabelBadFaith); err != nil {
69
+
return fmt.Errorf("failed to label post: %w", err)
70
+
}
71
+
logger.Info("determined that reply was bad faith and emitted label")
72
}
73
74
+
if results.OffTopic {
75
+
if err := dsmt.emitLabel(ctx, uri, LabelOffTopic); err != nil {
76
+
return fmt.Errorf("failed to label post: %w", err)
77
+
}
78
+
logger.Info("determined that reply was off topic and emitted label")
79
}
80
81
+
if results.Funny {
82
+
if err := dsmt.emitLabel(ctx, uri, LabelFunny); err != nil {
83
+
return fmt.Errorf("failed to label post: %w", err)
84
+
}
85
+
logger.Info("determined that reply was funny and emitted label")
86
+
}
87
88
return nil
89
}
+2
labeler/index.ts
+2
labeler/index.ts
+36
-8
lmstudio.go
+36
-8
lmstudio.go
···
75
Type: "boolean",
76
Description: "Whether the reply to the parent is bad faith or not.",
77
},
78
},
79
-
Required: []string{"bad_faith"},
80
}
81
)
82
···
124
return &chatResp, nil
125
}
126
127
-
func (c *LMStudioClient) GetIsBadFaith(ctx context.Context, parent, reply string) (bool, error) {
128
request := ChatRequest{
129
Model: "google/gemma-3-27b",
130
Messages: []Message{
131
{
132
Role: "system",
133
-
Content: "You are an observer of posts on a microblogging website. You determine if the second message provided by the user is a bad faith reply to the second message provided to you. Opposing viewpoints are good, and should be appreciated. However, things that are toxic, trollish, or offer no good value to the conversation are considered bad faith.",
134
},
135
{
136
Role: "user",
···
142
},
143
},
144
Temperature: 0.7,
145
-
MaxTokens: 50,
146
ResponseFormat: &ResponseFormat{
147
Type: "json_schema",
148
JSONSchema: &JSONSchemaWrap{
···
154
}
155
response, err := c.sendChatRequest(request)
156
if err != nil {
157
-
return false, fmt.Errorf("failed to get chat response: %w", err)
158
}
159
160
var result map[string]any
161
if err := json.Unmarshal([]byte(response.Choices[0].Message.Content), &result); err != nil {
162
-
return false, fmt.Errorf("failed to unmarshal response: %w", err)
163
}
164
165
badFaith, ok := result["bad_faith"].(bool)
166
if !ok {
167
-
return false, fmt.Errorf("model gave bad response, not structured")
168
}
169
170
-
return badFaith, nil
171
}
···
75
Type: "boolean",
76
Description: "Whether the reply to the parent is bad faith or not.",
77
},
78
+
"off_topic": {
79
+
Type: "boolean",
80
+
Description: "Whether the reply to the parent is off topic.",
81
+
},
82
+
"funny": {
83
+
Type: "boolean",
84
+
Description: "Whether the reply to the parent is funny.",
85
+
},
86
},
87
+
Required: []string{"bad_faith", "off_topic", "funny"},
88
}
89
)
90
···
132
return &chatResp, nil
133
}
134
135
+
type BadFaithResults struct {
136
+
BadFaith bool
137
+
OffTopic bool
138
+
Funny bool
139
+
}
140
+
141
+
func (c *LMStudioClient) GetIsBadFaith(ctx context.Context, parent, reply string) (*BadFaithResults, error) {
142
request := ChatRequest{
143
Model: "google/gemma-3-27b",
144
Messages: []Message{
145
{
146
Role: "system",
147
+
Content: "You are an observer of posts on a microblogging website. You determine if the second message provided by the user is a bad faith reply, and off topic reply, and/or a funny reply to the second message provided to you. Opposing viewpoints are good, and should be appreciated. However, things that are toxic, trollish, or offer no good value to the conversation are considered bad faith. Just because something is bad faith or off topic does not mean the post cannot also be funny.",
148
},
149
{
150
Role: "user",
···
156
},
157
},
158
Temperature: 0.7,
159
+
MaxTokens: 100,
160
ResponseFormat: &ResponseFormat{
161
Type: "json_schema",
162
JSONSchema: &JSONSchemaWrap{
···
168
}
169
response, err := c.sendChatRequest(request)
170
if err != nil {
171
+
return nil, fmt.Errorf("failed to get chat response: %w", err)
172
}
173
174
var result map[string]any
175
if err := json.Unmarshal([]byte(response.Choices[0].Message.Content), &result); err != nil {
176
+
return nil, fmt.Errorf("failed to unmarshal response: %w", err)
177
}
178
179
badFaith, ok := result["bad_faith"].(bool)
180
if !ok {
181
+
return nil, fmt.Errorf("model gave bad response (bad faith), not structured")
182
}
183
184
+
offTopic, ok := result["off_topic"].(bool)
185
+
if !ok {
186
+
return nil, fmt.Errorf("model gave bad response (off topic), not structured")
187
+
}
188
+
189
+
funny, ok := result["funny"].(bool)
190
+
if !ok {
191
+
return nil, fmt.Errorf("model gave bad response (funny), not structured")
192
+
}
193
+
194
+
return &BadFaithResults{
195
+
BadFaith: badFaith,
196
+
OffTopic: offTopic,
197
+
Funny: funny,
198
+
}, nil
199
}