Skip to content

Commit afb8ba5

Browse files
committed
fix(server): Improve prompt
1 parent d60c0aa commit afb8ba5

File tree

3 files changed

+31
-29
lines changed

3 files changed

+31
-29
lines changed

bun.lock

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
"resend": "^4.0.0",
3838
"sharp": "^0.33.5",
3939
"tiny-invariant": "^1.3.3",
40+
"zod": "^3.24.2",
4041
},
4142
"devDependencies": {
4243
"@types/bun": "^1.1.16",
@@ -1874,6 +1875,8 @@
18741875

18751876
"zhead": ["[email protected]", "", {}, "sha512-8F0OI5dpWIA5IGG5NHUg9staDwz/ZPxZtvGVf01j7vHqSyZ0raHY+78atOVxRqb73AotX22uV1pXt3gYSstGag=="],
18761877

1878+
"zod": ["[email protected]", "", {}, "sha512-lY7CDW43ECgW9u1TcT3IoXHflywfVqDYze4waEz812jR/bZ8FHDsl7pFQoSZTz5N+2NqRXs8GBwnAwo3ZNxqhQ=="],
1879+
18771880
"zwitch": ["[email protected]", "", {}, "sha512-bXE4cR/kVZhKZX/RjPEflHaKVhUVl85noU3v6b8apfQEc1x4A+zBxjZ4lN8LqGd6WZ3dl98pY4o717VFmoPp+A=="],
18781881

18791882
"@aws-crypto/sha256-browser/@smithy/util-utf8": ["@smithy/[email protected]", "", { "dependencies": { "@smithy/util-buffer-from": "^2.2.0", "tslib": "^2.6.2" } }, "sha512-R8Rdn8Hy72KKcebgLiv8jQcQkXoLMOGGv5uI1/k0l+snqkOzQ1R0ChUBCxWMlBsFMekWjq0wRudIweFs7sKT5A=="],

server/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@
4747
"postgres": "^3.4.4",
4848
"resend": "^4.0.0",
4949
"sharp": "^0.33.5",
50-
"tiny-invariant": "^1.3.3"
50+
"tiny-invariant": "^1.3.3",
51+
"zod": "^3.24.2"
5152
},
5253
"devDependencies": {
5354
"@types/bun": "^1.1.16",

server/src/methods/createLinearIssue.ts

Lines changed: 26 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { eq } from "drizzle-orm"
33
import OpenAI from "openai"
44
import { spaces, users } from "../db/schema"
55
import { db } from "../db"
6+
import { z } from "zod"
67
import {
78
createIssue,
89
generateIssueLink,
@@ -15,6 +16,7 @@ import {
1516
} from "@in/server/libs/linear"
1617
import { openaiClient } from "../libs/openAI"
1718
import { Log } from "../utils/log"
19+
import { zodResponseFormat } from "openai/helpers/zod.mjs"
1820

1921
type Context = {
2022
currentUserId: number
@@ -41,32 +43,29 @@ export const handler = async (
4143
const linearUsers = await getLinearUsers({ userId: currentUserId })
4244

4345
const message = `
44-
You are an expert linguist creating accurate task titles from messages in any language. Follow these steps:
46+
You are a product manager creating tasks for engineers, designers, and other startup roles from messages in their Slack messages. Follow these steps:
4547
4648
1. INPUT MESSAGE: "${text}"
4749
4850
2. TITLE CREATION RULES:
49-
a. Make sure to start with an everyday action verb (e.g., "Fix", "Update", "Add", "Remove")
50-
b. Use sentence case (First word capitalized)
51-
c. Include specific issue reproduction steps or feature context
52-
d. Maintain key information density from original message
53-
e. PROHIBITED: AI jargon ("optimize", "leverage", "streamline", "capability")
54-
f. IGNORE time annotations: "-2h", "(2h)", etc.
55-
g.Be careful to not count everything as issue.
56-
t. Make sure you do not add any of these words in sentences : "feature" or "functionality" but you can count them as label. eg. this is wrong: Add SMS sign in **feature**
57-
s. Make sure you are not returning the sentence with it's own verb without making it task title and adding the action verb in the beginning of the title eg.
58-
Message: edit message
59-
title should be "Add edit message" no "Edit message"
51+
a. Use common task title verbs like "Fix", "Update", "Add", "Remove"
52+
b. Use sentence case
53+
c. Keep it concise and to the point explaining the task/feature/fix mentioned in the message.
54+
d. PROHIBITED: AI jargon ("optimize", "leverage", "streamline", "capability") use simple and decriptive words often used in project management software or tasks in a software company. Match their tone, no need to formalize it. Keep technical jargon user mentioned.
55+
g. Be careful to not count every word as a task.
56+
h. Make sure you are not returning the sentence with it's own verb without making it task title and adding the action verb in the beginning of the title eg.
57+
Message: edit message
58+
title should be "Add edit message" no "Edit message"
6059
6160
TITLE FORMAT EXAMPLES:
6261
Message: "Dena please fix open DM chats on notification click, it's working randomly for me."
63-
Title: "Fix random DM opening behavior on notification clicks"
62+
Title: "Fix random DM open on notification click"
6463
6564
Message: "@Mo this message failed to translate. It was a long message from a zh user"
66-
Title: "Fix translation failures for long Chinese messages"
65+
Title: "Fix translation bug for long ZH messages"
6766
68-
Message: "video sending"
69-
Title: "Add video"
67+
Message: "todo: - video upload"
68+
Title: "Add video upload"
7069
7170
3. ASSIGNEE DETECTION:
7271
- Trigger on exact @ mentions
@@ -80,17 +79,10 @@ export const handler = async (
8079
8180
OUTPUT FORMAT:
8281
{
83-
"title": "<Action Verb + Specific Context>",
84-
"description": "${text}",
82+
"title": "<Task Title>",
8583
"labelIds": ["<Matching-Label-ID>"] || [],
8684
"assigneeId": "<Mentioned-User-ID>" || ""
8785
}
88-
89-
REQUIREMENTS:
90-
- Description must be exact original text
91-
- Empty arrays/strings allowed for unmatched fields
92-
- Title must use concrete action verbs
93-
- No explanations in output
9486
`
9587

9688
// const message = `
@@ -120,7 +112,7 @@ export const handler = async (
120112
// "title": "<Translated/Original Text as Natural Task Title>",
121113
// "description": "${text}",
122114
// "labelIds": ["<Matching-Label-ID>"] || [],
123-
// "assigneeId": "<@Mention-Matched-ID>" || ""
115+
// "assigneeId": "<@Mention-Matched-ID>" || null
124116
// }
125117

126118
// Key Requirements:
@@ -130,15 +122,21 @@ export const handler = async (
130122
// - Never explain your reasoning
131123
// `
132124

125+
const ResponseSchema = z.object({
126+
title: z.string(),
127+
labelIds: z.array(z.string()),
128+
assigneeId: z.string().optional(),
129+
})
130+
133131
const response = await openaiClient?.chat.completions.create({
134132
messages: [
135133
{
136134
role: "user",
137-
content: message + "\n\nRespond with valid JSON using the required format.",
135+
content: message,
138136
},
139137
],
140-
model: "gpt-4o",
141-
response_format: { type: "json_object" },
138+
model: "gpt-4o-2024-11-20",
139+
response_format: zodResponseFormat(ResponseSchema, "task"),
142140
})
143141

144142
if (!response) {

0 commit comments

Comments
 (0)