this repo has no description

add off topic, funny, and check quotes

Changed files
+69 -22
labeler
+29 -14
handle_post.go
··· 2 2 3 3 import ( 4 4 "context" 5 - "errors" 6 5 "fmt" 7 6 "time" 8 7 ··· 16 15 return nil 17 16 } 18 17 19 - if post.Reply == nil { 20 - return nil 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 21 26 } 22 27 23 - if post.Reply.Parent == nil { 24 - return errors.New("badly formatted reply ref (no parent)") 28 + if parentUri == "" { 29 + return nil 25 30 } 26 31 27 - atUri, err := syntax.ParseATURI(post.Reply.Parent.Uri) 32 + atUri, err := syntax.ParseATURI(parentUri) 28 33 if err != nil { 29 34 return fmt.Errorf("failed to parse parent aturi: %w", err) 30 35 } ··· 46 51 return nil 47 52 } 48 53 49 - parent, err := dsmt.getPost(ctx, post.Reply.Parent.Uri) 54 + parent, err := dsmt.getPost(ctx, parentUri) 50 55 if err != nil { 51 56 return fmt.Errorf("failed to get parent post: %w", err) 52 57 } ··· 54 59 ctx, cancel := context.WithTimeout(ctx, 30*time.Second) 55 60 defer cancel() 56 61 57 - isBadFaith, err := dsmt.lmstudioc.GetIsBadFaith(ctx, parent.Text, post.Text) 62 + results, err := dsmt.lmstudioc.GetIsBadFaith(ctx, parent.Text, post.Text) 58 63 if err != nil { 59 64 return fmt.Errorf("failed to check bad faith: %w", err) 60 65 } 61 66 62 - if !isBadFaith { 63 - logger.Info("determined that reply was not bad faith") 64 - return nil 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") 65 72 } 66 73 67 - if err := dsmt.emitLabel(ctx, uri, LabelBadFaith); err != nil { 68 - return fmt.Errorf("failed to label post: %w", err) 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") 69 79 } 70 80 71 - logger.Info("determined that reply was bad faith and emitted label") 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 + } 72 87 73 88 return nil 74 89 }
+2
labeler/index.ts
··· 4 4 5 5 const LABELS: Record<string, boolean> = { 6 6 'bad-faith': true, 7 + 'off-topic': true, 8 + funny: true, 7 9 } 8 10 9 11 function run() {
+36 -8
lmstudio.go
··· 75 75 Type: "boolean", 76 76 Description: "Whether the reply to the parent is bad faith or not.", 77 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 + }, 78 86 }, 79 - Required: []string{"bad_faith"}, 87 + Required: []string{"bad_faith", "off_topic", "funny"}, 80 88 } 81 89 ) 82 90 ··· 124 132 return &chatResp, nil 125 133 } 126 134 127 - func (c *LMStudioClient) GetIsBadFaith(ctx context.Context, parent, reply string) (bool, error) { 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) { 128 142 request := ChatRequest{ 129 143 Model: "google/gemma-3-27b", 130 144 Messages: []Message{ 131 145 { 132 146 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.", 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.", 134 148 }, 135 149 { 136 150 Role: "user", ··· 142 156 }, 143 157 }, 144 158 Temperature: 0.7, 145 - MaxTokens: 50, 159 + MaxTokens: 100, 146 160 ResponseFormat: &ResponseFormat{ 147 161 Type: "json_schema", 148 162 JSONSchema: &JSONSchemaWrap{ ··· 154 168 } 155 169 response, err := c.sendChatRequest(request) 156 170 if err != nil { 157 - return false, fmt.Errorf("failed to get chat response: %w", err) 171 + return nil, fmt.Errorf("failed to get chat response: %w", err) 158 172 } 159 173 160 174 var result map[string]any 161 175 if err := json.Unmarshal([]byte(response.Choices[0].Message.Content), &result); err != nil { 162 - return false, fmt.Errorf("failed to unmarshal response: %w", err) 176 + return nil, fmt.Errorf("failed to unmarshal response: %w", err) 163 177 } 164 178 165 179 badFaith, ok := result["bad_faith"].(bool) 166 180 if !ok { 167 - return false, fmt.Errorf("model gave bad response, not structured") 181 + return nil, fmt.Errorf("model gave bad response (bad faith), not structured") 168 182 } 169 183 170 - return badFaith, nil 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 171 199 }
+2
main.go
··· 25 25 26 26 const ( 27 27 LabelBadFaith = "bad-faith" 28 + LabelOffTopic = "off-topic" 29 + LabelFunny = "funny" 28 30 ) 29 31 30 32 func main() {